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 #ifndef DRUM_PATTERN_EDITOR_H 25 #define DRUM_PATTERN_EDITOR_H 26 27 #include "../EventListener.h" 28 29 #include <hydrogen/object.h> 30 31 #include <QtGui> 32 #if QT_VERSION >= 0x050000 33 # include <QtWidgets> 34 #endif 35 36 namespace H2Core 37 { 38 class Note; 39 class Pattern; 40 } 41 42 class PatternEditorInstrumentList; 43 class PatternEditorPanel; 44 /// 45 /// Drum pattern editor 46 /// 47 class DrumPatternEditor : public QWidget, public EventListener, public H2Core::Object 48 { 49 H2_OBJECT 50 Q_OBJECT 51 52 public: 53 DrumPatternEditor(QWidget* parent, PatternEditorPanel *panel); 54 ~DrumPatternEditor(); 55 56 void setResolution(uint res, bool bUseTriplets); getResolution()57 uint getResolution() { return m_nResolution; } isUsingTriplets()58 bool isUsingTriplets() { return m_bUseTriplets; } 59 60 void zoom_in(); 61 void zoom_out(); 62 63 static QColor computeNoteColor( float ); 64 65 // Implements EventListener interface 66 virtual void patternModifiedEvent(); 67 virtual void patternChangedEvent(); 68 virtual void selectedPatternChangedEvent(); 69 virtual void selectedInstrumentChangedEvent(); 70 //~ Implements EventListener interface 71 void addOrDeleteNoteAction( int nColumn, 72 int row, 73 int selectedPatternNumber, 74 int oldLength, 75 float oldVelocity, 76 float oldPan_L, 77 float oldPan_R, 78 float oldLeadLag, 79 int oldNoteKeyVal, 80 int oldOctaveKeyVal, 81 bool listen, 82 bool isMidi, 83 bool isInstrumentMode, 84 bool isNoteOff); 85 void editNoteLengthAction( int nColumn, int nRealColumn, int row, int length, int selectedPatternNumber ); 86 void undoRedoAction( int column, 87 QString mode, 88 int nSelectedPatternNumber, 89 int nSelectedInstrument, 90 float velocity, 91 float pan_L, 92 float pan_R, 93 float leadLag, 94 float probability, 95 int noteKeyVal, 96 int octaveKeyVal ); 97 void functionClearNotesRedoAction( int nSelectedInstrument, int selectedPatternNumber ); 98 void functionClearNotesUndoAction( std::list< H2Core::Note* > noteList, int nSelectedInstrument, int patternNumber ); 99 void functionFillNotesUndoAction( QStringList noteList, int nSelectedInstrument, int patternNumber ); 100 void functionFillNotesRedoAction( QStringList noteList, int nSelectedInstrument, int patternNumber ); 101 void functionRandomVelocityAction( QStringList noteVeloValue, int nSelectedInstrument, int selectedPatternNumber ); 102 void functionMoveInstrumentAction( int nSourceInstrument, int nTargetInstrument ); 103 void functionDropInstrumentUndoAction( int nTargetInstrument, std::vector<int>* AddedComponents ); 104 void functionDropInstrumentRedoAction(QString sDrumkitName, QString sInstrumentName, int nTargetInstrument, std::vector<int>* AddedComponents ); 105 void functionDeleteInstrumentUndoAction( std::list< H2Core::Note* > noteList, int nSelectedInstrument, QString instrumentName, QString drumkitName ); 106 void functionAddEmptyInstrumentUndo(); 107 void functionAddEmptyInstrumentRedo(); 108 void functionPasteNotesRedoAction(std::list<H2Core::Pattern*> & changeList, std::list<H2Core::Pattern*> & appliedList); 109 void functionPasteNotesUndoAction(std::list<H2Core::Pattern*> & appliedList); 110 111 public slots: 112 void updateEditor(); 113 114 private: 115 float m_nGridWidth; 116 uint m_nGridHeight; 117 int m_nEditorHeight; 118 uint m_nResolution; 119 bool m_bUseTriplets; 120 121 bool m_bRightBtnPressed; 122 H2Core::Note *m_pDraggedNote; 123 //~ 124 125 H2Core::Pattern *m_pPattern; 126 127 PatternEditorPanel *m_pPatternEditorPanel; 128 129 void __draw_note( H2Core::Note* note, QPainter& painter ); 130 void __draw_pattern( QPainter& painter ); 131 void __draw_grid( QPainter& painter ); 132 void __create_background( QPainter& pointer ); 133 134 virtual void mousePressEvent(QMouseEvent *ev); 135 virtual void mouseReleaseEvent(QMouseEvent *ev); 136 virtual void mouseMoveEvent(QMouseEvent *ev); 137 virtual void keyPressEvent (QKeyEvent *ev); 138 virtual void showEvent ( QShowEvent *ev ); 139 virtual void hideEvent ( QHideEvent *ev ); 140 virtual void paintEvent(QPaintEvent *ev); 141 142 int getColumn(QMouseEvent *ev); 143 144 int findFreeCompoID( int startingPoint = 0 ); 145 int findExistingCompo( QString SourceName ); 146 QString renameCompo( QString OriginalName ); 147 148 int __nRealColumn; 149 int __nColumn; 150 int __row; 151 int __oldLength; 152 int __selectedPatternNumber; 153 }; 154 155 156 #endif 157