1 /* 2 * tracker/Tracker.h 3 * 4 * Copyright 2009 Peter Barth 5 * 6 * This file is part of Milkytracker. 7 * 8 * Milkytracker is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * Milkytracker is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with Milkytracker. If not, see <http://www.gnu.org/licenses/>. 20 * 21 */ 22 23 #ifndef TRACKER__H 24 #define TRACKER__H 25 26 #include "BasicTypes.h" 27 #include "Event.h" 28 #include "EditModes.h" 29 #include "FileTypes.h" 30 #include "XModule.h" 31 32 #define INPUTCONTAINERHEIGHT_DEFAULT (25+SCROLLBUTTONSIZE+4) 33 #define INPUTCONTAINERHEIGHT_EXTENDED (25+SCROLLBUTTONSIZE+4+13) 34 35 template<class Type> 36 class PPSimpleVector; 37 38 class PPScreen; 39 class ModuleEditor; 40 class PatternEditor; 41 class SampleEditor; 42 class EnvelopeEditor; 43 class PlayerController; 44 class PlayerMaster; 45 class TabManager; 46 class PatternEditorControl; 47 class PPListBox; 48 class PPStaticText; 49 class EnvelopeEditorControl; 50 class PianoControl; 51 class PeakLevelControl; 52 class ScopesControl; 53 class SampleEditorControl; 54 class PPContainer; 55 class PPMessageBoxContainer; 56 class TrackerSettingsDatabase; 57 class PPDictionaryKey; 58 class PPFont; 59 60 // OS Interfaces 61 class PPSavePanel; 62 class PPOpenPanel; 63 64 // Section forwards 65 class SectionAbstract; 66 class SectionTranspose; 67 class SectionAdvancedEdit; 68 class SectionDiskMenu; 69 class SectionHDRecorder; 70 class SectionSettings; 71 class SectionInstruments; 72 class SectionSamples; 73 class SectionQuickOptions; 74 class SectionOptimize; 75 class SectionAbout; 76 77 class PatternEditorControl; 78 class InputControlListener; 79 class PPDialogBase; 80 class DialogResponder; 81 class ToolInvokeHelper; 82 83 struct TMixerSettings; 84 85 // Key binding forwards 86 class Tracker; 87 typedef void (Tracker::*TTrackerKeyBindingHandler)(); 88 89 template<class Type> 90 class PPKeyBindings; 91 92 class Tracker : public EventListenerInterface 93 { 94 private: 95 // I've replaced some constants 96 #ifndef __LOWRES__ 97 pp_int32 SCOPESHEIGHT(); 98 pp_int32 CURRENTSCOPESHEIGHT(); UPPERSECTIONDEFAULTHEIGHTWOINS()99 pp_int32 UPPERSECTIONDEFAULTHEIGHTWOINS() { return 54+64; } UPPERSECTIONDEFAULTHEIGHT()100 pp_int32 UPPERSECTIONDEFAULTHEIGHT() { return ((UPPERSECTIONDEFAULTHEIGHTWOINS())+(CURRENTSCOPESHEIGHT())); } INSTRUMENTSECTIONDEFAULTHEIGHT()101 pp_int32 INSTRUMENTSECTIONDEFAULTHEIGHT() { return 206; } 102 pp_int32 SAMPLESECTIONDEFAULTHEIGHT(); TABHEADERHEIGHT()103 pp_int32 TABHEADERHEIGHT() { return 16; } 104 pp_int32 MAXEDITORHEIGHT(); 105 #else 106 pp_int32 SCOPESHEIGHT() { return 64; } 107 pp_int32 SCOPESWIDTH() { return 320-26; } 108 pp_int32 UPPERSECTIONDEFAULTHEIGHT() { return (64+16); } 109 pp_int32 INSTRUMENTSECTIONDEFAULTHEIGHT() { return 188; } 110 pp_int32 SAMPLESECTIONDEFAULTHEIGHT() { return 184; } 111 pp_int32 NUMSUBMENUS() { return 5; } 112 pp_int32 MAXEDITORHEIGHT(); 113 #endif 114 115 bool* muteChannels; 116 117 TabManager* tabManager; 118 PlayerController* playerController; 119 PlayerMaster* playerMaster; 120 ModuleEditor* moduleEditor; 121 class PlayerLogic* playerLogic; 122 class RecorderLogic* recorderLogic; 123 124 PatternEditorControl* patternEditorControl; 125 PeakLevelControl* peakLevelControl; 126 ScopesControl* scopesControl; 127 PPStaticText* playTimeText; 128 129 // - Sections -------------------------------------------------------------- 130 class SectionSwitcher* sectionSwitcher; 131 132 PPSimpleVector<SectionAbstract>* sections; 133 SectionTranspose* sectionTranspose; 134 SectionAdvancedEdit* sectionAdvancedEdit; 135 SectionDiskMenu* sectionDiskMenu; 136 SectionHDRecorder* sectionHDRecorder; 137 SectionSettings* sectionSettings; 138 SectionInstruments* sectionInstruments; 139 SectionSamples* sectionSamples; 140 SectionQuickOptions* sectionQuickOptions; 141 SectionOptimize* sectionOptimize; 142 SectionAbout* sectionAbout; 143 144 InputControlListener* inputControlListener; 145 146 DialogResponder* responder; 147 PPDialogBase* dialog; 148 ToolInvokeHelper* toolInvokeHelper; 149 150 PPScreen* screen; 151 152 TrackerSettingsDatabase* settingsDatabase; 153 TrackerSettingsDatabase* settingsDatabaseCopy; 154 155 PPSystemString currentFileName; 156 bool lastState; 157 158 // - Tracker mode ---------------------------------------------------------- 159 EditModes editMode; 160 161 // - Misc. settings -------------------------------------------------------- 162 bool extendedOrderlist; 163 bool followSong; 164 bool caughtMouseInUpperLeftCorner; 165 bool useClassicBrowser; 166 167 // - Keyboard bindings ----------------------------------------------------- 168 PPKeyBindings<TTrackerKeyBindingHandler>* eventKeyDownBindings; 169 PPKeyBindings<TTrackerKeyBindingHandler>* eventKeyDownBindingsMilkyTracker; 170 PPKeyBindings<TTrackerKeyBindingHandler>* eventKeyDownBindingsFastTracker; 171 172 // - settings -------------------------------------------------------------- 173 void buildDefaultSettings(); 174 void applySettingByKey(PPDictionaryKey* theKey, TMixerSettings& settings, pp_uint32 version); 175 176 static void getMixerSettingsFromDatabase(TMixerSettings& mixerSettings, 177 TrackerSettingsDatabase& currentSettings); 178 179 void applySettings(TrackerSettingsDatabase* newSettings, 180 TrackerSettingsDatabase* currentSettings = NULL, 181 bool applyMixerSettings = true, 182 bool allowMixerRestart = true); 183 184 // - global controls ------------------------------------------------------- 185 PPListBox* listBoxOrderList; 186 PPListBox* listBoxInstruments; 187 PPListBox* listBoxSamples; 188 189 // - build UI parts -------------------------------------------------------- 190 void initSectionOrderlist(pp_int32 x, pp_int32 y); 191 void initSectionSpeed(pp_int32 x, pp_int32 y); 192 void initSectionPattern(pp_int32 x, pp_int32 y); 193 void initSectionMainOptions(pp_int32 x, pp_int32 y); 194 void initListboxesSection(pp_int32 x, pp_int32 y); 195 196 // - instrument selector dialog -------------------------------------------- 197 void initAdvEdit(); 198 199 void initInstrumentChooser(pp_int32 id, const PPString& buttonText, const PPString& buttonText2, const PPString& caption, 200 const PPString& userString1, const PPString& userString2, 201 pp_int32 srcSelection = -1, pp_int32 srcSelection2 = -1, pp_int32 srcSelection3 = -1); 202 void updateInstrumentChooser(bool repaint = true); 203 204 PPMessageBoxContainer* instrumentChooser; 205 206 // - message boxes --------------------------------------------------------- 207 PPMessageBoxContainer* messageBoxContainerGeneric; 208 209 enum MessageBoxTypes 210 { 211 MessageBox_OK, 212 MessageBox_YESNO, 213 MessageBox_YESNOCANCEL 214 }; 215 void showMessageBox(pp_int32 id, const PPString& caption, MessageBoxTypes type, bool update = true); 216 void showMessageBoxSized(pp_int32 id, const PPString& caption, MessageBoxTypes type, pp_int32 width = -1, pp_int32 height = -1, bool update = true); 217 void showQuitMessageBox(const char* caption, const char* cpationOk, const char* captionCancel); 218 219 // - software input panel -------------------------------------------------- 220 PPContainer* inputContainerCurrent; 221 PPContainer* inputContainerDefault; 222 PPContainer* inputContainerExtended; 223 void initInputContainerDefault(pp_int32 x, pp_int32 y); 224 void initInputContainerExtended(pp_int32 x, pp_int32 y); 225 226 enum SIPs 227 { 228 SIPDefault, 229 SIPExtended 230 }; 231 void setInputControl(SIPs sip); 232 void moveInputControls(pp_uint32 deltay); 233 void hideInputControl(bool bHide = true); 234 235 // - GUI refreshing -------------------------------------------------------- 236 void updateAboutToggleButton(pp_int32 id, bool b, bool repaint = true); 237 238 void updateSongTitle(bool repaint = true); 239 240 #ifdef __LOWRES__ 241 void updateJamMenuOrder(bool repaint = true); 242 #endif 243 void updateOrderlist(bool repaint = true); 244 void updateSongLength(bool repaint = true); 245 void updateSongRepeat(bool repaint = true); 246 247 void updateBPM(bool repaint = true); 248 bool updateSpeed(bool repaint = true); 249 void updatePatternAddAndOctave(bool repaint = true); 250 251 void updatePatternIndex(bool repaint = true); 252 void updatePatternLength(bool repaint = true); 253 void updatePattern(bool repaint = true); 254 255 void updateSamplesListBox(bool repaint = true); 256 void updateInstrumentsListBox(bool repaint = true); 257 258 void updateSongInfo(bool repaint = true); 259 260 void updateTabTitle(); 261 void updateWindowTitle(); 262 void updateWindowTitle(const PPSystemString& fileName); 263 264 bool updatePianoControl(PianoControl* pianoControl); 265 bool updatePeakLevelControl(); 266 bool updatePlayTime(); 267 268 void updateSampleEditor(bool repaint = true, bool force = false); 269 void updateSampleEditorAndInstrumentSection(bool repaint = true); 270 271 void updateAfterLoad(bool loadResult, bool wasPlaying, bool wasPlayingPattern); 272 void updateAfterTabSwitch(); 273 274 // - show hide GUI sections ------------------------------------------------ 275 // Show/hide main section (song settings + main menu) 276 void showSongSettings(bool show); 277 void showMainOptions(bool show); 278 279 #ifdef __LOWRES__ 280 void selectScopesControl(pp_int32 ctrlType); 281 void updateScopesControlButtons(); 282 void toggleJamMenuPianoSize(); 283 void flipInstrumentListBoxes(); 284 #endif 285 286 void showMainMenu(bool show, bool showInstrumentSelector); 287 288 void showScopes(bool visible, pp_uint32 style); 289 // - misc. ----------------------------------------------------------------- 290 pp_int32 lastPos, lastRow; 291 pp_int32 lastSpeed, lastBPM, lastMainVol; resetStateMemories()292 void resetStateMemories() 293 { 294 lastPos = lastRow = -1; 295 lastSpeed = lastBPM = lastMainVol = -1; 296 } 297 298 bool updateSongPosition(pp_int32 pos = -1, pp_int32 row = -1, bool fast = false); 299 // this always repaints, so no bool return value 300 void updateRecordButton(PPContainer* container, const PPColor& pColor); 301 void doFollowSong(); 302 getPatternEditorControl()303 PatternEditorControl* getPatternEditorControl() { return patternEditorControl; } 304 void updatePatternEditorControl(bool repaint = true, bool fast = false); 305 PatternEditor* getPatternEditor(); 306 SampleEditor* getSampleEditor(); 307 EnvelopeEditor* getEnvelopeEditor(); 308 309 pp_int32 getOrderListBoxIndex(); 310 void setOrderListIndex(pp_int32 index); 311 bool isEditingCurrentOrderlistPattern(); 312 pp_int32 getInstrumentToPlay(pp_int32 note, PlayerController*& playerController); 313 314 void setNumChannels(pp_int32 numChannels, bool repaint = true); 315 316 bool isActiveEditing(); 317 318 void ensureSongStopped(bool bResetMainVolume, bool suspend); 319 void ensureSongPlaying(bool continuePlaying); 320 void initPlayback(); 321 322 bool shouldFollowSong(); 323 324 bool getFollowSong(); 325 void setFollowSong(bool b, bool repaint = true); 326 327 bool getProspectiveMode(); 328 void setProspectiveMode(bool b, bool repaint = true); 329 330 bool getCursorWrapAround(); 331 void setCursorWrapAround(bool b, bool repaint = true); 332 333 void setLiveSwitch(bool b, bool repaint = true); 334 335 void updateSongRow(bool checkFollowSong = true); 336 337 void selectInstrument(pp_int32 instrument); 338 void fillInstrumentListBox(PPListBox* listBox, ModuleEditor* moduleEditor = NULL); 339 void fillSampleListBox(PPListBox* listBox, pp_int32 insIndex, ModuleEditor* moduleEditor = NULL); 340 void fillModuleListBox(PPListBox* listBox); 341 342 void setChanged(); 343 344 bool checkForChanges(ModuleEditor* module = NULL); 345 bool checkForChangesOpenModule(); 346 347 bool swapAndCopyHandler(pp_int32 messageBoxID, pp_int32 messageBoxButtonID); 348 void handleQuit(); 349 bool messageBoxEventListener(pp_int32 messageBoxID, pp_int32 messageBoxButtonID); 350 351 void rearrangePatternEditorControl(); 352 void rearrangePatternEditorControlOrInstrumentContainer(); 353 354 void expandOrderlist(bool b); 355 356 void flipSpeedSection(); 357 358 void enableInstrument(bool b); 359 360 void commitListBoxChanges(); 361 362 // Signal waitstate 363 void signalWaitState(bool b); 364 365 // - Load/Save ------------------------------------------------------------- 366 FileTypes currentSaveFileType; 367 PPSavePanel* savePanel; 368 EventListenerInterface* fileSystemChangedListener; 369 370 FileTypes getCurrentSelectedSampleSaveType(); 371 372 struct TPrepareLoadingParameters 373 { 374 FileTypes eType; 375 PPSystemString filename; 376 PPSystemString preferredFilename; 377 bool suspendPlayer; 378 bool repaint; 379 bool res; 380 PPString lastError; 381 bool wasPlaying; 382 bool wasPlayingPattern; 383 bool abortLoading; 384 bool deleteFile; 385 bool didOpenTab; 386 TPrepareLoadingParametersTPrepareLoadingParameters387 TPrepareLoadingParameters() : 388 abortLoading(false), 389 deleteFile(false), 390 didOpenTab(false) 391 { 392 } 393 } loadingParameters; 394 395 static pp_uint32 fileTypeToHint(FileTypes type); 396 397 void prepareLoadSaveUI(); 398 void finishLoadSaveUI(); 399 400 bool loadGenericFileType(const PPSystemString& fileName); 401 402 bool prepareLoading(FileTypes eType, 403 const PPSystemString& fileName, 404 bool suspendPlayer, 405 bool repaint, bool 406 saveCheck); 407 408 bool finishLoading(); 409 410 bool loadTypeFromFile(FileTypes eType, 411 const PPSystemString& fileName, 412 bool suspendPlayer = true, 413 bool repaint = true, 414 bool saveCheck = true); 415 416 bool loadTypeWithDialog(FileTypes eType, 417 bool suspendPlayer = true, 418 bool repaint = true); 419 void loadType(FileTypes eType); 420 421 bool prepareSavingWithDialog(FileTypes eType); 422 bool saveTypeWithDialog(FileTypes eType, EventListenerInterface* fileSystemChangedListener = NULL); 423 bool saveCurrentModuleAsSelectedType(); 424 void saveType(FileTypes eType); 425 void save(); 426 void saveAs(); 427 void handleSaveProceed(); 428 void handleSaveCancel(); 429 430 void buildMODSaveErrorWarning(pp_int32 error); 431 void estimateSongLength(bool signalWait = false); 432 433 public: 434 Tracker(); 435 436 virtual ~Tracker(); 437 setScreen(PPScreen * screen)438 void setScreen(PPScreen* screen) { this->screen = screen; } 439 440 void initUI(); 441 442 void setModuleNumChannels(pp_uint32 numChannels); 443 444 // PPEvent listener 445 pp_int32 handleEvent(PPObject* sender, PPEvent* event); 446 447 PPSize getWindowSizeFromDatabase(); 448 bool getFullScreenFlagFromDatabase(); 449 pp_int32 getScreenScaleFactorFromDatabase(); 450 bool getShowSplashFlagFromDatabase(); 451 452 void showSplash(); 453 void hideSplash(); 454 455 // Tracker startup 456 void startUp(bool forceNoSplash = false); 457 458 // Tracker shutdown 459 bool shutDown(); 460 461 mp_sint32 saveModule(const PPSystemString& fileName); 462 463 void sendNoteDown(pp_int32 note, pp_int32 volume = -1); 464 void sendNoteUp(pp_int32 note); 465 466 private: 467 void switchEditMode(EditModes mode); 468 469 // Process keyboard events according to current edit mode 470 void processShortcuts(PPEvent* event); 471 472 // Process messagebox shortcuts (RETURN & ESC) 473 bool processMessageBoxShortcuts(PPEvent* event); 474 475 void processShortcutsMilkyTracker(PPEvent* event); 476 477 void selectNextOrder(bool wrap = false); 478 void selectPreviousOrder(bool wrap = false); 479 480 void selectNextInstrument(); 481 void selectPreviousInstrument(); 482 483 void processShortcutsFastTracker(PPEvent* event); 484 485 // - Keyboard bindings ----------------------------------------------------- 486 pp_int16 currentKeyCode; 487 488 bool executeBinding(const PPKeyBindings<TTrackerKeyBindingHandler>* bindings, pp_uint16 keyCode); 489 void initKeyBindings(); 490 491 void eventKeyDownBinding_OpenTab(); 492 void eventKeyDownBinding_CloseTab(); 493 494 void eventKeyDownBinding_SwitchToNextTab(); 495 void eventKeyDownBinding_SwitchToPreviousTab(); 496 497 void setOctave(pp_uint32 octave); 498 499 void eventKeyDownBinding_SelectOctave1(); 500 void eventKeyDownBinding_SelectOctave2(); 501 void eventKeyDownBinding_SelectOctave3(); 502 void eventKeyDownBinding_SelectOctave4(); 503 void eventKeyDownBinding_SelectOctave5(); 504 void eventKeyDownBinding_SelectOctave6(); 505 void eventKeyDownBinding_SelectOctave7(); 506 void eventKeyDownBinding_SelectOctave8(); 507 508 void eventKeyDownBinding_PlaySong(); 509 void eventKeyDownBinding_PlayPattern(); 510 void eventKeyDownBinding_PlayPosition(); 511 void eventKeyDownBinding_PlayPatternFromFIRSTQUARTER(); 512 void eventKeyDownBinding_PlayPatternFromSECONDQUARTER(); 513 void eventKeyDownBinding_PlayPatternFromTHIRDQUARTER(); 514 void eventKeyDownBinding_PlayRow(); 515 void eventKeyDownBinding_PlayTrace(); 516 void eventKeyDownBinding_Stop(); 517 void eventKeyDownBinding_Edit(); 518 519 void eventKeyDownBinding_UnmuteAll(); 520 521 void eventKeyDownBinding_Open(); 522 void eventKeyDownBinding_Save(); 523 void eventKeyDownBinding_SaveAs(); 524 525 void eventKeyDownBinding_NextPattern(); 526 void eventKeyDownBinding_PreviousPattern(); 527 528 // - Invoke sections 529 void eventKeyDownBinding_InvokeMainScreen(); 530 void eventKeyDownBinding_InvokeSectionInstruments(); 531 void eventKeyDownBinding_InvokeSectionSamples(); 532 void eventKeyDownBinding_InvokeSectionSettings(); 533 void eventKeyDownBinding_InvokeSectionTranspose(); 534 void eventKeyDownBinding_InvokeSectionAdvancedEdit(); 535 void eventKeyDownBinding_InvokeSectionDiskMenu(); 536 void eventKeyDownBinding_InvokeSectionHDRecorder(); 537 void eventKeyDownBinding_InvokeSectionQuickOptions(); 538 void eventKeyDownBinding_InvokeSectionOptimize(); 539 void eventKeyDownBinding_InvokeSectionAbout(); 540 541 // Some handy shortcuts 542 void eventKeyDownBinding_ToggleFT2Edit(); 543 void eventKeyDownBinding_ToggleFollowSong(); 544 void eventKeyDownBinding_ToggleProspectiveMode(); 545 void eventKeyDownBinding_ToggleCursorWrapAround(); 546 void eventKeyDownBinding_ToggleLiveSwitch(); 547 void eventKeyDownBinding_ToggleRecordKeyOff(); 548 void eventKeyDownBinding_ToggleScopes(); 549 550 void eventKeyDownBinding_InvokePatternToolVolumeScalePattern(); 551 void eventKeyDownBinding_InvokePatternToolVolumeScaleTrack(); 552 void eventKeyDownBinding_InvokePatternToolVolumeScaleSelection(); 553 554 void eventKeyDownBinding_InvokeQuickChooseInstrument(); 555 556 // - Some FT2 standard bindings 557 void eventKeyDownBinding_TransposeCurInsTrackDown(); 558 void eventKeyDownBinding_TransposeCurInsTrackUp(); 559 560 void eventKeyDownBinding_TransposeCurInsPatternDown(); 561 void eventKeyDownBinding_TransposeCurInsPatternUp(); 562 563 void eventKeyDownBinding_TransposeCurInsBlockDown(); 564 void eventKeyDownBinding_TransposeCurInsBlockUp(); 565 566 void eventKeyDownBinding_TransposeAllInsTrackDown(); 567 void eventKeyDownBinding_TransposeAllInsTrackUp(); 568 569 void eventKeyDownBinding_TransposeAllInsPatternDown(); 570 void eventKeyDownBinding_TransposeAllInsPatternUp(); 571 572 void eventKeyDownBinding_TransposeAllInsBlockDown(); 573 void eventKeyDownBinding_TransposeAllInsBlockUp(); 574 575 void eventKeyDownBinding_ExitApplication(); 576 577 // Contributed by 8ch (http://modarchive.org/forums/index.php?topic=2713.0): 578 void eventKeyDownBinding_DelCurOrderPosition(); 579 void eventKeyDownBinding_InsNewOrderPosition(); 580 void eventKeyDownBinding_DecCurOrderPattern(); 581 void eventKeyDownBinding_IncCurOrderPattern(); 582 583 584 private: 585 // - friend classes -------------------------------------------------------- 586 friend class SectionAbstract; 587 friend class SectionUpperLeft; 588 friend class SectionSettings; 589 friend class SectionTranspose; 590 friend class SectionAdvancedEdit; 591 friend class SectionDiskMenu; 592 friend class SectionReplacedInstrumentListBoxes; 593 friend class SectionInstruments; 594 friend class SectionSamples; 595 friend class SectionHDRecorder; 596 friend class SectionQuickOptions; 597 friend class SectionOptimize; 598 friend class SectionAbout; 599 600 friend class InputControlListener; 601 friend class SampleLoadChannelSelectionHandler; 602 friend class ZapInstrumentHandler; 603 friend class ToolInvokeHelper; 604 friend class SaveProceedHandler; 605 friend class PanningSettingsContainer; 606 607 friend class TabManager; 608 friend class PlayerLogic; 609 friend class RecorderLogic; 610 friend class Zapper; 611 friend class SectionSwitcher; 612 }; 613 614 #endif 615