1 //========================================================= 2 // MusE 3 // Linux Music Editor 4 // $Id: dcanvas.h,v 1.8.2.2 2009/02/02 21:38:00 terminator356 Exp $ 5 // (C) Copyright 1999 Werner Schweer (ws@seh.de) 6 // (C) Copyright 2016 Tim E. Real (terminator356 on users dot sourceforge dot net) 7 // 8 // This program is free software; you can redistribute it and/or 9 // modify it under the terms of the GNU General Public License 10 // as published by the Free Software Foundation; version 2 of 11 // the License, or (at your option) any later version. 12 // 13 // This program 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 this program; if not, write to the Free Software 20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 // 22 //========================================================= 23 24 #ifndef __DCANVAS_H__ 25 #define __DCANVAS_H__ 26 27 #include "ecanvas.h" 28 #include "song.h" 29 #include "steprec.h" 30 #include <map> 31 #include <QList> 32 #include <QSet> 33 34 #define TH 18 35 36 class QResizeEvent; 37 class QDragEnterEvent; 38 class QDropEvent; 39 class QDragMoveEvent; 40 class QDragLeaveEvent; 41 42 namespace MusECore { 43 struct DrumMap; 44 } 45 46 namespace MusEGui { 47 48 class MidiEditor; 49 class DrumEdit; 50 51 //--------------------------------------------------------- 52 // DEvent 53 // ''visual'' Drum Event 54 //--------------------------------------------------------- 55 56 class DEvent : public EItem { 57 public: 58 DEvent(MusECore::Event e, MusECore::Part* p, int instr); 59 }; 60 61 62 struct instrument_number_mapping_t //FINDMICH TODO move into a suitable namespace! 63 { 64 QSet<MusECore::Track*> tracks; 65 int pitch; 66 instrument_number_mapping_tinstrument_number_mapping_t67 instrument_number_mapping_t() 68 { 69 pitch=-1; 70 tracks.clear(); 71 } 72 instrument_number_mapping_tinstrument_number_mapping_t73 instrument_number_mapping_t(const QSet<MusECore::Track*>& tr, int p) 74 { 75 tracks=tr; 76 pitch=p; 77 } 78 79 bool operator==(const instrument_number_mapping_t& that) const //TODO maybe compare the Track* serial numbers, not the pointers themselves? 80 { 81 return (this->tracks == that.tracks && this->pitch==that.pitch); 82 } 83 84 bool operator!=(const instrument_number_mapping_t& that) 85 { 86 return !operator==(that); 87 } 88 }; 89 90 //--------------------------------------------------------- 91 // DrumCanvas 92 //--------------------------------------------------------- 93 94 class DrumCanvas : public EventCanvas { 95 Q_OBJECT 96 97 MusECore::DrumMap* ourDrumMap; 98 bool must_delete_our_drum_map; //FINDMICH really delete it! 99 QVector<instrument_number_mapping_t> instrument_map; 100 101 DrumEdit* drumEditor; 102 103 MusECore::StepRec* steprec; 104 105 // Cursor tool position 106 QPoint cursorPos; 107 int _stepSize; 108 109 110 virtual void drawCanvas(QPainter&, const QRect&, const QRegion& = QRegion()) override; 111 virtual void drawItem(QPainter&, const CItem*, const QRect&, const QRegion& = QRegion()) override; 112 void drawTopItem(QPainter& p, const QRect& rect, const QRegion& = QRegion()) override; 113 virtual void drawMoving(QPainter&, const CItem*, const QRect&, const QRegion& = QRegion()) override; 114 virtual MusECore::Undo moveCanvasItems(CItemMap&, int, int, DragType, bool rasterize = true) override; 115 virtual bool moveItem(MusECore::Undo&, CItem*, const QPoint&, DragType, bool rasterize = true) override; 116 virtual CItem* newItem(const QPoint&, int) override; resizeItem(CItem *,bool,bool)117 virtual void resizeItem(CItem*, bool, bool) override { } // Non-virt width is meaningless, such as drums. 118 virtual void newItem(CItem*, bool) override; 119 virtual void newItem(CItem*, bool, bool replace ); 120 virtual bool deleteItem(CItem*) override; 121 virtual void itemPressed(const CItem*) override; 122 virtual void itemReleased(const CItem*, const QPoint& /*oldpos*/) override; 123 virtual void itemMoving(const CItem*, const QPoint& newMP) override; 124 virtual void itemMoved(const CItem*, const QPoint& oldMP) override; 125 126 CItem* newItem(int tick, int instrument, int velocity); 127 128 bool index2Note(int index, int* port, int* channel, int* note); 129 int y2pitch(int y) const override; 130 int pitch2y(int pitch) const override; y2height(int)131 inline int y2height(int) const override { return TH; } yItemOffset()132 inline int yItemOffset() const override { return -TH/2; } 133 void startDrag(CItem*, DragType) override; 134 void dragEnterEvent(QDragEnterEvent* event) override; 135 void dragMoveEvent(QDragMoveEvent*) override; 136 void dragLeaveEvent(QDragLeaveEvent*) override; 137 virtual CItem* addItem(MusECore::Part*, const MusECore::Event&) override; 138 virtual void resizeEvent(QResizeEvent*) override; 139 virtual void curPartChanged() override; 140 int getNextStep(unsigned int pos, int basicStep, int stepSize=1); 141 void mouseMove(QMouseEvent* event) override; 142 void showNoteTooltip(QMouseEvent* event); 143 void showStatusTip(QMouseEvent *event); 144 145 protected: 146 void setCursor() override; 147 void setMouseOverItemCursor() override; 148 149 signals: 150 void newWidth(int); 151 void ourDrumMapChanged(bool /*instrumentMap changed as well?*/); 152 153 private slots: 154 void midiNote(int pitch, int velo); 155 156 public slots: 157 void mapChanged(int, int); 158 void keyPressed(int, int); 159 void keyReleased(int, bool); 160 void setTool2(int); 161 void setCurDrumInstrument(int); 162 virtual void setStep(int); 163 164 public: 165 enum { 166 CMD_CUT, CMD_COPY, CMD_COPY_RANGE, CMD_PASTE, CMD_PASTE_TO_CUR_PART, CMD_PASTE_DIALOG, 167 CMD_SELECT_ALL, CMD_SELECT_NONE, CMD_SELECT_INVERT, 168 CMD_SELECT_ILOOP, CMD_SELECT_OLOOP, CMD_SELECT_PREV_PART, CMD_SELECT_NEXT_PART, 169 CMD_DEL, CMD_FIXED_LEN, CMD_RIGHT, CMD_LEFT, CMD_RIGHT_NOSNAP, CMD_LEFT_NOSNAP, CMD_MODIFY_VELOCITY, CMD_CRESCENDO, 170 CMD_QUANTIZE, CMD_ERASE_EVENT, CMD_NOTE_SHIFT, CMD_DELETE_OVERLAPS, 171 CMD_GROUP_NONE, CMD_GROUP_CHAN, CMD_GROUP_MAX, CMD_RANGE_TO_SELECTION 172 }; 173 DrumCanvas(MidiEditor*, QWidget*, int, int, 174 const char* name = 0); 175 virtual ~DrumCanvas(); 176 void cmd(int); 177 virtual void modifySelected(NoteInfo::ValType type, int val, bool delta_mode = true) override; 178 virtual void keyPress(QKeyEvent* event) override; 179 virtual void keyRelease(QKeyEvent* event) override; 180 const MusECore::Event* getEventAtCursorPos(); 181 void selectCursorEvent(const MusECore::Event* ev); 182 183 int pitch_and_track_to_instrument(int pitch, MusECore::Track* track); 184 185 // Returns OR'd WorkingDrumMapEntry::OverrideType flags indicating whether a map item's members, 186 // given by 'fields' (OR'd WorkingDrumMapEntry::Fields), are either the original or working map item. 187 // Here in DrumCanvas the flags can be NoOverride, TrackOverride, and InstrumentOverride. 188 int isWorkingMapInstrument(int instr, int fields) const; 189 // Returns true if any of the instrument's group tracks have non-empty working lists. 190 bool hasOverrides(int instr) const; 191 // Resets all overrides in all patches (clears all override lists), in the instrument's group tracks. 192 void resetOverridesForAllPatches(int instr); 193 getOurDrumMap()194 MusECore::DrumMap* getOurDrumMap() { return ourDrumMap; } getOurDrumMapSize()195 int getOurDrumMapSize() { return instrument_map.size(); } get_instrument_map()196 QVector<instrument_number_mapping_t>& get_instrument_map() { return instrument_map; } 197 void propagate_drummap_change(int instrument, int fields, bool isReset, bool includeDefault, bool isInstrumentMod, bool doWholeMap); 198 void rebuildOurDrumMap(); drumEdit()199 DrumEdit* drumEdit() { return drumEditor; } 200 }; 201 202 } // namespace MusEGui 203 204 #endif 205 206