2 * Copyright (C) 2005-2008 Team XBMC
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)
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.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #include "GUIWindowVisualisation.h"
23 #include "Application.h"
24 #include "music/dialogs/GUIDialogMusicOSD.h"
25 #include "GUIUserMessages.h"
26 #include "GUIInfoManager.h"
27 #include "music/dialogs/GUIDialogVisualisationPresetList.h"
28 #include "guilib/GUIWindowManager.h"
29 #include "settings/Settings.h"
30 #include "settings/AdvancedSettings.h"
32 using namespace MUSIC_INFO;
34 #define START_FADE_LENGTH 2.0f // 2 seconds on startup
38 CGUIWindowVisualisation::CGUIWindowVisualisation(void)
39 : CGUIWindow(WINDOW_VISUALISATION, "MusicVisualisation.xml"),
40 m_initTimer(true), m_lockedTimer(true)
42 m_bShowPreset = false;
45 bool CGUIWindowVisualisation::OnAction(const CAction &action)
47 bool passToVis = false;
48 switch (action.GetID())
50 case ACTION_VIS_PRESET_NEXT:
51 case ACTION_VIS_PRESET_PREV:
52 case ACTION_VIS_PRESET_RANDOM:
53 case ACTION_VIS_RATE_PRESET_PLUS:
54 case ACTION_VIS_RATE_PRESET_MINUS:
58 case ACTION_SHOW_INFO:
61 g_settings.m_bMyMusicSongThumbInVis = g_infoManager.ToggleShowInfo();
69 g_windowManager.PreviousWindow();
73 case ACTION_VIS_PRESET_LOCK:
74 { // show the locked icon + fall through so that the vis handles the locking
77 m_lockedTimer.StartZero();
78 g_infoManager.SetShowCodec(true);
83 case ACTION_VIS_PRESET_SHOW:
85 if (!m_lockedTimer.IsRunning() || m_bShowPreset)
86 m_bShowPreset = !m_bShowPreset;
87 g_infoManager.SetShowCodec(m_bShowPreset);
92 case ACTION_DECREASE_RATING:
93 case ACTION_INCREASE_RATING:
95 // actual action is taken care of in CApplication::OnAction()
96 m_initTimer.StartZero();
97 g_infoManager.SetShowInfo(true);
100 // TODO: These should be mapped to it's own function - at the moment it's overriding
101 // the global action of fastforward/rewind and OSD.
102 /* case KEY_BUTTON_Y:
103 g_application.m_CdgParser.Pause();
107 case ACTION_ANALOG_FORWARD:
108 // calculate the speed based on the amount the button is held down
109 if (action.GetAmount())
111 float AVDelay = g_application.m_CdgParser.GetAVDelay();
112 g_application.m_CdgParser.SetAVDelay(AVDelay - action.GetAmount() / 4.0f);
120 CGUIControl *control = (CGUIControl *)GetControl(CONTROL_VIS);
122 return control->OnAction(action);
125 return CGUIWindow::OnAction(action);
128 bool CGUIWindowVisualisation::OnMessage(CGUIMessage& message)
130 switch ( message.GetMessage() )
132 case GUI_MSG_GET_VISUALISATION:
133 case GUI_MSG_VISUALISATION_RELOAD:
134 case GUI_MSG_PLAYBACK_STARTED:
136 CGUIControl *control = (CGUIControl *)GetControl(CONTROL_VIS);
138 return control->OnMessage(message);
141 case GUI_MSG_VISUALISATION_ACTION:
143 CAction action(message.GetParam1());
144 return OnAction(action);
146 case GUI_MSG_WINDOW_DEINIT:
148 if (IsActive()) // save any changed settings from the OSD
150 // check and close any OSD windows
151 CGUIDialogMusicOSD *pOSD = (CGUIDialogMusicOSD *)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_OSD);
152 if (pOSD && pOSD->IsDialogRunning()) pOSD->Close(true);
153 CGUIDialogVisualisationPresetList *pList = (CGUIDialogVisualisationPresetList *)g_windowManager.GetWindow(WINDOW_DIALOG_VIS_PRESET_LIST);
154 if (pList && pList->IsDialogRunning()) pList->Close(true);
157 case GUI_MSG_WINDOW_INIT:
159 // check whether we've come back here from a window during which time we've actually
160 // stopped playing music
161 if (message.GetParam1() == WINDOW_INVALID && !g_application.IsPlayingAudio())
162 { // why are we here if nothing is playing???
163 g_windowManager.PreviousWindow();
167 // hide or show the preset button(s)
168 g_infoManager.SetShowCodec(m_bShowPreset);
169 g_infoManager.SetShowInfo(true); // always show the info initially.
170 CGUIWindow::OnMessage(message);
171 if (g_infoManager.GetCurrentSongTag())
172 m_tag = *g_infoManager.GetCurrentSongTag();
174 if (g_settings.m_bMyMusicSongThumbInVis)
180 // start display init timer (fade out after 3 secs...)
181 m_initTimer.StartZero();
186 return CGUIWindow::OnMessage(message);
189 EVENT_RESULT CGUIWindowVisualisation::OnMouseEvent(const CPoint &point, const CMouseEvent &event)
191 if (event.m_id == ACTION_MOUSE_RIGHT_CLICK)
192 { // no control found to absorb this click - go back to GUI
193 OnAction(CAction(ACTION_SHOW_GUI));
194 return EVENT_RESULT_HANDLED;
196 if (event.m_id != ACTION_MOUSE_MOVE || event.m_offsetX || event.m_offsetY)
197 { // some other mouse action has occurred - bring up the OSD
198 CGUIDialog *pOSD = (CGUIDialog *)g_windowManager.GetWindow(WINDOW_DIALOG_MUSIC_OSD);
201 pOSD->SetAutoClose(3000);
204 return EVENT_RESULT_HANDLED;
206 return EVENT_RESULT_UNHANDLED;
209 void CGUIWindowVisualisation::FrameMove()
211 // check for a tag change
212 const CMusicInfoTag* tag = g_infoManager.GetCurrentSongTag();
213 if (tag && *tag != m_tag)
214 { // need to fade in then out again
217 m_initTimer.StartZero();
218 g_infoManager.SetShowInfo(true);
220 if (m_initTimer.IsRunning() && m_initTimer.GetElapsedSeconds() > (float)g_advancedSettings.m_songInfoDuration)
223 if (!g_settings.m_bMyMusicSongThumbInVis)
224 { // reached end of fade in, fade out again
225 g_infoManager.SetShowInfo(false);
228 // show or hide the locked texture
229 if (m_lockedTimer.IsRunning() && m_lockedTimer.GetElapsedSeconds() > START_FADE_LENGTH)
231 m_lockedTimer.Stop();
234 g_infoManager.SetShowCodec(false);
237 CGUIWindow::FrameMove();