| 1 |
/* |
| 2 |
* Copyright (C) 2005-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "GUIWindowVisualisation.h" |
| 10 |
|
| 11 |
#include "GUIInfoManager.h" |
| 12 |
#include "GUIUserMessages.h" |
| 13 |
#include "ServiceBroker.h" |
| 14 |
#include "application/ApplicationComponents.h" |
| 15 |
#include "application/ApplicationPlayer.h" |
| 16 |
#include "guilib/GUIComponent.h" |
| 17 |
#include "guilib/GUIDialog.h" |
| 18 |
#include "guilib/GUIWindowManager.h" |
| 19 |
#include "input/actions/Action.h" |
| 20 |
#include "input/actions/ActionIDs.h" |
| 21 |
#include "input/mouse/MouseEvent.h" |
| 22 |
#include "settings/AdvancedSettings.h" |
| 23 |
#include "settings/Settings.h" |
| 24 |
#include "settings/SettingsComponent.h" |
| 25 |
|
| 26 |
using namespace KODI; |
| 27 |
using namespace MUSIC_INFO; |
| 28 |
|
| 29 |
#define START_FADE_LENGTH 2.0f // 2 seconds on startup |
| 30 |
|
| 31 |
#define CONTROL_VIS 2 |
| 32 |
|
| 33 |
CGUIWindowVisualisation::CGUIWindowVisualisation(void) |
| 34 |
: CGUIWindow(WINDOW_VISUALISATION, "MusicVisualisation.xml") |
| 35 |
{ |
| 36 |
m_bShowPreset = false; |
| 37 |
m_loadType = KEEP_IN_MEMORY; |
| 38 |
} |
| 39 |
|
| 40 |
bool CGUIWindowVisualisation::OnAction(const CAction &action) |
| 41 |
{ |
| 42 |
bool passToVis = false; |
| 43 |
switch (action.GetID()) |
| 44 |
{ |
| 45 |
case ACTION_VIS_PRESET_NEXT: |
| 46 |
case ACTION_VIS_PRESET_PREV: |
| 47 |
case ACTION_VIS_PRESET_RANDOM: |
| 48 |
case ACTION_VIS_RATE_PRESET_PLUS: |
| 49 |
case ACTION_VIS_RATE_PRESET_MINUS: |
| 50 |
passToVis = true; |
| 51 |
break; |
| 52 |
|
| 53 |
case ACTION_SHOW_INFO: |
| 54 |
{ |
| 55 |
m_initTimer.Stop(); |
| 56 |
CServiceBroker::GetSettingsComponent()->GetSettings()->SetBool(CSettings::SETTING_MYMUSIC_SONGTHUMBINVIS, |
| 57 |
CServiceBroker::GetGUI()->GetInfoManager().GetInfoProviders().GetPlayerInfoProvider().ToggleShowInfo()); |
| 58 |
return true; |
| 59 |
} |
| 60 |
break; |
| 61 |
|
| 62 |
case ACTION_SHOW_OSD: |
| 63 |
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_DIALOG_MUSIC_OSD); |
| 64 |
return true; |
| 65 |
|
| 66 |
case ACTION_SHOW_GUI: |
| 67 |
// save the settings |
| 68 |
CServiceBroker::GetSettingsComponent()->GetSettings()->Save(); |
| 69 |
CServiceBroker::GetGUI()->GetWindowManager().PreviousWindow(); |
| 70 |
return true; |
| 71 |
break; |
| 72 |
|
| 73 |
case ACTION_VIS_PRESET_LOCK: |
| 74 |
{ // show the locked icon + fall through so that the vis handles the locking |
| 75 |
if (!m_bShowPreset) |
| 76 |
{ |
| 77 |
m_lockedTimer.StartZero(); |
| 78 |
} |
| 79 |
passToVis = true; |
| 80 |
} |
| 81 |
break; |
| 82 |
case ACTION_VIS_PRESET_SHOW: |
| 83 |
{ |
| 84 |
if (!m_lockedTimer.IsRunning() || m_bShowPreset) |
| 85 |
m_bShowPreset = !m_bShowPreset; |
| 86 |
return true; |
| 87 |
} |
| 88 |
break; |
| 89 |
|
| 90 |
case ACTION_DECREASE_RATING: |
| 91 |
case ACTION_INCREASE_RATING: |
| 92 |
{ |
| 93 |
// actual action is taken care of in CApplication::OnAction() |
| 94 |
m_initTimer.StartZero(); |
| 95 |
CServiceBroker::GetGUI()->GetInfoManager().GetInfoProviders().GetPlayerInfoProvider().SetShowInfo(true); |
| 96 |
} |
| 97 |
break; |
| 98 |
//! @todo These should be mapped to its own function - at the moment it's overriding |
| 99 |
//! the global action of fastforward/rewind and OSD. |
| 100 |
/* case KEY_BUTTON_Y: |
| 101 |
g_application.m_CdgParser.Pause(); |
| 102 |
return true; |
| 103 |
break; |
| 104 |
|
| 105 |
case ACTION_ANALOG_FORWARD: |
| 106 |
// calculate the speed based on the amount the button is held down |
| 107 |
if (action.GetAmount()) |
| 108 |
{ |
| 109 |
float AVDelay = g_application.m_CdgParser.GetAVDelay(); |
| 110 |
g_application.m_CdgParser.SetAVDelay(AVDelay - action.GetAmount() / 4.0f); |
| 111 |
return true; |
| 112 |
} |
| 113 |
break;*/ |
| 114 |
} |
| 115 |
|
| 116 |
if (passToVis) |
| 117 |
{ |
| 118 |
CGUIControl *control = GetControl(CONTROL_VIS); |
| 119 |
if (control) |
| 120 |
return control->OnAction(action); |
| 121 |
} |
| 122 |
|
| 123 |
return CGUIWindow::OnAction(action); |
| 124 |
} |
| 125 |
|
| 126 |
bool CGUIWindowVisualisation::OnMessage(CGUIMessage& message) |
| 127 |
{ |
| 128 |
switch ( message.GetMessage() ) |
| 129 |
{ |
| 130 |
case GUI_MSG_GET_VISUALISATION: |
| 131 |
case GUI_MSG_VISUALISATION_RELOAD: |
| 132 |
case GUI_MSG_PLAYBACK_STARTED: |
| 133 |
{ |
| 134 |
CGUIControl *control = GetControl(CONTROL_VIS); |
| 135 |
if (control) |
| 136 |
return control->OnMessage(message); |
| 137 |
} |
| 138 |
break; |
| 139 |
case GUI_MSG_VISUALISATION_ACTION: |
| 140 |
{ |
| 141 |
CAction action(message.GetParam1()); |
| 142 |
return OnAction(action); |
| 143 |
} |
| 144 |
case GUI_MSG_WINDOW_DEINIT: |
| 145 |
{ |
| 146 |
if (IsActive()) // save any changed settings from the OSD |
| 147 |
CServiceBroker::GetSettingsComponent()->GetSettings()->Save(); |
| 148 |
|
| 149 |
// close all active modal dialogs |
| 150 |
CServiceBroker::GetGUI()->GetWindowManager().CloseInternalModalDialogs(true); |
| 151 |
} |
| 152 |
break; |
| 153 |
case GUI_MSG_WINDOW_INIT: |
| 154 |
{ |
| 155 |
// check whether we've come back here from a window during which time we've actually |
| 156 |
// stopped playing music |
| 157 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 158 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 159 |
if (message.GetParam1() == WINDOW_INVALID && !appPlayer->IsPlayingAudio()) |
| 160 |
{ // why are we here if nothing is playing??? |
| 161 |
CServiceBroker::GetGUI()->GetWindowManager().PreviousWindow(); |
| 162 |
return true; |
| 163 |
} |
| 164 |
|
| 165 |
// hide or show the preset button(s) |
| 166 |
CGUIInfoManager& infoMgr = CServiceBroker::GetGUI()->GetInfoManager(); |
| 167 |
infoMgr.GetInfoProviders().GetPlayerInfoProvider().SetShowInfo(true); // always show the info initially. |
| 168 |
CGUIWindow::OnMessage(message); |
| 169 |
if (infoMgr.GetCurrentSongTag()) |
| 170 |
m_tag = *infoMgr.GetCurrentSongTag(); |
| 171 |
|
| 172 |
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MYMUSIC_SONGTHUMBINVIS)) |
| 173 |
{ // always on |
| 174 |
m_initTimer.Stop(); |
| 175 |
} |
| 176 |
else |
| 177 |
{ |
| 178 |
// start display init timer (fade out after 3 secs...) |
| 179 |
m_initTimer.StartZero(); |
| 180 |
} |
| 181 |
return true; |
| 182 |
} |
| 183 |
} |
| 184 |
return CGUIWindow::OnMessage(message); |
| 185 |
} |
| 186 |
|
| 187 |
EVENT_RESULT CGUIWindowVisualisation::OnMouseEvent(const CPoint& point, |
| 188 |
const MOUSE::CMouseEvent& event) |
| 189 |
{ |
| 190 |
if (event.m_id == ACTION_MOUSE_RIGHT_CLICK) |
| 191 |
{ // no control found to absorb this click - go back to GUI |
| 192 |
OnAction(CAction(ACTION_SHOW_GUI)); |
| 193 |
return EVENT_RESULT_HANDLED; |
| 194 |
} |
| 195 |
if (event.m_id == ACTION_GESTURE_NOTIFY) |
| 196 |
return EVENT_RESULT_UNHANDLED; |
| 197 |
if (event.m_id != ACTION_MOUSE_MOVE || event.m_offsetX || event.m_offsetY) |
| 198 |
{ // some other mouse action has occurred - bring up the OSD |
| 199 |
CGUIDialog *pOSD = CServiceBroker::GetGUI()->GetWindowManager().GetDialog(WINDOW_DIALOG_MUSIC_OSD); |
| 200 |
if (pOSD) |
| 201 |
{ |
| 202 |
pOSD->SetAutoClose(3000); |
| 203 |
pOSD->Open(); |
| 204 |
} |
| 205 |
return EVENT_RESULT_HANDLED; |
| 206 |
} |
| 207 |
return EVENT_RESULT_UNHANDLED; |
| 208 |
} |
| 209 |
|
| 210 |
void CGUIWindowVisualisation::FrameMove() |
| 211 |
{ |
| 212 |
CGUIInfoManager& infoMgr = CServiceBroker::GetGUI()->GetInfoManager(); |
| 213 |
|
| 214 |
// check for a tag change |
| 215 |
const CMusicInfoTag* tag = infoMgr.GetCurrentSongTag(); |
| 216 |
if (tag && *tag != m_tag) |
| 217 |
{ // need to fade in then out again |
| 218 |
m_tag = *tag; |
| 219 |
// fade in |
| 220 |
m_initTimer.StartZero(); |
| 221 |
infoMgr.GetInfoProviders().GetPlayerInfoProvider().SetShowInfo(true); |
| 222 |
} |
| 223 |
if (m_initTimer.IsRunning() && m_initTimer.GetElapsedSeconds() > (float)CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_songInfoDuration) |
| 224 |
{ |
| 225 |
m_initTimer.Stop(); |
| 226 |
if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MYMUSIC_SONGTHUMBINVIS)) |
| 227 |
{ // reached end of fade in, fade out again |
| 228 |
infoMgr.GetInfoProviders().GetPlayerInfoProvider().SetShowInfo(false); |
| 229 |
} |
| 230 |
} |
| 231 |
// show or hide the locked texture |
| 232 |
if (m_lockedTimer.IsRunning() && m_lockedTimer.GetElapsedSeconds() > START_FADE_LENGTH) |
| 233 |
{ |
| 234 |
m_lockedTimer.Stop(); |
| 235 |
} |
| 236 |
CGUIWindow::FrameMove(); |
| 237 |
} |