| 1 | /* |
|---|
| 2 | * Hydrogen |
|---|
| 3 | * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net] |
|---|
| 4 | * |
|---|
| 5 | * http://www.hydrogen-music.org |
|---|
| 6 | * |
|---|
| 7 | * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | * it under the terms of the GNU General Public License as published by |
|---|
| 9 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | * (at your option) any later version. |
|---|
| 11 | * |
|---|
| 12 | * This program is distributed in the hope that it will be useful, |
|---|
| 13 | * but WITHOUT ANY WARRANTY, without even the implied warranty of |
|---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | * GNU General Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License |
|---|
| 18 | * along with this program; if not, write to the Free Software |
|---|
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | * |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | #include "Skin.h" |
|---|
| 25 | #include "PlayerControl.h" |
|---|
| 26 | #include "InstrumentRack.h" |
|---|
| 27 | #include "HydrogenApp.h" |
|---|
| 28 | |
|---|
| 29 | #include "widgets/LCD.h" |
|---|
| 30 | #include "widgets/Button.h" |
|---|
| 31 | #include "widgets/CpuLoadWidget.h" |
|---|
| 32 | #include "widgets/MidiActivityWidget.h" |
|---|
| 33 | #include "widgets/PixmapWidget.h" |
|---|
| 34 | |
|---|
| 35 | #include "Mixer/Mixer.h" |
|---|
| 36 | #include "SongEditor/SongEditorPanel.h" |
|---|
| 37 | #include "PatternEditor/PatternEditorPanel.h" |
|---|
| 38 | #include "InstrumentEditor/InstrumentEditorPanel.h" |
|---|
| 39 | |
|---|
| 40 | #include <hydrogen/hydrogen.h> |
|---|
| 41 | #include <hydrogen/Transport.h> |
|---|
| 42 | #include <hydrogen/audio_engine.h> |
|---|
| 43 | #include <hydrogen/IO/JackOutput.h> |
|---|
| 44 | #include <hydrogen/Preferences.h> |
|---|
| 45 | #include <hydrogen/JackTimeMasterEvents.h> |
|---|
| 46 | using namespace H2Core; |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | //beatconter global |
|---|
| 50 | int bcDisplaystatus = 0; |
|---|
| 51 | //~ beatcounter |
|---|
| 52 | |
|---|
| 53 | PlayerControl::PlayerControl(QWidget *parent) |
|---|
| 54 | : QLabel(parent) |
|---|
| 55 | , Object( "PlayerControl" ) |
|---|
| 56 | { |
|---|
| 57 | // Background image |
|---|
| 58 | setPixmap( QPixmap( Skin::getImagePath() + "/playerControlPanel/background.png" ) ); |
|---|
| 59 | setScaledContents( true ); |
|---|
| 60 | |
|---|
| 61 | QHBoxLayout *hbox = new QHBoxLayout(); |
|---|
| 62 | hbox->setSpacing( 0 ); |
|---|
| 63 | hbox->setMargin( 0 ); |
|---|
| 64 | setLayout( hbox ); |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | // CONTROLS |
|---|
| 69 | PixmapWidget *pControlsPanel = new PixmapWidget( NULL ); |
|---|
| 70 | pControlsPanel->setFixedSize( 317, 43 ); |
|---|
| 71 | pControlsPanel->setPixmap( "/playerControlPanel/background_Control.png" ); |
|---|
| 72 | hbox->addWidget( pControlsPanel ); |
|---|
| 73 | |
|---|
| 74 | m_pTimeDisplayH = new LCDDisplay( pControlsPanel, LCDDigit::LARGE_GRAY, 2 ); |
|---|
| 75 | m_pTimeDisplayH->move( 27, 12 ); |
|---|
| 76 | m_pTimeDisplayH->setText( "00" ); |
|---|
| 77 | |
|---|
| 78 | m_pTimeDisplayM = new LCDDisplay( pControlsPanel, LCDDigit::LARGE_GRAY, 2 ); |
|---|
| 79 | m_pTimeDisplayM->move( 61, 12 ); |
|---|
| 80 | m_pTimeDisplayM->setText( "00" ); |
|---|
| 81 | |
|---|
| 82 | m_pTimeDisplayS = new LCDDisplay( pControlsPanel, LCDDigit::LARGE_GRAY, 2 ); |
|---|
| 83 | m_pTimeDisplayS->move( 95, 12 ); |
|---|
| 84 | m_pTimeDisplayS->setText( "00" ); |
|---|
| 85 | |
|---|
| 86 | m_pTimeDisplayMS = new LCDDisplay( pControlsPanel, LCDDigit::SMALL_GRAY, 3 ); |
|---|
| 87 | m_pTimeDisplayMS->move( 122, 16 ); |
|---|
| 88 | m_pTimeDisplayMS->setText( "000" ); |
|---|
| 89 | |
|---|
| 90 | // Rewind button |
|---|
| 91 | m_pRwdBtn = new Button( |
|---|
| 92 | pControlsPanel, |
|---|
| 93 | "/playerControlPanel/btn_rwd_on.png", |
|---|
| 94 | "/playerControlPanel/btn_rwd_off.png", |
|---|
| 95 | "/playerControlPanel/btn_rwd_over.png", |
|---|
| 96 | QSize(21, 15) |
|---|
| 97 | ); |
|---|
| 98 | m_pRwdBtn->move(168, 17); |
|---|
| 99 | m_pRwdBtn->setToolTip( trUtf8("Rewind") ); |
|---|
| 100 | connect(m_pRwdBtn, SIGNAL(clicked(Button*)), this, SLOT(RewindBtnClicked(Button*))); |
|---|
| 101 | |
|---|
| 102 | // Play button |
|---|
| 103 | m_pPlayBtn = new ToggleButton( |
|---|
| 104 | pControlsPanel, |
|---|
| 105 | "/playerControlPanel/btn_play_on.png", |
|---|
| 106 | "/playerControlPanel/btn_play_off.png", |
|---|
| 107 | "/playerControlPanel/btn_play_over.png", |
|---|
| 108 | QSize(26, 17) |
|---|
| 109 | ); |
|---|
| 110 | m_pPlayBtn->move(195, 17); |
|---|
| 111 | m_pPlayBtn->setPressed(false); |
|---|
| 112 | m_pPlayBtn->setToolTip( trUtf8("Play/ Pause") ); |
|---|
| 113 | connect(m_pPlayBtn, SIGNAL(clicked(Button*)), this, SLOT(playBtnClicked(Button*))); |
|---|
| 114 | |
|---|
| 115 | // Stop button |
|---|
| 116 | m_pStopBtn = new Button( |
|---|
| 117 | pControlsPanel, |
|---|
| 118 | "/playerControlPanel/btn_stop_on.png", |
|---|
| 119 | "/playerControlPanel/btn_stop_off.png", |
|---|
| 120 | "/playerControlPanel/btn_stop_over.png", |
|---|
| 121 | QSize(21, 15) |
|---|
| 122 | ); |
|---|
| 123 | m_pStopBtn->move(227, 17); |
|---|
| 124 | m_pStopBtn->setToolTip( trUtf8("Stop") ); |
|---|
| 125 | connect(m_pStopBtn, SIGNAL(clicked(Button*)), this, SLOT(stopBtnClicked(Button*))); |
|---|
| 126 | |
|---|
| 127 | // Fast forward button |
|---|
| 128 | m_pFfwdBtn = new Button( |
|---|
| 129 | pControlsPanel, |
|---|
| 130 | "/playerControlPanel/btn_ffwd_on.png", |
|---|
| 131 | "/playerControlPanel/btn_ffwd_off.png", |
|---|
| 132 | "/playerControlPanel/btn_ffwd_over.png", |
|---|
| 133 | QSize(21, 15) |
|---|
| 134 | ); |
|---|
| 135 | m_pFfwdBtn->move(254, 17); |
|---|
| 136 | m_pFfwdBtn->setToolTip( trUtf8("Fast Forward") ); |
|---|
| 137 | connect(m_pFfwdBtn, SIGNAL(clicked(Button*)), this, SLOT(FFWDBtnClicked(Button*))); |
|---|
| 138 | |
|---|
| 139 | // Loop song button button |
|---|
| 140 | m_pSongLoopBtn = new ToggleButton( |
|---|
| 141 | pControlsPanel, |
|---|
| 142 | "/playerControlPanel/btn_loop_on.png", |
|---|
| 143 | "/playerControlPanel/btn_loop_off.png", |
|---|
| 144 | "/playerControlPanel/btn_loop_over.png", |
|---|
| 145 | QSize(21, 15) |
|---|
| 146 | ); |
|---|
| 147 | m_pSongLoopBtn->move(283, 17); |
|---|
| 148 | m_pSongLoopBtn->setToolTip( trUtf8("Loop song") ); |
|---|
| 149 | connect( m_pSongLoopBtn, SIGNAL( clicked(Button*) ), this, SLOT( songLoopBtnClicked(Button*) ) ); |
|---|
| 150 | //~ CONTROLS |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | // MODE |
|---|
| 154 | PixmapWidget *pModePanel = new PixmapWidget( NULL ); |
|---|
| 155 | pModePanel->setFixedSize( 90, 43 ); |
|---|
| 156 | pModePanel->setPixmap( "/playerControlPanel/background_Mode.png" ); |
|---|
| 157 | hbox->addWidget( pModePanel ); |
|---|
| 158 | |
|---|
| 159 | // Live mode button |
|---|
| 160 | m_pLiveModeBtn = new ToggleButton( |
|---|
| 161 | pModePanel, |
|---|
| 162 | "/playerControlPanel/statusLED_on.png", |
|---|
| 163 | "/playerControlPanel/statusLED_off.png", |
|---|
| 164 | "/playerControlPanel/statusLED_off.png", |
|---|
| 165 | QSize(11, 9) |
|---|
| 166 | ); |
|---|
| 167 | m_pLiveModeBtn->move(10, 4); |
|---|
| 168 | m_pLiveModeBtn->setPressed(true); |
|---|
| 169 | m_pLiveModeBtn->setToolTip( trUtf8("Pattern Mode") ); |
|---|
| 170 | connect(m_pLiveModeBtn, SIGNAL(clicked(Button*)), this, SLOT(liveModeBtnClicked(Button*))); |
|---|
| 171 | |
|---|
| 172 | // Song mode button |
|---|
| 173 | m_pSongModeBtn = new ToggleButton( |
|---|
| 174 | pModePanel, |
|---|
| 175 | "/playerControlPanel/statusLED_on.png", |
|---|
| 176 | "/playerControlPanel/statusLED_off.png", |
|---|
| 177 | "/playerControlPanel/statusLED_off.png", |
|---|
| 178 | QSize(11, 9) |
|---|
| 179 | ); |
|---|
| 180 | m_pSongModeBtn->move(10, 15); |
|---|
| 181 | m_pSongModeBtn->setPressed(false); |
|---|
| 182 | m_pSongModeBtn->setToolTip( trUtf8("Song Mode") ); |
|---|
| 183 | connect(m_pSongModeBtn, SIGNAL(clicked(Button*)), this, SLOT(songModeBtnClicked(Button*))); |
|---|
| 184 | |
|---|
| 185 | // Switch mode button |
|---|
| 186 | m_pSwitchModeBtn = new Button( |
|---|
| 187 | pModePanel, |
|---|
| 188 | "/playerControlPanel/btn_mode_on.png", |
|---|
| 189 | "/playerControlPanel/btn_mode_off.png", |
|---|
| 190 | "/playerControlPanel/btn_mode_over.png", |
|---|
| 191 | QSize(69, 13) |
|---|
| 192 | ); |
|---|
| 193 | m_pSwitchModeBtn->move(10, 26); |
|---|
| 194 | m_pSwitchModeBtn->setToolTip( trUtf8("Switch Song/ Pattern Mode") ); |
|---|
| 195 | connect(m_pSwitchModeBtn, SIGNAL(clicked(Button*)), this, SLOT(switchModeBtnClicked(Button*))); |
|---|
| 196 | //~ MODE |
|---|
| 197 | |
|---|
| 198 | // BC on off |
|---|
| 199 | PixmapWidget *pControlsBBTBConoffPanel = new PixmapWidget( NULL ); |
|---|
| 200 | pControlsBBTBConoffPanel->setFixedSize( 15, 43 ); |
|---|
| 201 | pControlsBBTBConoffPanel->setPixmap( "/playerControlPanel/onoff.png" ); |
|---|
| 202 | hbox->addWidget( pControlsBBTBConoffPanel ); |
|---|
| 203 | |
|---|
| 204 | m_pBConoffBtn = new ToggleButton( |
|---|
| 205 | pControlsBBTBConoffPanel, |
|---|
| 206 | "/playerControlPanel/bc_on.png", |
|---|
| 207 | "/playerControlPanel/bc_off.png", |
|---|
| 208 | "/playerControlPanel/bc_off.png", |
|---|
| 209 | QSize(10, 40) |
|---|
| 210 | ); |
|---|
| 211 | m_pBConoffBtn->move(1, 1); |
|---|
| 212 | m_pBConoffBtn->setPressed(false); |
|---|
| 213 | m_pBConoffBtn->setToolTip( trUtf8("BeatCounter Panel on") ); |
|---|
| 214 | connect(m_pBConoffBtn, SIGNAL(clicked(Button*)), this, SLOT(bconoffBtnClicked(Button*))); |
|---|
| 215 | //~ BC on off |
|---|
| 216 | |
|---|
| 217 | //beatcounter |
|---|
| 218 | m_pControlsBCPanel = new PixmapWidget( NULL ); |
|---|
| 219 | m_pControlsBCPanel->setFixedSize( 86, 43 ); |
|---|
| 220 | m_pControlsBCPanel->setPixmap( "/playerControlPanel/beatConter_BG.png" ); |
|---|
| 221 | hbox->addWidget( m_pControlsBCPanel ); |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | m_pBCDisplayZ = new LCDDisplay( m_pControlsBCPanel, LCDDigit::LARGE_GRAY, 2 ); |
|---|
| 225 | m_pBCDisplayZ->move( 36, 8 ); |
|---|
| 226 | m_pBCDisplayZ->setText( "--" ); |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | m_pBCDisplayT = new LCDDisplay( m_pControlsBCPanel, LCDDigit::SMALL_GRAY, 1 ); |
|---|
| 230 | m_pBCDisplayT->move( 23, 26 ); |
|---|
| 231 | m_pBCDisplayT->setText( "4" ); |
|---|
| 232 | |
|---|
| 233 | m_pBCDisplayB = new LCDDisplay( m_pControlsBCPanel, LCDDigit::SMALL_GRAY, 2 ); |
|---|
| 234 | m_pBCDisplayB->move( 39, 26 ); |
|---|
| 235 | //small fix against qt4 png transparent problem |
|---|
| 236 | // m_pBCDisplayB->setText( "4" ); |
|---|
| 237 | m_pBCDisplayB->setText( "04" ); |
|---|
| 238 | |
|---|
| 239 | m_pBCTUpBtn = new Button( |
|---|
| 240 | m_pControlsBCPanel, |
|---|
| 241 | "/lcd/LCDSpinBox_up_on.png", |
|---|
| 242 | "/lcd/LCDSpinBox_up_off.png", |
|---|
| 243 | "/lcd/LCDSpinBox_up_over.png", |
|---|
| 244 | QSize(16, 8) |
|---|
| 245 | ); |
|---|
| 246 | m_pBCTUpBtn->move( 4, 6 ); |
|---|
| 247 | connect( m_pBCTUpBtn, SIGNAL( clicked( Button* ) ), this, SLOT(bctButtonClicked( Button* ) ) ); |
|---|
| 248 | |
|---|
| 249 | m_pBCTDownBtn = new Button( |
|---|
| 250 | m_pControlsBCPanel, |
|---|
| 251 | "/lcd/LCDSpinBox_down_on.png", |
|---|
| 252 | "/lcd/LCDSpinBox_down_off.png", |
|---|
| 253 | "/lcd/LCDSpinBox_down_over.png", |
|---|
| 254 | QSize(16, 8) |
|---|
| 255 | ); |
|---|
| 256 | m_pBCTDownBtn->move( 4, 16 ); |
|---|
| 257 | connect( m_pBCTDownBtn, SIGNAL( clicked( Button* ) ), this, SLOT(bctButtonClicked( Button* ) ) ); |
|---|
| 258 | |
|---|
| 259 | m_pBCBUpBtn = new Button( |
|---|
| 260 | m_pControlsBCPanel, |
|---|
| 261 | "/lcd/LCDSpinBox_up_on.png", |
|---|
| 262 | "/lcd/LCDSpinBox_up_off.png", |
|---|
| 263 | "/lcd/LCDSpinBox_up_over.png", |
|---|
| 264 | QSize(16, 8) |
|---|
| 265 | ); |
|---|
| 266 | m_pBCBUpBtn->move( 65, 6 ); |
|---|
| 267 | connect( m_pBCBUpBtn, SIGNAL( clicked( Button* ) ), this, SLOT(bcbButtonClicked( Button* ) ) ); |
|---|
| 268 | |
|---|
| 269 | m_pBCBDownBtn = new Button( |
|---|
| 270 | m_pControlsBCPanel, |
|---|
| 271 | "/lcd/LCDSpinBox_down_on.png", |
|---|
| 272 | "/lcd/LCDSpinBox_down_off.png", |
|---|
| 273 | "/lcd/LCDSpinBox_down_over.png", |
|---|
| 274 | QSize(16, 8) |
|---|
| 275 | ); |
|---|
| 276 | m_pBCBDownBtn->move( 65, 16 ); |
|---|
| 277 | connect( m_pBCBDownBtn, SIGNAL( clicked( Button* ) ), this, SLOT(bcbButtonClicked( Button* ) ) ); |
|---|
| 278 | |
|---|
| 279 | m_pBCSetPlayBtn = new ToggleButton( |
|---|
| 280 | m_pControlsBCPanel, |
|---|
| 281 | "/playerControlPanel/btn_set_play_on.png", |
|---|
| 282 | "/playerControlPanel/btn_set_play_off.png", |
|---|
| 283 | "/playerControlPanel/btn_set_play_off.png", |
|---|
| 284 | QSize(15, 13) |
|---|
| 285 | ); |
|---|
| 286 | m_pBCSetPlayBtn->move(67, 27); |
|---|
| 287 | m_pBCSetPlayBtn->setPressed(false); |
|---|
| 288 | m_pBCSetPlayBtn->setToolTip( trUtf8("Set BPM / Set BPM and play") ); |
|---|
| 289 | connect(m_pBCSetPlayBtn, SIGNAL(clicked(Button*)), this, SLOT(bcSetPlayBtnClicked(Button*))); |
|---|
| 290 | //~ beatcounter |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | // BPM |
|---|
| 294 | PixmapWidget *pBPMPanel = new PixmapWidget( NULL ); |
|---|
| 295 | pBPMPanel->setFixedSize( 145, 43 ); |
|---|
| 296 | pBPMPanel->setPixmap( "/playerControlPanel/background_BPM.png" ); |
|---|
| 297 | hbox->addWidget( pBPMPanel ); |
|---|
| 298 | |
|---|
| 299 | // LCD BPM SpinBox |
|---|
| 300 | m_pLCDBPMSpinbox = new LCDSpinBox( pBPMPanel, 6, LCDSpinBox::FLOAT, 30, 400 ); |
|---|
| 301 | m_pLCDBPMSpinbox->move( 43, 6 ); |
|---|
| 302 | connect( m_pLCDBPMSpinbox, SIGNAL(changed(LCDSpinBox*)), this, SLOT(bpmChanged())); |
|---|
| 303 | connect( m_pLCDBPMSpinbox, SIGNAL(spinboxClicked()), this, SLOT(bpmClicked())); |
|---|
| 304 | |
|---|
| 305 | m_pBPMUpBtn = new Button( |
|---|
| 306 | pBPMPanel, |
|---|
| 307 | "/lcd/LCDSpinBox_up_on.png", |
|---|
| 308 | "/lcd/LCDSpinBox_up_off.png", |
|---|
| 309 | "/lcd/LCDSpinBox_up_over.png", |
|---|
| 310 | QSize(16, 8) |
|---|
| 311 | ); |
|---|
| 312 | m_pBPMUpBtn->move( 12, 5 ); |
|---|
| 313 | connect( m_pBPMUpBtn, SIGNAL( clicked( Button* ) ), this, SLOT(bpmButtonClicked( Button* ) ) ); |
|---|
| 314 | connect( m_pBPMUpBtn, SIGNAL( mousePress( Button* ) ), this, SLOT(bpmButtonPressed( Button* ) ) ); |
|---|
| 315 | |
|---|
| 316 | m_pBPMDownBtn = new Button( |
|---|
| 317 | pBPMPanel, |
|---|
| 318 | "/lcd/LCDSpinBox_down_on.png", |
|---|
| 319 | "/lcd/LCDSpinBox_down_off.png", |
|---|
| 320 | "/lcd/LCDSpinBox_down_over.png", |
|---|
| 321 | QSize(16, 8) |
|---|
| 322 | ); |
|---|
| 323 | m_pBPMDownBtn->move( 12, 14 ); |
|---|
| 324 | connect( m_pBPMDownBtn, SIGNAL( clicked( Button* ) ), this, SLOT(bpmButtonClicked( Button* ) ) ); |
|---|
| 325 | connect( m_pBPMDownBtn, SIGNAL( mousePress( Button* ) ), this, SLOT(bpmButtonPressed( Button* ) ) ); |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | m_pMetronomeWidget = new MetronomeWidget( pBPMPanel ); |
|---|
| 329 | m_pMetronomeWidget->resize( 85, 5 ); |
|---|
| 330 | m_pMetronomeWidget->move( 42, 25 ); |
|---|
| 331 | |
|---|
| 332 | m_pMetronomeBtn = new ToggleButton( |
|---|
| 333 | pBPMPanel, |
|---|
| 334 | "/playerControlPanel/btn_metronome_on.png", |
|---|
| 335 | "/playerControlPanel/btn_metronome_off.png", |
|---|
| 336 | "/playerControlPanel/btn_metronome_over.png", |
|---|
| 337 | QSize( 20, 13 ) |
|---|
| 338 | ); |
|---|
| 339 | m_pMetronomeBtn->move( 10, 26 ); |
|---|
| 340 | connect( m_pMetronomeBtn, SIGNAL( clicked( Button* ) ), this, SLOT(metronomeButtonClicked( Button* ) ) ); |
|---|
| 341 | //~ BPM |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | // JACK |
|---|
| 345 | PixmapWidget *pJackPanel = new PixmapWidget( NULL ); |
|---|
| 346 | pJackPanel->setFixedSize( 113, 43 ); |
|---|
| 347 | pJackPanel->setPixmap( "/playerControlPanel/background_Jack.png" ); |
|---|
| 348 | hbox->addWidget( pJackPanel ); |
|---|
| 349 | |
|---|
| 350 | // Jack transport mode button |
|---|
| 351 | m_pJackTransportBtn = new ToggleButton( |
|---|
| 352 | pJackPanel, |
|---|
| 353 | "/playerControlPanel/jackTransportBtn_on.png", |
|---|
| 354 | "/playerControlPanel/jackTransportBtn_off.png", |
|---|
| 355 | "/playerControlPanel/jackTransportBtn_over.png", |
|---|
| 356 | QSize(45, 13) |
|---|
| 357 | ); |
|---|
| 358 | m_pJackTransportBtn->hide(); |
|---|
| 359 | m_pJackTransportBtn->setPressed(true); |
|---|
| 360 | m_pJackTransportBtn->setToolTip( trUtf8("Jack-transport on/off") ); |
|---|
| 361 | connect(m_pJackTransportBtn, SIGNAL(clicked(Button*)), this, SLOT(jackTransportBtnClicked(Button*))); |
|---|
| 362 | m_pJackTransportBtn->move(10, 26); |
|---|
| 363 | |
|---|
| 364 | //jack time master |
|---|
| 365 | m_pJackMasterBtn = new ToggleButton( |
|---|
| 366 | pJackPanel, |
|---|
| 367 | "/playerControlPanel/jackMasterBtn_on.png", |
|---|
| 368 | "/playerControlPanel/jackMasterBtn_off.png", |
|---|
| 369 | "/playerControlPanel/jackMasterBtn_over.png", |
|---|
| 370 | QSize(45, 13) |
|---|
| 371 | ); |
|---|
| 372 | m_pJackMasterBtn->hide(); |
|---|
| 373 | m_pJackMasterBtn->setPressed(true); |
|---|
| 374 | m_pJackMasterBtn->setToolTip( trUtf8("Jack-Time-Master on/off") ); |
|---|
| 375 | connect(m_pJackMasterBtn, SIGNAL(clicked(Button*)), this, SLOT(jackMasterBtnClicked(Button*))); |
|---|
| 376 | m_pJackMasterBtn->move(56, 26); |
|---|
| 377 | //~ jack time master |
|---|
| 378 | |
|---|
| 379 | m_pEngine = Hydrogen::get_instance(); |
|---|
| 380 | |
|---|
| 381 | // CPU load widget |
|---|
| 382 | m_pCpuLoadWidget = new CpuLoadWidget( pJackPanel ); |
|---|
| 383 | |
|---|
| 384 | // Midi Activity widget |
|---|
| 385 | m_pMidiActivityWidget = new MidiActivityWidget( pJackPanel ); |
|---|
| 386 | |
|---|
| 387 | m_pMidiActivityWidget->move( 10, 14 ); |
|---|
| 388 | m_pCpuLoadWidget->move( 10, 4 ); |
|---|
| 389 | //~ JACK |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | PixmapWidget *pLcdBackGround = new PixmapWidget( NULL ); |
|---|
| 393 | pLcdBackGround->setFixedSize( 256, 43 ); |
|---|
| 394 | pLcdBackGround->setPixmap( "/playerControlPanel/lcd_background.png" ); |
|---|
| 395 | hbox->addWidget( pLcdBackGround ); |
|---|
| 396 | |
|---|
| 397 | m_pShowMixerBtn = new ToggleButton( |
|---|
| 398 | pLcdBackGround, |
|---|
| 399 | "/skin_btn_on.png", |
|---|
| 400 | "/skin_btn_off.png", |
|---|
| 401 | "/skin_btn_over.png", |
|---|
| 402 | QSize( 80, 17 ), |
|---|
| 403 | true |
|---|
| 404 | ); |
|---|
| 405 | m_pShowMixerBtn->move( 7, 6 ); |
|---|
| 406 | m_pShowMixerBtn->setToolTip( trUtf8( "Show mixer" ) ); |
|---|
| 407 | m_pShowMixerBtn->setText( trUtf8( "Mixer" ) ); |
|---|
| 408 | connect(m_pShowMixerBtn, SIGNAL(clicked(Button*)), this, SLOT(showButtonClicked(Button*))); |
|---|
| 409 | |
|---|
| 410 | m_pShowInstrumentRackBtn = new ToggleButton( |
|---|
| 411 | pLcdBackGround, |
|---|
| 412 | "/skin_btn_on.png", |
|---|
| 413 | "/skin_btn_off.png", |
|---|
| 414 | "/skin_btn_over.png", |
|---|
| 415 | QSize( 160, 17 ), |
|---|
| 416 | true |
|---|
| 417 | ); |
|---|
| 418 | m_pShowInstrumentRackBtn->move( 88, 6 ); |
|---|
| 419 | m_pShowInstrumentRackBtn->setToolTip( trUtf8( "Show Instrument Rack" ) ); |
|---|
| 420 | m_pShowInstrumentRackBtn->setText( trUtf8( "Instrument rack" ) ); |
|---|
| 421 | connect( m_pShowInstrumentRackBtn, SIGNAL( clicked(Button*) ), this, SLOT( showButtonClicked( Button*)) ); |
|---|
| 422 | |
|---|
| 423 | m_pStatusLabel = new LCDDisplay(pLcdBackGround , LCDDigit::SMALL_BLUE, 30, true ); |
|---|
| 424 | m_pStatusLabel->move( 7, 25 ); |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | hbox->addStretch( 1000 ); // this must be the last widget in the HBOX!! |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | QTimer *timer = new QTimer( this ); |
|---|
| 433 | connect(timer, SIGNAL(timeout()), this, SLOT(updatePlayerControl())); |
|---|
| 434 | timer->start(100); // update player control at 10 fps |
|---|
| 435 | |
|---|
| 436 | m_pBPMTimer = new QTimer( this ); |
|---|
| 437 | connect(m_pBPMTimer, SIGNAL(timeout()), this, SLOT(onBpmTimerEvent())); |
|---|
| 438 | |
|---|
| 439 | m_pStatusTimer = new QTimer( this ); |
|---|
| 440 | connect( m_pStatusTimer, SIGNAL( timeout() ), this, SLOT( onStatusTimerEvent() ) ); |
|---|
| 441 | |
|---|
| 442 | m_pScrollTimer = new QTimer( this ); |
|---|
| 443 | connect( m_pScrollTimer, SIGNAL( timeout() ), this, SLOT( onScrollTimerEvent() ) ); |
|---|
| 444 | m_pScrollMessage = ""; |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | |
|---|
| 450 | PlayerControl::~PlayerControl() { |
|---|
| 451 | } |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | void PlayerControl::updatePlayerControl() |
|---|
| 458 | { |
|---|
| 459 | Preferences *pPref = Preferences::getInstance(); |
|---|
| 460 | HydrogenApp *pH2App = HydrogenApp::getInstance(); |
|---|
| 461 | m_pShowMixerBtn->setPressed( pH2App->getMixer()->isVisible() ); |
|---|
| 462 | m_pShowInstrumentRackBtn->setPressed( pH2App->getInstrumentRack()->isVisible() ); |
|---|
| 463 | |
|---|
| 464 | TransportPosition::State state = m_pEngine->get_transport()->get_state(); |
|---|
| 465 | if (state == TransportPosition::ROLLING ) { |
|---|
| 466 | m_pPlayBtn->setPressed(true); |
|---|
| 467 | } |
|---|
| 468 | else { |
|---|
| 469 | m_pPlayBtn->setPressed(false); |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | Song *song = m_pEngine->getSong(); |
|---|
| 473 | |
|---|
| 474 | m_pSongLoopBtn->setPressed( song->is_loop_enabled() ); |
|---|
| 475 | |
|---|
| 476 | m_pLCDBPMSpinbox->setValue( song->__bpm ); |
|---|
| 477 | |
|---|
| 478 | if ( song->get_mode() == Song::PATTERN_MODE ) { |
|---|
| 479 | m_pLiveModeBtn->setPressed( true ); |
|---|
| 480 | m_pSongModeBtn->setPressed( false ); |
|---|
| 481 | } |
|---|
| 482 | else { |
|---|
| 483 | m_pLiveModeBtn->setPressed( false ); |
|---|
| 484 | m_pSongModeBtn->setPressed( true ); |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | //beatcounter |
|---|
| 488 | if ( pPref->m_bbc == Preferences::BC_OFF ) { |
|---|
| 489 | m_pControlsBCPanel->hide(); |
|---|
| 490 | m_pBConoffBtn->setPressed(false); |
|---|
| 491 | }else |
|---|
| 492 | { |
|---|
| 493 | m_pControlsBCPanel->show(); |
|---|
| 494 | m_pBConoffBtn->setPressed(true); |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | if ( pPref->m_mmcsetplay == Preferences::SET_PLAY_OFF) { |
|---|
| 498 | m_pBCSetPlayBtn->setPressed(false); |
|---|
| 499 | }else |
|---|
| 500 | { |
|---|
| 501 | m_pBCSetPlayBtn->setPressed(true); |
|---|
| 502 | } |
|---|
| 503 | //~ beatcounter |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | if ( pPref->m_sAudioDriver == "Jack" ) { |
|---|
| 509 | m_pJackTransportBtn->show(); |
|---|
| 510 | switch ( pPref->m_bJackTransportMode ) { |
|---|
| 511 | case Preferences::NO_JACK_TRANSPORT: |
|---|
| 512 | m_pJackTransportBtn->setPressed(false); |
|---|
| 513 | // Jack Master Btn |
|---|
| 514 | m_pJackMasterBtn->setPressed(false); |
|---|
| 515 | break; |
|---|
| 516 | |
|---|
| 517 | case Preferences::USE_JACK_TRANSPORT: |
|---|
| 518 | m_pJackTransportBtn->setPressed(true); |
|---|
| 519 | //m_pJackMasterBtn->setPressed(false); |
|---|
| 520 | break; |
|---|
| 521 | } |
|---|
| 522 | } |
|---|
| 523 | else { |
|---|
| 524 | m_pJackTransportBtn->hide(); |
|---|
| 525 | } |
|---|
| 526 | |
|---|
| 527 | //jack transport master |
|---|
| 528 | #ifdef JACK_SUPPORT |
|---|
| 529 | if ( pPref->m_sAudioDriver == "Jack" ) { |
|---|
| 530 | m_pJackMasterBtn->show(); |
|---|
| 531 | switch ( pPref->m_bJackMasterMode ) { |
|---|
| 532 | case Preferences::NO_JACK_TIME_MASTER: |
|---|
| 533 | m_pJackMasterBtn->setPressed(false); |
|---|
| 534 | break; |
|---|
| 535 | |
|---|
| 536 | case Preferences::USE_JACK_TIME_MASTER: |
|---|
| 537 | if ( m_pJackTransportBtn->isPressed()){ |
|---|
| 538 | m_pJackMasterBtn->setPressed(true); |
|---|
| 539 | } |
|---|
| 540 | else |
|---|
| 541 | { |
|---|
| 542 | m_pJackMasterBtn->setPressed(false); |
|---|
| 543 | Hydrogen::get_instance()->clearJackTimeMaster(); |
|---|
| 544 | pPref->m_bJackMasterMode = Preferences::NO_JACK_TIME_MASTER; |
|---|
| 545 | } |
|---|
| 546 | //m_pJackTransportBtn->setPressed(true); |
|---|
| 547 | break; |
|---|
| 548 | } |
|---|
| 549 | } |
|---|
| 550 | else { |
|---|
| 551 | m_pJackMasterBtn->hide(); |
|---|
| 552 | |
|---|
| 553 | } |
|---|
| 554 | #endif |
|---|
| 555 | //~ jack transport master |
|---|
| 556 | |
|---|
| 557 | // time |
|---|
| 558 | float fFrames = Hydrogen::get_instance()->get_transport()->get_current_frame(); |
|---|
| 559 | float fSampleRate = m_pEngine->getAudioOutput()->getSampleRate(); |
|---|
| 560 | if ( fSampleRate != 0 ) { |
|---|
| 561 | float fSeconds = fFrames / fSampleRate; |
|---|
| 562 | |
|---|
| 563 | int nMSec = (int)( (fSeconds - (int)fSeconds) * 1000.0 ); |
|---|
| 564 | int nSeconds = ( (int)fSeconds ) % 60; |
|---|
| 565 | int nMins = (int)( fSeconds / 60.0 ) % 60; |
|---|
| 566 | int nHours = (int)( fSeconds / 3600.0 ); |
|---|
| 567 | |
|---|
| 568 | char tmp[100]; |
|---|
| 569 | sprintf(tmp, "%02d", nHours ); |
|---|
| 570 | m_pTimeDisplayH->setText( QString( tmp ) ); |
|---|
| 571 | |
|---|
| 572 | sprintf(tmp, "%02d", nMins ); |
|---|
| 573 | m_pTimeDisplayM->setText( QString( tmp ) ); |
|---|
| 574 | |
|---|
| 575 | sprintf(tmp, "%02d", nSeconds ); |
|---|
| 576 | m_pTimeDisplayS->setText( QString( tmp ) ); |
|---|
| 577 | |
|---|
| 578 | sprintf(tmp, "%03d", nMSec ); |
|---|
| 579 | m_pTimeDisplayMS->setText( QString( tmp ) ); |
|---|
| 580 | } |
|---|
| 581 | |
|---|
| 582 | m_pMetronomeBtn->setPressed(pPref->m_bUseMetronome); |
|---|
| 583 | |
|---|
| 584 | |
|---|
| 585 | //beatcounter get BC message |
|---|
| 586 | char bcstatus[4]; |
|---|
| 587 | int beatstocountondisplay = 1; |
|---|
| 588 | beatstocountondisplay = m_pEngine->getBcStatus(); |
|---|
| 589 | |
|---|
| 590 | switch (beatstocountondisplay){ |
|---|
| 591 | case 1 : |
|---|
| 592 | if (bcDisplaystatus == 1){ |
|---|
| 593 | Preferences::getInstance()->m_bbc = Preferences::BC_OFF; |
|---|
| 594 | bcDisplaystatus = 0; |
|---|
| 595 | } |
|---|
| 596 | sprintf(bcstatus, "R"); |
|---|
| 597 | m_pBCDisplayZ->setText( QString (bcstatus) ); |
|---|
| 598 | |
|---|
| 599 | break; |
|---|
| 600 | default: |
|---|
| 601 | if (Preferences::getInstance()->m_bbc == Preferences::BC_OFF){ |
|---|
| 602 | Preferences::getInstance()->m_bbc = Preferences::BC_ON; |
|---|
| 603 | bcDisplaystatus = 1; |
|---|
| 604 | } |
|---|
| 605 | sprintf(bcstatus, "%02d ", beatstocountondisplay -1); |
|---|
| 606 | m_pBCDisplayZ->setText( QString (bcstatus) ); |
|---|
| 607 | |
|---|
| 608 | } |
|---|
| 609 | //~ beatcounter |
|---|
| 610 | |
|---|
| 611 | } |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | /// Start audio engine |
|---|
| 617 | void PlayerControl::playBtnClicked(Button* ref) { |
|---|
| 618 | if (ref->isPressed()) { |
|---|
| 619 | m_pEngine->sequencer_play(); |
|---|
| 620 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8("Playing."), 5000); |
|---|
| 621 | } |
|---|
| 622 | else { |
|---|
| 623 | // m_pPlayBtn->setPressed(true); |
|---|
| 624 | m_pEngine->sequencer_stop(); |
|---|
| 625 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8("Pause."), 5000); |
|---|
| 626 | } |
|---|
| 627 | } |
|---|
| 628 | |
|---|
| 629 | |
|---|
| 630 | |
|---|
| 631 | |
|---|
| 632 | /// Stop audio engine |
|---|
| 633 | void PlayerControl::stopBtnClicked(Button* ref) |
|---|
| 634 | { |
|---|
| 635 | UNUSED( ref ); |
|---|
| 636 | m_pPlayBtn->setPressed(false); |
|---|
| 637 | m_pEngine->sequencer_stop(); |
|---|
| 638 | m_pEngine->setPatternPos( 0 ); |
|---|
| 639 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8("Stopped."), 5000); |
|---|
| 640 | } |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | /// Switch mode |
|---|
| 646 | void PlayerControl::switchModeBtnClicked(Button* ref) |
|---|
| 647 | { |
|---|
| 648 | UNUSED( ref ); |
|---|
| 649 | |
|---|
| 650 | Song *song = m_pEngine->getSong(); |
|---|
| 651 | |
|---|
| 652 | m_pEngine->sequencer_stop(); |
|---|
| 653 | m_pEngine->setPatternPos( 0 ); // from start |
|---|
| 654 | if( song->get_mode() == Song::PATTERN_MODE ) { |
|---|
| 655 | m_pEngine->getSong()->set_mode( Song::SONG_MODE ); |
|---|
| 656 | m_pSongModeBtn->setPressed(true); |
|---|
| 657 | m_pLiveModeBtn->setPressed(false); |
|---|
| 658 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8("Song mode selected."), 5000); |
|---|
| 659 | } |
|---|
| 660 | else { |
|---|
| 661 | m_pEngine->getSong()->set_mode( Song::PATTERN_MODE ); |
|---|
| 662 | m_pSongModeBtn->setPressed(false); |
|---|
| 663 | m_pLiveModeBtn->setPressed(true); |
|---|
| 664 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8("Pattern mode selected."), 5000); |
|---|
| 665 | } |
|---|
| 666 | } |
|---|
| 667 | |
|---|
| 668 | |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | /// Set Song mode |
|---|
| 672 | void PlayerControl::songModeBtnClicked(Button* ref) |
|---|
| 673 | { |
|---|
| 674 | UNUSED( ref ); |
|---|
| 675 | |
|---|
| 676 | m_pEngine->sequencer_stop(); |
|---|
| 677 | m_pEngine->setPatternPos( 0 ); // from start |
|---|
| 678 | m_pEngine->getSong()->set_mode( Song::SONG_MODE ); |
|---|
| 679 | m_pSongModeBtn->setPressed(true); |
|---|
| 680 | m_pLiveModeBtn->setPressed(false); |
|---|
| 681 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8("Song mode selected."), 5000); |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | ///Set Live mode |
|---|
| 688 | void PlayerControl::liveModeBtnClicked(Button* ref) |
|---|
| 689 | { |
|---|
| 690 | UNUSED( ref ); |
|---|
| 691 | |
|---|
| 692 | m_pEngine->sequencer_stop(); |
|---|
| 693 | m_pEngine->getSong()->set_mode( Song::PATTERN_MODE ); |
|---|
| 694 | //m_pEngine->sequencer_setNextPattern( m_pEngine->getSelectedPatternNumber() ); // imposto il pattern correntemente selezionato come il prossimo da suonare |
|---|
| 695 | m_pSongModeBtn->setPressed(false); |
|---|
| 696 | m_pLiveModeBtn->setPressed(true); |
|---|
| 697 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8("Pattern mode selected."), 5000); |
|---|
| 698 | } |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | void PlayerControl::bpmChanged() { |
|---|
| 703 | float fNewBpmValue = m_pLCDBPMSpinbox->getValue(); |
|---|
| 704 | if (fNewBpmValue < 30) { |
|---|
| 705 | fNewBpmValue = 30; |
|---|
| 706 | } |
|---|
| 707 | else if (fNewBpmValue > 400 ) { |
|---|
| 708 | fNewBpmValue = 400; |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | m_pEngine->getSong()->__is_modified = true; |
|---|
| 712 | |
|---|
| 713 | AudioEngine::get_instance()->lock("PlayerControl::bpmChanged"); |
|---|
| 714 | m_pEngine->setBPM( fNewBpmValue ); |
|---|
| 715 | AudioEngine::get_instance()->unlock(); |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | //beatcounter |
|---|
| 721 | void PlayerControl::bconoffBtnClicked( Button* ) |
|---|
| 722 | { |
|---|
| 723 | Preferences *pPref = Preferences::getInstance(); |
|---|
| 724 | if (m_pBConoffBtn->isPressed()) { |
|---|
| 725 | pPref->m_bbc = Preferences::BC_ON; |
|---|
| 726 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8(" BC Panel on"), 5000); |
|---|
| 727 | m_pControlsBCPanel->show(); |
|---|
| 728 | |
|---|
| 729 | } |
|---|
| 730 | else { |
|---|
| 731 | pPref->m_bbc = Preferences::BC_OFF; |
|---|
| 732 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8(" BC Panel off"), 5000); |
|---|
| 733 | m_pControlsBCPanel->hide(); |
|---|
| 734 | } |
|---|
| 735 | |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | void PlayerControl::bcSetPlayBtnClicked( Button* ) |
|---|
| 739 | { |
|---|
| 740 | Preferences *pPref = Preferences::getInstance(); |
|---|
| 741 | if (m_pBCSetPlayBtn->isPressed()) { |
|---|
| 742 | pPref->m_mmcsetplay = Preferences::SET_PLAY_ON; |
|---|
| 743 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8(" Count BPM and start PLAY"), 5000); |
|---|
| 744 | |
|---|
| 745 | } |
|---|
| 746 | else { |
|---|
| 747 | pPref->m_mmcsetplay = Preferences::SET_PLAY_OFF; |
|---|
| 748 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8(" Count and set BPM"), 5000); |
|---|
| 749 | } |
|---|
| 750 | |
|---|
| 751 | } |
|---|
| 752 | |
|---|
| 753 | |
|---|
| 754 | void PlayerControl::bcbButtonClicked( Button* bBtn) |
|---|
| 755 | { |
|---|
| 756 | int tmp = m_pEngine->getbeatsToCount(); |
|---|
| 757 | char tmpb[3]; // m_pBCBUpBtn |
|---|
| 758 | if ( bBtn == m_pBCBUpBtn ) { |
|---|
| 759 | tmp ++; |
|---|
| 760 | if (tmp > 16) |
|---|
| 761 | tmp = 2; |
|---|
| 762 | //small fix against qt4 png transparent problem |
|---|
| 763 | //think this will be solved in next time |
|---|
| 764 | // if (tmp < 10 ){ |
|---|
| 765 | // sprintf(tmpb, "%01d", tmp ); |
|---|
| 766 | // }else |
|---|
| 767 | // { |
|---|
| 768 | sprintf(tmpb, "%02d", tmp ); |
|---|
| 769 | // } |
|---|
| 770 | m_pBCDisplayB->setText( QString( tmpb ) ); |
|---|
| 771 | m_pEngine->setbeatsToCount( tmp ); |
|---|
| 772 | } |
|---|
| 773 | else { |
|---|
| 774 | tmp --; |
|---|
| 775 | if (tmp < 2 ) |
|---|
| 776 | tmp = 16; |
|---|
| 777 | //small fix against qt4 png transparent problem |
|---|
| 778 | //think this will be solved in next time |
|---|
| 779 | // if (tmp < 10 ){ |
|---|
| 780 | // sprintf(tmpb, "%01d", tmp ); |
|---|
| 781 | // }else |
|---|
| 782 | // { |
|---|
| 783 | sprintf(tmpb, "%02d", tmp ); |
|---|
| 784 | // } |
|---|
| 785 | m_pBCDisplayB->setText( QString( tmpb ) ); |
|---|
| 786 | m_pEngine->setbeatsToCount( tmp ); |
|---|
| 787 | } |
|---|
| 788 | } |
|---|
| 789 | |
|---|
| 790 | |
|---|
| 791 | void PlayerControl::bctButtonClicked( Button* tBtn) |
|---|
| 792 | { |
|---|
| 793 | float tmp = m_pEngine->getNoteLength() * 4; |
|---|
| 794 | |
|---|
| 795 | if ( tBtn == m_pBCTUpBtn) { |
|---|
| 796 | tmp = tmp / 2 ; |
|---|
| 797 | if (tmp < 1) |
|---|
| 798 | tmp = 8; |
|---|
| 799 | |
|---|
| 800 | m_pBCDisplayT->setText( QString::number( tmp ) ); |
|---|
| 801 | m_pEngine->setNoteLength( (tmp) / 4 ); |
|---|
| 802 | } else { |
|---|
| 803 | tmp = tmp * 2; |
|---|
| 804 | if (tmp > 8 ) |
|---|
| 805 | tmp = 1; |
|---|
| 806 | m_pBCDisplayT->setText( QString::number(tmp) ); |
|---|
| 807 | m_pEngine->setNoteLength( (tmp) / 4 ); |
|---|
| 808 | } |
|---|
| 809 | } |
|---|
| 810 | //~ beatcounter |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | |
|---|
| 814 | void PlayerControl::jackTransportBtnClicked( Button* ) |
|---|
| 815 | { |
|---|
| 816 | Preferences *pPref = Preferences::getInstance(); |
|---|
| 817 | |
|---|
| 818 | if (m_pJackTransportBtn->isPressed()) { |
|---|
| 819 | AudioEngine::get_instance()->lock( "PlayerControl::jackTransportBtnClicked" ); |
|---|
| 820 | pPref->m_bJackTransportMode = Preferences::USE_JACK_TRANSPORT; |
|---|
| 821 | AudioEngine::get_instance()->unlock(); |
|---|
| 822 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8("Jack-transport mode = On"), 5000); |
|---|
| 823 | } |
|---|
| 824 | else { |
|---|
| 825 | AudioEngine::get_instance()->lock( "PlayerControl::jackTransportBtnClicked" ); |
|---|
| 826 | pPref->m_bJackTransportMode = Preferences::NO_JACK_TRANSPORT; |
|---|
| 827 | AudioEngine::get_instance()->unlock(); |
|---|
| 828 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8("Jack-transport mode = Off"), 5000); |
|---|
| 829 | } |
|---|
| 830 | |
|---|
| 831 | if (pPref->m_sAudioDriver != "Jack") { |
|---|
| 832 | QMessageBox::warning( this, "Hydrogen", trUtf8( "JACK-transport will work only with JACK driver." ) ); |
|---|
| 833 | } |
|---|
| 834 | } |
|---|
| 835 | |
|---|
| 836 | |
|---|
| 837 | void PlayerControl::jackTimeMasterEvent( int data ) |
|---|
| 838 | { |
|---|
| 839 | switch( data ) { |
|---|
| 840 | case JACK_TIME_MASTER_NOW: |
|---|
| 841 | m_pJackMasterBtn->setPressed(true); |
|---|
| 842 | break; |
|---|
| 843 | case JACK_TIME_MASTER_NO_MORE: |
|---|
| 844 | m_pJackMasterBtn->setPressed(false); |
|---|
| 845 | break; |
|---|
| 846 | } |
|---|
| 847 | } |
|---|
| 848 | |
|---|
| 849 | //jack time master |
|---|
| 850 | void PlayerControl::jackMasterBtnClicked( Button* ) |
|---|
| 851 | { |
|---|
| 852 | #ifdef JACK_SUPPORT |
|---|
| 853 | Preferences *pPref = Preferences::getInstance(); |
|---|
| 854 | |
|---|
| 855 | // This function just manipulates Hydrogen. |
|---|
| 856 | // The widget updates itself by the EventListener |
|---|
| 857 | if (m_pJackMasterBtn->isPressed()) { |
|---|
| 858 | // Set as time master. |
|---|
| 859 | Hydrogen::get_instance()->setJackTimeMaster(false); |
|---|
| 860 | pPref->m_bJackMasterMode = Preferences::USE_JACK_TIME_MASTER; |
|---|
| 861 | HydrogenApp::getInstance()->setStatusBarMessage(trUtf8(" Jack-Time-Master mode = On"), 5000); |
|---|
| 862 | } |
|---|
| 863 | else { |
|---|
| 864 | // Clear time master. |
|---|
| 865 | pPref->m_bJackMasterMode = Preferences::NO_JACK_TIME_MASTER; |
|---|
| 866 | (HydrogenApp::getInstance())->setStatusBarMessage(trUtf8(" Jack-Time-Master mode = Off"), 5000); |
|---|
| 867 | Hydrogen::get_instance()->clearJackTimeMaster(); |
|---|
| 868 | } |
|---|
| 869 | |
|---|
| 870 | if (pPref->m_sAudioDriver != "Jack") { |
|---|
| 871 | QMessageBox::warning( this, "Hydrogen", trUtf8( "JACK-transport will work only with JACK driver." ) ); |
|---|
| 872 | } |
|---|
| 873 | #endif |
|---|
| 874 | } |
|---|
| 875 | //~ jack time master |
|---|
| 876 | |
|---|
| 877 | void PlayerControl::bpmClicked() |
|---|
| 878 | { |
|---|
| 879 | bool bIsOkPressed; |
|---|
| 880 | double fNewVal= QInputDialog::getDouble( this, "Hydrogen", trUtf8( "New BPM value" ), m_pLCDBPMSpinbox->getValue(), 10, 400, 2, &bIsOkPressed ); |
|---|
| 881 | if ( bIsOkPressed ) { |
|---|
| 882 | if ( fNewVal < 30 ) { |
|---|
| 883 | return; |
|---|
| 884 | } |
|---|
| 885 | |
|---|
| 886 | m_pEngine->getSong()->__is_modified = true; |
|---|
| 887 | |
|---|
| 888 | AudioEngine::get_instance()->lock( "PlayerControl::bpmChanged"); |
|---|
| 889 | m_pEngine->setBPM( fNewVal ); |
|---|
| 890 | AudioEngine::get_instance()->unlock(); |
|---|
| 891 | } |
|---|
| 892 | else { |
|---|
| 893 | // user entered nothing or pressed Cancel |
|---|
| 894 | } |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | |
|---|
| 898 | void PlayerControl::bpmButtonPressed( Button* pBtn) |
|---|
| 899 | { |
|---|
| 900 | if ( pBtn == m_pBPMUpBtn ) { |
|---|
| 901 | m_pLCDBPMSpinbox->upBtnClicked(); |
|---|
| 902 | m_nBPMIncrement = 1; |
|---|
| 903 | } |
|---|
| 904 | else { |
|---|
| 905 | m_pLCDBPMSpinbox->downBtnClicked(); |
|---|
| 906 | m_nBPMIncrement = -1; |
|---|
| 907 | } |
|---|
| 908 | m_pBPMTimer->start( 100 ); |
|---|
| 909 | } |
|---|
| 910 | |
|---|
| 911 | |
|---|
| 912 | void PlayerControl::bpmButtonClicked( Button* ) |
|---|
| 913 | { |
|---|
| 914 | m_pBPMTimer->stop(); |
|---|
| 915 | } |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | void PlayerControl::onBpmTimerEvent() |
|---|
| 919 | { |
|---|
| 920 | if (m_nBPMIncrement == 1) { |
|---|
| 921 | m_pLCDBPMSpinbox->upBtnClicked(); |
|---|
| 922 | } |
|---|
| 923 | else { |
|---|
| 924 | m_pLCDBPMSpinbox->downBtnClicked(); |
|---|
| 925 | } |
|---|
| 926 | } |
|---|
| 927 | |
|---|
| 928 | |
|---|
| 929 | void PlayerControl::FFWDBtnClicked( Button* ) |
|---|
| 930 | { |
|---|
| 931 | Hydrogen *pEngine = Hydrogen::get_instance(); |
|---|
| 932 | pEngine->setPatternPos( pEngine->getPatternPos() + 1 ); |
|---|
| 933 | } |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | void PlayerControl::RewindBtnClicked( Button* ) |
|---|
| 938 | { |
|---|
| 939 | Hydrogen *pEngine = Hydrogen::get_instance(); |
|---|
| 940 | pEngine->setPatternPos( pEngine->getPatternPos() - 1 ); |
|---|
| 941 | } |
|---|
| 942 | |
|---|
| 943 | |
|---|
| 944 | |
|---|
| 945 | void PlayerControl::songLoopBtnClicked( Button* ) |
|---|
| 946 | { |
|---|
| 947 | Hydrogen *pEngine = Hydrogen::get_instance(); |
|---|
| 948 | Song *song = pEngine->getSong(); |
|---|
| 949 | song->set_loop_enabled( ! song->is_loop_enabled() ); |
|---|
| 950 | song->__is_modified = true; |
|---|
| 951 | |
|---|
| 952 | if ( song->is_loop_enabled() ) { |
|---|
| 953 | HydrogenApp::getInstance()->setStatusBarMessage(trUtf8("Loop song = On"), 5000); |
|---|
| 954 | } |
|---|
| 955 | else { |
|---|
| 956 | HydrogenApp::getInstance()->setStatusBarMessage(trUtf8("Loop song = Off"), 5000); |
|---|
| 957 | } |
|---|
| 958 | } |
|---|
| 959 | |
|---|
| 960 | void PlayerControl::metronomeButtonClicked(Button* ref) |
|---|
| 961 | { |
|---|
| 962 | Preferences::getInstance()->m_bUseMetronome = ref->isPressed(); |
|---|
| 963 | } |
|---|
| 964 | |
|---|
| 965 | |
|---|
| 966 | |
|---|
| 967 | void PlayerControl::showButtonClicked( Button* pRef ) |
|---|
| 968 | { |
|---|
| 969 | //INFOLOG( "[showButtonClicked]" ); |
|---|
| 970 | HydrogenApp *pH2App = HydrogenApp::getInstance(); |
|---|
| 971 | |
|---|
| 972 | if ( pRef == m_pShowMixerBtn ) { |
|---|
| 973 | bool isVisible = pH2App->getMixer()->isVisible(); |
|---|
| 974 | pH2App->showMixer( !isVisible ); |
|---|
| 975 | } |
|---|
| 976 | else if ( pRef == m_pShowInstrumentRackBtn ) { |
|---|
| 977 | bool isVisible = pH2App->getInstrumentRack()->isVisible(); |
|---|
| 978 | pH2App->getInstrumentRack()->setHidden( isVisible ); |
|---|
| 979 | } |
|---|
| 980 | } |
|---|
| 981 | |
|---|
| 982 | |
|---|
| 983 | |
|---|
| 984 | void PlayerControl::showMessage( const QString& msg, int msec ) |
|---|
| 985 | { |
|---|
| 986 | if ( m_pScrollTimer->isActive ()) |
|---|
| 987 | m_pScrollTimer->stop(); |
|---|
| 988 | m_pStatusLabel->setText( msg ); |
|---|
| 989 | m_pStatusTimer->start( msec ); |
|---|
| 990 | |
|---|
| 991 | |
|---|
| 992 | } |
|---|
| 993 | |
|---|
| 994 | |
|---|
| 995 | |
|---|
| 996 | void PlayerControl::showScrollMessage( const QString& msg, int msec, bool test ) |
|---|
| 997 | { |
|---|
| 998 | |
|---|
| 999 | if ( test == false ){ |
|---|
| 1000 | m_pStatusLabel->setText( msg ); |
|---|
| 1001 | m_pScrollTimer->start( msec ); |
|---|
| 1002 | }else |
|---|
| 1003 | { |
|---|
| 1004 | m_pScrollMessage = msg; |
|---|
| 1005 | m_pStatusLabel->setText( msg ); |
|---|
| 1006 | m_pStatusTimer->start( msec ); |
|---|
| 1007 | m_pScrollTimer->start( msec ); |
|---|
| 1008 | |
|---|
| 1009 | } |
|---|
| 1010 | |
|---|
| 1011 | |
|---|
| 1012 | } |
|---|
| 1013 | |
|---|
| 1014 | void PlayerControl::onScrollTimerEvent() |
|---|
| 1015 | { |
|---|
| 1016 | int lwl = 25; |
|---|
| 1017 | int msgLength = m_pScrollMessage.length(); |
|---|
| 1018 | if ( msgLength > lwl) |
|---|
| 1019 | m_pScrollMessage = m_pScrollMessage.right( msgLength - 1 ); |
|---|
| 1020 | m_pScrollTimer->stop(); |
|---|
| 1021 | |
|---|
| 1022 | if ( msgLength > lwl){ |
|---|
| 1023 | showScrollMessage( m_pScrollMessage, 150, false ); |
|---|
| 1024 | }else |
|---|
| 1025 | { |
|---|
| 1026 | showMessage( m_pScrollMessage, 2000 ); |
|---|
| 1027 | } |
|---|
| 1028 | } |
|---|
| 1029 | |
|---|
| 1030 | void PlayerControl::onStatusTimerEvent() |
|---|
| 1031 | { |
|---|
| 1032 | m_pStatusTimer->stop(); |
|---|
| 1033 | m_pStatusLabel->setText( "" ); |
|---|
| 1034 | } |
|---|
| 1035 | |
|---|
| 1036 | |
|---|
| 1037 | |
|---|
| 1038 | //:::::::::::::::::::::::::::::::::::::::::::::::: |
|---|
| 1039 | |
|---|
| 1040 | |
|---|
| 1041 | |
|---|
| 1042 | MetronomeWidget::MetronomeWidget(QWidget *pParent) |
|---|
| 1043 | : QWidget( pParent ) |
|---|
| 1044 | , Object( "MetronomeWidget" ) |
|---|
| 1045 | , m_nValue( 0 ) |
|---|
| 1046 | , m_state( METRO_OFF ) |
|---|
| 1047 | { |
|---|
| 1048 | // INFOLOG( "INIT" ); |
|---|
| 1049 | HydrogenApp::getInstance()->addEventListener( this ); |
|---|
| 1050 | |
|---|
| 1051 | m_metro_off.load( Skin::getImagePath() + "/playerControlPanel/metronome_off.png" ); |
|---|
| 1052 | m_metro_on_firstbeat.load( Skin::getImagePath() + "/playerControlPanel/metronome_up.png" ); |
|---|
| 1053 | m_metro_on.load( Skin::getImagePath() + "/playerControlPanel/metronome_down.png" ); |
|---|
| 1054 | |
|---|
| 1055 | QTimer *timer = new QTimer(this); |
|---|
| 1056 | connect( timer, SIGNAL( timeout() ), this, SLOT( updateWidget() ) ); |
|---|
| 1057 | timer->start(50); // update player control at 20 fps |
|---|
| 1058 | } |
|---|
| 1059 | |
|---|
| 1060 | |
|---|
| 1061 | MetronomeWidget::~MetronomeWidget() |
|---|
| 1062 | { |
|---|
| 1063 | // INFOLOG( "DESTROY" ); |
|---|
| 1064 | } |
|---|
| 1065 | |
|---|
| 1066 | |
|---|
| 1067 | void MetronomeWidget::metronomeEvent( int nValue ) |
|---|
| 1068 | { |
|---|
| 1069 | if (nValue == 1) { |
|---|
| 1070 | m_state = METRO_FIRST; |
|---|
| 1071 | m_nValue = 5; |
|---|
| 1072 | } |
|---|
| 1073 | else { |
|---|
| 1074 | m_state = METRO_ON; |
|---|
| 1075 | m_nValue = 5; |
|---|
| 1076 | } |
|---|
| 1077 | updateWidget(); |
|---|
| 1078 | } |
|---|
| 1079 | |
|---|
| 1080 | |
|---|
| 1081 | void MetronomeWidget::updateWidget() |
|---|
| 1082 | { |
|---|
| 1083 | if ( m_nValue > 0 ) { |
|---|
| 1084 | m_nValue -= 1; |
|---|
| 1085 | if (m_nValue == 0 ) { |
|---|
| 1086 | m_nValue = 0; |
|---|
| 1087 | m_state = METRO_OFF; |
|---|
| 1088 | } |
|---|
| 1089 | update(); |
|---|
| 1090 | } |
|---|
| 1091 | } |
|---|
| 1092 | |
|---|
| 1093 | |
|---|
| 1094 | void MetronomeWidget::paintEvent( QPaintEvent* ev) |
|---|
| 1095 | { |
|---|
| 1096 | QPainter painter(this); |
|---|
| 1097 | switch( m_state ) { |
|---|
| 1098 | case METRO_FIRST: |
|---|
| 1099 | painter.drawPixmap( ev->rect(), m_metro_on_firstbeat, ev->rect() ); |
|---|
| 1100 | break; |
|---|
| 1101 | |
|---|
| 1102 | case METRO_ON: |
|---|
| 1103 | painter.drawPixmap( ev->rect(), m_metro_on, ev->rect() ); |
|---|
| 1104 | break; |
|---|
| 1105 | |
|---|
| 1106 | case METRO_OFF: |
|---|
| 1107 | painter.drawPixmap( ev->rect(), m_metro_off, ev->rect() ); |
|---|
| 1108 | break; |
|---|
| 1109 | } |
|---|
| 1110 | } |
|---|
| 1111 | |
|---|
| 1112 | |
|---|
| 1113 | |
|---|
| 1114 | |
|---|