1 /* 2 MIDI Virtual Piano Keyboard 3 Copyright (C) 2008-2021, Pedro Lopez-Cabanillas <plcl@users.sf.net> 4 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 3 of the License, or 8 (at your option) any later version. 9 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. 14 15 You should have received a copy of the GNU General Public License along 16 with this program; If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef VPIANO_H 20 #define VPIANO_H 21 22 #include <QMainWindow> 23 #include <drumstick/pianokeybd.h> 24 #include "nativefilter.h" 25 #include "instrument.h" 26 #include "ui_vpiano.h" 27 28 #if defined(Q_OS_WINDOWS) 29 #include "winsnap.h" 30 #endif 31 32 class QTranslator; 33 class QLabel; 34 class QComboBox; 35 class QSpinBox; 36 class QSlider; 37 class QDial; 38 class Instrument; 39 class About; 40 class Preferences; 41 class MidiSetup; 42 class KMapDialog; 43 class DialogExtraControls; 44 class RiffImportDlg; 45 class ColorDialog; 46 47 namespace drumstick { 48 namespace rt { 49 class MIDIInput; 50 class MIDIOutput; 51 class BackendManager; 52 } 53 namespace widgets { 54 class PianoHandler; 55 }} 56 57 class VPiano : public QMainWindow, public drumstick::widgets::PianoHandler 58 { 59 Q_OBJECT 60 61 public: 62 VPiano( QWidget * parent = nullptr, Qt::WindowFlags flags = Qt::Window ); 63 virtual ~VPiano(); isInitialized()64 bool isInitialized() const { return m_initialized; } 65 void retranslateUi(); 66 QMenu *createPopupMenu () override; 67 68 // PianoHandler methods 69 void noteOn(const int midiNote, const int vel) override; 70 void noteOff(const int midiNote, const int vel) override; 71 72 #if ENABLE_DBUS 73 74 public Q_SLOTS: 75 void quit(); 76 void panic(); 77 void reset_controllers(); 78 void channel(int value); 79 void octave(int value); 80 void transpose(int value); 81 void velocity(int value); 82 void connect_in(const QString &value); 83 void connect_out(const QString &value); 84 void connect_thru(bool value); 85 86 void noteoff(int note); 87 void noteon(int note); 88 void polykeypress(int note, int value); 89 void controlchange(int control, int value); 90 void programchange(int value); 91 void programnamechange(const QString &value); 92 void chankeypress(int value); 93 void pitchwheel(int value); 94 95 Q_SIGNALS: 96 void event_noteoff(int note); 97 void event_noteon(int note); 98 void event_polykeypress(int note, int value); 99 void event_controlchange(int control, int value); 100 void event_programchange(int value); 101 void event_chankeypress(int value); 102 void event_pitchwheel(int value); 103 104 #endif /*ENABLE_DBUS*/ 105 106 protected Q_SLOTS: 107 void slotAbout(); 108 void slotAboutQt(); 109 void slotAboutTranslation(); 110 void slotConnections(); 111 void slotPreferences(); 112 void slotEditKeyboardMap(); 113 void slotPanic(); 114 void slotResetAllControllers(); 115 void slotResetBender(); 116 void slotHelpContents(); 117 void slotOpenWebSite(); 118 void slotImportSF(); 119 void slotEditExtraControls(); 120 void slotNameOrientation(QAction* action); 121 void slotNameVisibility(QAction* action); 122 void slotNameVariant(QAction* action); 123 void slotControlSliderMoved(const int value); 124 void slotExtraController(const int value); 125 void slotControlClicked(const bool value); 126 void slotBenderSliderMoved(const int pos); 127 void slotBenderSliderReleased(); 128 void slotComboBankActivated(const int index = -1); 129 void slotComboProgActivated(const int index = -1); 130 void slotBaseOctaveValueChanged(const int octave); 131 void slotTransposeValueChanged(const int transpose); 132 void slotVelocityValueChanged(int value); 133 void slotChannelValueChanged(const int channel); 134 void slotComboControlCurrentIndexChanged(const int index); 135 void slotShortcuts(); 136 void slotVelocityUp(); 137 void slotVelocityDown(); 138 void slotBankNext(); 139 void slotBankPrev(); 140 void slotProgramNext(); 141 void slotProgramPrev(); 142 void slotControllerNext(); 143 void slotControllerPrev(); 144 void slotControllerUp(); 145 void slotControllerDown(); 146 void slotSwitchLanguage(QAction *action); 147 void slotKeyboardInput(bool value); 148 void slotMouseInput(bool value); 149 void slotTouchScreenInput(bool value); 150 void slotColorPolicy(); 151 void slotColorScale(bool value); 152 void slotNoteName(const QString& text); 153 void slotLoadConfiguration(); 154 void slotSaveConfiguration(); 155 //void slotEditPrograms(); 156 //void slotDebugDestroyed(QObject *obj); 157 158 //drumstick-rt slots 159 void slotNoteOn(const int chan, const int note, const int vel); 160 void slotNoteOff(const int chan, const int note, const int vel); 161 void slotKeyPressure(const int chan, const int note, const int value); 162 void slotController(const int chan, const int control, const int value); 163 void slotProgram(const int chan, const int program); 164 void slotChannelPressure(const int chan, const int value); 165 void slotPitchBend(const int chan, const int value); 166 void toggleWindowFrame(const bool state); 167 168 protected: 169 void closeEvent ( QCloseEvent *event ) override; 170 void showEvent ( QShowEvent *event ) override; 171 void hideEvent( QHideEvent *event ) override; 172 #if QT_VERSION < QT_VERSION_CHECK(6,0,0) 173 bool nativeEvent( const QByteArray &eventType, void *message, long *result ) override; 174 #else 175 bool nativeEvent( const QByteArray &eventType, void *message, qintptr *result ) override; 176 #endif 177 void changeEvent ( QEvent *event ) override; 178 179 private: 180 void initialization(); 181 bool initMidi(); 182 void readSettings(); 183 void readMidiControllerSettings(); 184 void writeSettings(); 185 void applyPreferences(); 186 void applyInitialSettings(); 187 void populateControllers(); 188 void populateInstruments(); 189 void populatePrograms(int bank = -1); 190 void initToolBars(); 191 void clearExtraControllers(); 192 void initExtraControllers(); 193 void initControllers(int channel); 194 void resetAllControllers(); 195 void initializeAllControllers(); 196 void allNotesOff(); 197 void sendController(const int controller, const int value); 198 void sendBankChange(const int bank); 199 void sendNoteOn(const int midiNote, const int vel); 200 void sendNoteOff(const int midiNote, const int vel); 201 void sendProgramChange(const int program); 202 void sendBender(const int value); 203 void sendPolyKeyPress(const int note, const int value); 204 void sendChanKeyPress(const int value); 205 void sendSysex(const QByteArray& data); 206 void updateController(int ctl, int val); 207 void updateExtraController(int ctl, int val); 208 void updateBankChange(int bank = -1); 209 void updateProgramChange(int program = -1); 210 void grabKb(); 211 void releaseKb(); 212 void updateNoteNames(bool drums); 213 void setWidgetTip(QWidget* w, int val); 214 215 QByteArray readSysexDataFile(const QString& fileName); 216 void createLanguageMenu(); 217 void enforceMIDIChannelState(); 218 QColor getHighlightColorFromPolicy(const int chan, const int note, const int vel); 219 int getType(const int note) const; 220 int getDegree(const int note) const; 221 222 void initLanguages(); 223 void retranslateToolbars(); 224 225 drumstick::rt::MIDIOutput* m_midiout; 226 drumstick::rt::MIDIInput* m_midiin; 227 drumstick::rt::BackendManager* m_backendManager; 228 229 bool m_initialized; 230 231 NativeFilter *m_filter; 232 233 Ui::VPiano ui; 234 235 QLabel* m_lblBank; 236 QLabel* m_lblBaseOctave; 237 QLabel* m_lblBender; 238 QLabel* m_lblChannel; 239 QLabel* m_lblControl; 240 QLabel* m_lblProgram; 241 QLabel* m_lblTranspose; 242 QLabel* m_lblValue; 243 QLabel* m_lblVelocity; 244 QSpinBox* m_sboxChannel; 245 QSpinBox* m_sboxOctave; 246 QSpinBox* m_sboxTranspose; 247 QDial* m_Velocity; 248 QComboBox* m_comboControl; 249 QDial* m_Control; 250 QSlider* m_bender; 251 QComboBox* m_comboBank; 252 QComboBox* m_comboProg; 253 Instrument* m_ins; 254 QStringList m_extraControls; 255 QMap<int,QMap<int,int> > m_ctlState, m_ctlSettings; 256 QMap<int,int> m_lastBank; 257 QMap<int,int> m_lastProg; 258 QMap<int,int> m_lastCtl; 259 QMap<QString, QString> m_supportedLangs; 260 QTranslator *m_trq, *m_trp, *m_trl; 261 QAction *m_currentLang; 262 QHash<QString,QList<QKeySequence> > m_defaultShortcuts; 263 #if defined(Q_OS_WINDOWS) 264 WinSnap m_snapper; 265 #endif 266 void connectMidiInSignals(); 267 }; 268 269 #endif // VPIANO_H 270