| 1 |
/* |
| 2 |
* Copyright (C) 2018-2022 Rerrah |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person |
| 5 |
* obtaining a copy of this software and associated documentation |
| 6 |
* files (the "Software"), to deal in the Software without |
| 7 |
* restriction, including without limitation the rights to use, |
| 8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
* copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following |
| 11 |
* conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be |
| 14 |
* included in all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 23 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifndef MAINWINDOW_HPP |
| 27 |
#define MAINWINDOW_HPP |
| 28 |
|
| 29 |
#include <atomic> |
| 30 |
#include <memory> |
| 31 |
#include <cstdint> |
| 32 |
#include <QMainWindow> |
| 33 |
#include <QKeyEvent> |
| 34 |
#include <QListWidgetItem> |
| 35 |
#include <QWidget> |
| 36 |
#include <QUndoStack> |
| 37 |
#include <QCloseEvent> |
| 38 |
#include <QDragEnterEvent> |
| 39 |
#include <QDropEvent> |
| 40 |
#include <QShowEvent> |
| 41 |
#include <QMessageBox> |
| 42 |
#include <QResizeEvent> |
| 43 |
#include <QMoveEvent> |
| 44 |
#include <QLabel> |
| 45 |
#include <QSpinBox> |
| 46 |
#include <QTimer> |
| 47 |
#include <QLibrary> |
| 48 |
#include <QShortcut> |
| 49 |
#include <QAction> |
| 50 |
#include <QActionGroup> |
| 51 |
#include <QLineEdit> |
| 52 |
#include "enum_hash.hpp" |
| 53 |
#include "configuration.hpp" |
| 54 |
#include "bamboo_tracker.hpp" |
| 55 |
#include "precise_timer.hpp" |
| 56 |
#include "audio/audio_stream.hpp" |
| 57 |
#include "gui/instrument_editor/instrument_editor_manager.hpp" |
| 58 |
#include "gui/color_palette.hpp" |
| 59 |
#include "gui/file_history.hpp" |
| 60 |
#include "gui/effect_list_dialog.hpp" |
| 61 |
#include "gui/keyboard_shortcut_list_dialog.hpp" |
| 62 |
#include "gui/bookmark_manager_form.hpp" |
| 63 |
#include "gui/instrument_selection_dialog.hpp" |
| 64 |
#include "gui/comment_edit_dialog.hpp" |
| 65 |
#include "gui/key_signature_manager_form.hpp" |
| 66 |
|
| 67 |
namespace Ui { |
| 68 |
class ModuleSaveCheckDialog; |
| 69 |
class MainWindow; |
| 70 |
} |
| 71 |
|
| 72 |
class ModuleSaveCheckDialog : public QMessageBox |
| 73 |
{ |
| 74 |
Q_OBJECT |
| 75 |
|
| 76 |
public: |
| 77 |
explicit ModuleSaveCheckDialog(const std::string& name, QWidget* parent = nullptr); |
| 78 |
}; |
| 79 |
|
| 80 |
class MainWindow : public QMainWindow |
| 81 |
{ |
| 82 |
Q_OBJECT |
| 83 |
|
| 84 |
public: |
| 85 |
MainWindow(std::weak_ptr<Configuration> config, QString filePath, bool isFirstLaunch, QWidget *parent = nullptr); |
| 86 |
~MainWindow() override; |
| 87 |
|
| 88 |
void assignADPCMSamples(); |
| 89 |
|
| 90 |
public slots: |
| 91 |
void onApplicationStateChanged(Qt::ApplicationState state); |
| 92 |
|
| 93 |
protected: |
| 94 |
bool eventFilter(QObject* watched, QEvent* event) override; |
| 95 |
void showEvent(QShowEvent*) override; |
| 96 |
void keyPressEvent(QKeyEvent* event) override; |
| 97 |
void keyReleaseEvent(QKeyEvent* event) override; |
| 98 |
void dragEnterEvent(QDragEnterEvent* event) override; |
| 99 |
void dropEvent(QDropEvent* event) override; |
| 100 |
void resizeEvent(QResizeEvent* event) override; |
| 101 |
void moveEvent(QMoveEvent* event) override; |
| 102 |
void closeEvent(QCloseEvent* event) override; |
| 103 |
|
| 104 |
// Midi |
| 105 |
private: |
| 106 |
static void midiThreadReceivedEvent(double delay, const uint8_t *msg, size_t len, void *userData); |
| 107 |
private slots: |
| 108 |
void midiKeyEvent(uchar status, uchar key, uchar velocity); |
| 109 |
void midiProgramEvent(uchar status, uchar program); |
| 110 |
|
| 111 |
private: |
| 112 |
std::unique_ptr<Ui::MainWindow> ui; |
| 113 |
std::weak_ptr<Configuration> config_; |
| 114 |
std::shared_ptr<ColorPalette> palette_; |
| 115 |
std::shared_ptr<BambooTracker> bt_; |
| 116 |
std::shared_ptr<AudioStream> stream_; |
| 117 |
std::unique_ptr<PreciseTimer> tickTimerForRealChip_; |
| 118 |
std::unique_ptr<QTimer> visualTimer_; |
| 119 |
std::shared_ptr<QUndoStack> comStack_; |
| 120 |
std::shared_ptr<FileHistory> fileHistory_; |
| 121 |
|
| 122 |
std::shared_ptr<QLibrary> scciDll_, c86ctlDll_; |
| 123 |
|
| 124 |
// Instrument list |
| 125 |
std::shared_ptr<InstrumentEditorManager> instDialogMan_; |
| 126 |
QListWidgetItem* renamingInstItem_; |
| 127 |
QLineEdit* renamingInstEdit_; |
| 128 |
void addInstrument(); |
| 129 |
void addDrumkit(); |
| 130 |
void removeInstrument(int row); |
| 131 |
void openInstrumentEditor(); |
| 132 |
int findRowFromInstrumentList(int instNum); |
| 133 |
void renameInstrument(); |
| 134 |
void finishRenamingInstrument(); |
| 135 |
void cloneInstrument(); |
| 136 |
void deepCloneInstrument(); |
| 137 |
void loadInstrument(); |
| 138 |
void funcLoadInstrument(QString file); |
| 139 |
void saveInstrument(); |
| 140 |
void importInstrumentsFromBank(); |
| 141 |
void funcImportInstrumentsFromBank(QString file); |
| 142 |
void exportInstrumentsToBank(); |
| 143 |
void swapInstruments(int row1, int row2); |
| 144 |
|
| 145 |
// Undo-Redo |
| 146 |
void undo(); |
| 147 |
void redo(); |
| 148 |
bool isModifiedForNotCommand_; |
| 149 |
|
| 150 |
// Load data |
| 151 |
void loadModule(); |
| 152 |
void openModule(const QString &file); |
| 153 |
void loadSong(); |
| 154 |
|
| 155 |
// Play song |
| 156 |
void startPlaySong(); |
| 157 |
void startPlayFromStart(); |
| 158 |
void startPlayPattern(); |
| 159 |
void startPlayFromCurrentStep(); |
| 160 |
void startPlayFromMarker(); |
| 161 |
void playStep(); |
| 162 |
void stopPlaySong(); |
| 163 |
bool hasLockedWigets_; |
| 164 |
void lockWidgets(bool isLock); |
| 165 |
|
| 166 |
// Octave change |
| 167 |
void changeOctave(bool upFlag); |
| 168 |
|
| 169 |
// Configuration change |
| 170 |
void changeConfiguration(); |
| 171 |
void setRealChipInterface(RealChipInterfaceType intf); |
| 172 |
void setMidiConfiguration(); |
| 173 |
void updateFonts(); |
| 174 |
|
| 175 |
// History change |
| 176 |
void changeFileHistory(QString file); |
| 177 |
|
| 178 |
// Backup |
| 179 |
bool backupModule(QString srcFile); |
| 180 |
|
| 181 |
void setWindowTitle(); |
| 182 |
void setModifiedTrue(); |
| 183 |
void setInitialSelectedInstrument(); |
| 184 |
QString getModuleFileBaseName() const; |
| 185 |
|
| 186 |
bool isEditedPattern_, isEditedOrder_, isEditedInstList_; |
| 187 |
bool isSelectedPattern_, isSelectedOrder_; |
| 188 |
|
| 189 |
bool hasShownOnce_; |
| 190 |
|
| 191 |
bool isSavedModBefore_; |
| 192 |
|
| 193 |
bool firstViewUpdateRequest_; |
| 194 |
|
| 195 |
// Menus |
| 196 |
std::unique_ptr<QActionGroup> pasteModeGroup_; |
| 197 |
|
| 198 |
// Toolbar |
| 199 |
QSpinBox *octave_, *highlight1_, *highlight2_, *volume_; |
| 200 |
|
| 201 |
// Status bars |
| 202 |
QLabel *statusStyle_, *statusInst_, *statusOctave_; |
| 203 |
QLabel *statusIntr_, *statusMixer_, *statusBpm_, *statusPlayPos_; |
| 204 |
|
| 205 |
// Shortcuts |
| 206 |
QAction octUpSc_, octDownSc_; |
| 207 |
QShortcut focusPtnSc_, focusOdrSc_, focusInstSc_; |
| 208 |
std::unique_ptr<QShortcut> instAddSc_; |
| 209 |
QAction playAndStopSc_, playStepSc_, goPrevOdrSc_, goNextOdrSc_, prevInstSc_, nextInstSc_; |
| 210 |
QAction incPtnSizeSc_, decPtnSizeSc_, incEditStepSc_, decEditStepSc_, prevSongSc_, nextSongSc_; |
| 211 |
QAction jamVolUpSc_, jamVolDownSc_; |
| 212 |
void setShortcuts(); |
| 213 |
|
| 214 |
// Dialogs |
| 215 |
std::unique_ptr<EffectListDialog> effListDialog_; |
| 216 |
std::unique_ptr<KeyboardShortcutListDialog> shortcutsDialog_; |
| 217 |
std::unique_ptr<BookmarkManagerForm> bmManForm_; |
| 218 |
std::unique_ptr<CommentEditDialog> commentDialog_; |
| 219 |
std::unique_ptr<KeySignatureManagerForm> ksManForm_; |
| 220 |
std::unique_ptr<QMessageBox> welcomeDialog_; |
| 221 |
|
| 222 |
// Bank import |
| 223 |
std::atomic_bool bankJamMidiCtrl_; |
| 224 |
std::unique_ptr<InstrumentSelectionDialog> importBankDialog_; |
| 225 |
|
| 226 |
// Meta methods |
| 227 |
int tickEventMethod_; |
| 228 |
int midiKeyEventMethod_; |
| 229 |
int midiProgramEventMethod_; |
| 230 |
|
| 231 |
void updateInstrumentListColors(); |
| 232 |
void setOrderListGroupMaximumWidth(); |
| 233 |
void freezeViews(); |
| 234 |
void unfreezeViews(); |
| 235 |
|
| 236 |
inline bool showUndoResetWarningDialog(QString text) |
| 237 |
{ |
| 238 |
return (QMessageBox::warning(this, tr("Warning"), |
| 239 |
tr("%1 If you execute this command, the command history is reset.").arg(text), |
| 240 |
QMessageBox::Yes | QMessageBox::No, |
| 241 |
QMessageBox::No) == QMessageBox::Yes); |
| 242 |
} |
| 243 |
|
| 244 |
inline void showStreamFailedDialog(const QString& errDetail) |
| 245 |
{ |
| 246 |
QMessageBox::critical(this, tr("Error"), |
| 247 |
tr("Could not open the audio stream. Please change the sound settings in Configuration.") |
| 248 |
+ "\n\n" + errDetail, |
| 249 |
QMessageBox::Ok, QMessageBox::Ok); |
| 250 |
} |
| 251 |
|
| 252 |
inline void showStreamRateWarningDialog(uint32_t curRate) |
| 253 |
{ |
| 254 |
QMessageBox::warning(this, tr("Warning"), |
| 255 |
tr("Could not set the sample rate of the audio stream to %1Hz. Currently the stream runs on %2Hz instead.") |
| 256 |
.arg(config_.lock()->getSampleRate()).arg(curRate), |
| 257 |
QMessageBox::Ok, QMessageBox::Ok); |
| 258 |
} |
| 259 |
|
| 260 |
inline void showMidiFailedDialog(const QString& errDetail) |
| 261 |
{ |
| 262 |
QMessageBox::critical(this, tr("Error"), |
| 263 |
tr("Could not initialize MIDI input.") |
| 264 |
+ "\n\n" + errDetail, |
| 265 |
QMessageBox::Ok, QMessageBox::Ok); |
| 266 |
} |
| 267 |
|
| 268 |
private slots: |
| 269 |
void on_instrumentList_customContextMenuRequested(const QPoint& pos); |
| 270 |
void on_instrumentList_itemDoubleClicked(QListWidgetItem*); |
| 271 |
void on_instrumentList_itemSelectionChanged(); |
| 272 |
void on_grooveCheckBox_stateChanged(int arg1); |
| 273 |
void on_actionExit_triggered(); |
| 274 |
void on_actionUndo_triggered(); |
| 275 |
void on_actionRedo_triggered(); |
| 276 |
void on_actionCut_triggered(); |
| 277 |
void on_actionCopy_triggered(); |
| 278 |
void on_actionPaste_triggered(); |
| 279 |
void on_actionDelete_triggered(); |
| 280 |
void updateMenuByPattern(); |
| 281 |
void updateMenuByOrder(); |
| 282 |
void onCurrentTrackChanged(); |
| 283 |
void updateMenuByInstrumentList(); |
| 284 |
void updateMenuByPatternSelection(bool isSelected); |
| 285 |
void updateMenuByOrderSelection(bool isSelected); |
| 286 |
void on_actionAll_triggered(); |
| 287 |
void on_actionNone_triggered(); |
| 288 |
void on_actionDecrease_Note_triggered(); |
| 289 |
void on_actionIncrease_Note_triggered(); |
| 290 |
void on_actionDecrease_Octave_triggered(); |
| 291 |
void on_actionIncrease_Octave_triggered(); |
| 292 |
void on_actionInsert_Order_triggered(); |
| 293 |
void on_actionRemove_Order_triggered(); |
| 294 |
void on_actionModule_Properties_triggered(); |
| 295 |
void on_actionNew_Instrument_triggered(); |
| 296 |
void on_actionRemove_Instrument_triggered(); |
| 297 |
void on_actionClone_Instrument_triggered(); |
| 298 |
void on_actionDeep_Clone_Instrument_triggered(); |
| 299 |
void on_actionEdit_triggered(); |
| 300 |
void on_actionPlay_triggered(); |
| 301 |
void on_actionPlay_Pattern_triggered(); |
| 302 |
void on_actionPlay_From_Start_triggered(); |
| 303 |
void on_actionPlay_From_Cursor_triggered(); |
| 304 |
void on_actionStop_triggered(); |
| 305 |
void on_actionEdit_Mode_triggered(); |
| 306 |
void on_actionToggle_Track_triggered(); |
| 307 |
void on_actionSolo_Track_triggered(); |
| 308 |
void on_actionKill_Sound_triggered(); |
| 309 |
void on_actionAbout_triggered(); |
| 310 |
void on_actionFollow_Mode_triggered(); |
| 311 |
void on_actionGroove_Settings_triggered(); |
| 312 |
void on_actionConfiguration_triggered(); |
| 313 |
void on_actionExpand_triggered(); |
| 314 |
void on_actionShrink_triggered(); |
| 315 |
void on_actionDuplicate_Order_triggered(); |
| 316 |
void on_actionMove_Order_Up_triggered(); |
| 317 |
void on_actionMove_Order_Down_triggered(); |
| 318 |
void on_actionClone_Patterns_triggered(); |
| 319 |
void on_actionClone_Order_triggered(); |
| 320 |
void on_actionNew_triggered(); |
| 321 |
void on_actionComments_triggered(); |
| 322 |
bool on_actionSave_triggered(); |
| 323 |
bool on_actionSave_As_triggered(); |
| 324 |
void on_actionOpen_triggered(); |
| 325 |
void on_actionLoad_From_File_triggered(); |
| 326 |
void on_actionSave_To_File_triggered(); |
| 327 |
void on_actionImport_From_Bank_File_triggered(); |
| 328 |
void on_actionInterpolate_triggered(); |
| 329 |
void on_actionReverse_triggered(); |
| 330 |
void on_actionReplace_Instrument_triggered(); |
| 331 |
void on_actionRow_triggered(); |
| 332 |
void on_actionColumn_triggered(); |
| 333 |
void on_actionPattern_triggered(); |
| 334 |
void on_actionOrder_triggered(); |
| 335 |
void on_actionRemove_Unused_Instruments_triggered(); |
| 336 |
void on_actionRemove_Unused_Patterns_triggered(); |
| 337 |
void on_actionWAV_triggered(); |
| 338 |
void on_actionVGM_triggered(); |
| 339 |
void on_actionS98_triggered(); |
| 340 |
void on_actionMix_triggered(); |
| 341 |
void on_actionOverwrite_triggered(); |
| 342 |
void onNewTickSignaledRealChip(); |
| 343 |
void onNewTickSignaled(int state); |
| 344 |
void on_actionClear_triggered(); |
| 345 |
void on_keyRepeatCheckBox_stateChanged(int arg1); |
| 346 |
void updateVisuals(); |
| 347 |
void on_action_Effect_List_triggered(); |
| 348 |
void on_actionShortcuts_triggered(); |
| 349 |
void on_actionExport_To_Bank_File_triggered(); |
| 350 |
void on_actionRemove_Duplicate_Instruments_triggered(); |
| 351 |
void on_actionRename_Instrument_triggered(); |
| 352 |
void on_action_Bookmark_Manager_triggered(); |
| 353 |
void on_actionFine_Decrease_Values_triggered(); |
| 354 |
void on_actionFine_Increase_Values_triggered(); |
| 355 |
void on_actionCoarse_D_ecrease_Values_triggered(); |
| 356 |
void on_actionCoarse_I_ncrease_Values_triggered(); |
| 357 |
void on_action_Toggle_Bookmark_triggered(); |
| 358 |
void on_action_Next_Bookmark_triggered(); |
| 359 |
void on_action_Previous_Bookmark_triggered(); |
| 360 |
void on_action_Instrument_Mask_triggered(); |
| 361 |
void on_action_Volume_Mask_triggered(); |
| 362 |
void on_actionSet_Ro_w_Marker_triggered(); |
| 363 |
void on_actionPlay_From_Marker_triggered(); |
| 364 |
void on_action_Go_To_triggered(); |
| 365 |
void on_actionRemove_Unused_ADPCM_Samples_triggered(); |
| 366 |
void on_action_Status_Bar_triggered(); |
| 367 |
void on_action_Toolbar_triggered(); |
| 368 |
void on_actionNew_Drumki_t_triggered(); |
| 369 |
void on_action_Wave_View_triggered(bool checked); |
| 370 |
void on_action_Transpose_Song_triggered(); |
| 371 |
void on_action_Swap_Tracks_triggered(); |
| 372 |
void on_action_Insert_triggered(); |
| 373 |
void on_action_Hide_Tracks_triggered(); |
| 374 |
void on_action_Estimate_Song_Length_triggered(); |
| 375 |
void on_action_Key_Signature_Manager_triggered(); |
| 376 |
void on_action_Welcome_triggered(); |
| 377 |
}; |
| 378 |
|
| 379 |
#endif // MAINWINDOW_HPP |