Fix keymap.
[vuplus_xbmc] / xbmc / guilib / GUIVisualisationControl.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include "GUIVisualisationControl.h"
22 #include "GUIWindowManager.h"
23 #include "GUIUserMessages.h"
24 #include "Application.h"
25 #include "addons/AddonManager.h"
26 #include "addons/Visualisation.h"
27 #include "utils/log.h"
28 #include "guilib/IRenderingCallback.h"
29 #include "Key.h"
30
31 using namespace std;
32 using namespace ADDON;
33
34 #define LABEL_ROW1 10
35 #define LABEL_ROW2 11
36 #define LABEL_ROW3 12
37
38 CGUIVisualisationControl::CGUIVisualisationControl(int parentID, int controlID, float posX, float posY, float width, float height)
39     : CGUIRenderingControl(parentID, controlID, posX, posY, width, height), m_bAttemptedLoad(false)
40 {
41   ControlType = GUICONTROL_VISUALISATION;
42 }
43
44 CGUIVisualisationControl::CGUIVisualisationControl(const CGUIVisualisationControl &from)
45   : CGUIRenderingControl(from), m_bAttemptedLoad(false), m_addon()
46 {
47   ControlType = GUICONTROL_VISUALISATION;
48 }
49
50 bool CGUIVisualisationControl::OnMessage(CGUIMessage &message)
51 {
52   switch (message.GetMessage())
53   {
54   case GUI_MSG_GET_VISUALISATION:
55     message.SetPointer(m_addon.get());
56     return m_addon;
57   case GUI_MSG_VISUALISATION_RELOAD:
58     FreeResources(true);
59     return true;
60   case GUI_MSG_PLAYBACK_STARTED:
61     if (m_addon)
62     {
63       m_addon->UpdateTrack();
64       return true;
65     }
66     break;
67   }
68   return CGUIRenderingControl::OnMessage(message);
69 }
70
71 bool CGUIVisualisationControl::OnAction(const CAction &action)
72 {
73   if (!m_addon)
74     return false;
75
76   switch (action.GetID())
77   {
78   case ACTION_VIS_PRESET_NEXT:
79     return m_addon->OnAction(VIS_ACTION_NEXT_PRESET);
80   case ACTION_VIS_PRESET_PREV:
81     return m_addon->OnAction(VIS_ACTION_PREV_PRESET);
82   case ACTION_VIS_PRESET_RANDOM:
83     return m_addon->OnAction(VIS_ACTION_RANDOM_PRESET);
84   case ACTION_VIS_RATE_PRESET_PLUS:
85     return m_addon->OnAction(VIS_ACTION_RATE_PRESET_PLUS);
86   case ACTION_VIS_RATE_PRESET_MINUS:
87     return m_addon->OnAction(VIS_ACTION_RATE_PRESET_MINUS);
88   case ACTION_VIS_PRESET_LOCK:
89     return m_addon->OnAction(VIS_ACTION_LOCK_PRESET);
90   default:
91     return CGUIRenderingControl::OnAction(action);
92   }
93 }
94
95 void CGUIVisualisationControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
96 {
97   if (g_application.m_pPlayer->IsPlayingAudio())
98   {
99     if (m_bInvalidated)
100       FreeResources(true);
101
102     if (!m_addon && !m_bAttemptedLoad)
103     {
104       AddonPtr addon;
105       if (ADDON::CAddonMgr::Get().GetDefault(ADDON_VIZ, addon))
106       {
107         m_addon = boost::dynamic_pointer_cast<CVisualisation>(addon);
108         if (m_addon)
109           if (!InitCallback(m_addon.get()))
110             m_addon.reset();
111       }
112
113       m_bAttemptedLoad = true;
114     }
115   }
116   CGUIRenderingControl::Process(currentTime, dirtyregions);
117 }
118
119 void CGUIVisualisationControl::FreeResources(bool immediately)
120 {
121   m_bAttemptedLoad = false;
122   // tell our app that we're going
123   if (!m_addon)
124     return;
125
126   CGUIMessage msg(GUI_MSG_VISUALISATION_UNLOADING, m_controlID, 0);
127   g_windowManager.SendMessage(msg);
128   CLog::Log(LOGDEBUG, "FreeVisualisation() started");
129   CGUIRenderingControl::FreeResources(immediately);
130   m_addon.reset();
131   CLog::Log(LOGDEBUG, "FreeVisualisation() done");
132 }
133