AutomationEditor.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * AutomationEditor.h - declaration of class AutomationEditor which is a window
  3. * where you can edit dynamic values in an easy way
  4. *
  5. * Copyright (c) 2006-2008 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef AUTOMATION_EDITOR_H
  26. #define AUTOMATION_EDITOR_H
  27. #include <QtCore/QMutex>
  28. #include <QVector>
  29. #include <QWidget>
  30. #include "Editor.h"
  31. #include "lmms_basics.h"
  32. #include "JournallingObject.h"
  33. #include "MidiTime.h"
  34. #include "AutomationPattern.h"
  35. #include "ComboBoxModel.h"
  36. #include "Knob.h"
  37. class QPainter;
  38. class QPixmap;
  39. class QScrollBar;
  40. class ComboBox;
  41. class NotePlayHandle;
  42. class TimeLineWidget;
  43. class AutomationEditor : public QWidget, public JournallingObject
  44. {
  45. Q_OBJECT
  46. Q_PROPERTY(QColor barLineColor READ barLineColor WRITE setBarLineColor)
  47. Q_PROPERTY(QColor beatLineColor READ beatLineColor WRITE setBeatLineColor)
  48. Q_PROPERTY(QColor lineColor READ lineColor WRITE setLineColor)
  49. Q_PROPERTY(QColor vertexColor READ vertexColor WRITE setVertexColor)
  50. Q_PROPERTY(QBrush scaleColor READ scaleColor WRITE setScaleColor)
  51. Q_PROPERTY(QBrush graphColor READ graphColor WRITE setGraphColor)
  52. Q_PROPERTY(QColor crossColor READ crossColor WRITE setCrossColor)
  53. Q_PROPERTY(QColor backgroundShade READ backgroundShade WRITE setBackgroundShade)
  54. public:
  55. void setCurrentPattern(AutomationPattern * new_pattern);
  56. inline const AutomationPattern * currentPattern() const
  57. {
  58. return m_pattern;
  59. }
  60. inline bool validPattern() const
  61. {
  62. return m_pattern != nullptr;
  63. }
  64. void saveSettings(QDomDocument & doc, QDomElement & parent) override;
  65. void loadSettings(const QDomElement & parent) override;
  66. QString nodeName() const override
  67. {
  68. return "automationeditor";
  69. }
  70. // qproperty access methods
  71. QColor barLineColor() const;
  72. void setBarLineColor(const QColor & c);
  73. QColor beatLineColor() const;
  74. void setBeatLineColor(const QColor & c);
  75. QColor lineColor() const;
  76. void setLineColor(const QColor & c);
  77. QBrush graphColor() const;
  78. void setGraphColor(const QBrush & c);
  79. QColor vertexColor() const;
  80. void setVertexColor(const QColor & c);
  81. QBrush scaleColor() const;
  82. void setScaleColor(const QBrush & c);
  83. QColor crossColor() const;
  84. void setCrossColor(const QColor & c);
  85. QColor backgroundShade() const;
  86. void setBackgroundShade(const QColor & c);
  87. enum EditModes
  88. {
  89. DRAW,
  90. ERASE,
  91. SELECT,
  92. MOVE
  93. };
  94. public slots:
  95. void update();
  96. void updateAfterPatternChange();
  97. protected:
  98. typedef AutomationPattern::timeMap timeMap;
  99. void keyPressEvent(QKeyEvent * ke) override;
  100. void leaveEvent(QEvent * e) override;
  101. void mousePressEvent(QMouseEvent * mouseEvent) override;
  102. void mouseReleaseEvent(QMouseEvent * mouseEvent) override;
  103. void mouseMoveEvent(QMouseEvent * mouseEvent) override;
  104. void paintEvent(QPaintEvent * pe) override;
  105. void resizeEvent(QResizeEvent * re) override;
  106. void wheelEvent(QWheelEvent * we) override;
  107. float getLevel( int y );
  108. int xCoordOfTick( int tick );
  109. float yCoordOfLevel( float level );
  110. inline void drawLevelTick( QPainter & p, int tick, float value);// bool is_selected ); //NEEDS Change in CSS
  111. void removeSelection();
  112. void selectAll();
  113. void getSelectedValues(timeMap & selected_values );
  114. void drawLine( int x0, float y0, int x1, float y1 );
  115. void removePoints( int x0, int x1 );
  116. protected slots:
  117. void play();
  118. void stop();
  119. void horScrolled( int new_pos );
  120. void verScrolled( int new_pos );
  121. void setEditMode(AutomationEditor::EditModes mode);
  122. void setEditMode(int mode);
  123. void setProgressionType(AutomationPattern::ProgressionTypes type);
  124. void setProgressionType(int type);
  125. void setTension();
  126. void copySelectedValues();
  127. void cutSelectedValues();
  128. void pasteValues();
  129. void deleteSelectedValues();
  130. void updatePosition( const MidiTime & t );
  131. void zoomingXChanged();
  132. void zoomingYChanged();
  133. /// Updates the pattern's quantization using the current user selected value.
  134. void setQuantization();
  135. private:
  136. enum Actions
  137. {
  138. NONE,
  139. MOVE_VALUE,
  140. SELECT_VALUES,
  141. MOVE_SELECTION
  142. } ;
  143. // some constants...
  144. static const int SCROLLBAR_SIZE = 12;
  145. static const int TOP_MARGIN = 16;
  146. static const int DEFAULT_Y_DELTA = 6;
  147. static const int DEFAULT_STEPS_PER_BAR = 16;
  148. static const int DEFAULT_PPB = 12 * DEFAULT_STEPS_PER_BAR;
  149. static const int VALUES_WIDTH = 64;
  150. AutomationEditor();
  151. AutomationEditor( const AutomationEditor & );
  152. virtual ~AutomationEditor();
  153. static QPixmap * s_toolDraw;
  154. static QPixmap * s_toolErase;
  155. static QPixmap * s_toolSelect;
  156. static QPixmap * s_toolMove;
  157. static QPixmap * s_toolYFlip;
  158. static QPixmap * s_toolXFlip;
  159. ComboBoxModel m_zoomingXModel;
  160. ComboBoxModel m_zoomingYModel;
  161. ComboBoxModel m_quantizeModel;
  162. static const QVector<double> m_zoomXLevels;
  163. FloatModel * m_tensionModel;
  164. QMutex m_patternMutex;
  165. AutomationPattern * m_pattern;
  166. float m_minLevel;
  167. float m_maxLevel;
  168. float m_step;
  169. float m_scrollLevel;
  170. float m_bottomLevel;
  171. float m_topLevel;
  172. void updateTopBottomLevels();
  173. QScrollBar * m_leftRightScroll;
  174. QScrollBar * m_topBottomScroll;
  175. MidiTime m_currentPosition;
  176. Actions m_action;
  177. tick_t m_selectStartTick;
  178. tick_t m_selectedTick;
  179. float m_selectStartLevel;
  180. float m_selectedLevels;
  181. float m_moveStartLevel;
  182. tick_t m_moveStartTick;
  183. int m_moveXOffset;
  184. float m_drawLastLevel;
  185. tick_t m_drawLastTick;
  186. int m_ppb;
  187. int m_y_delta;
  188. bool m_y_auto;
  189. timeMap m_valuesToCopy;
  190. timeMap m_selValuesForMove;
  191. EditModes m_editMode;
  192. bool m_mouseDownRight; //true if right click is being held down
  193. TimeLineWidget * m_timeLine;
  194. bool m_scrollBack;
  195. void drawCross(QPainter & p );
  196. void drawAutomationPoint( QPainter & p, timeMap::iterator it );
  197. bool inBBEditor();
  198. QColor m_barLineColor;
  199. QColor m_beatLineColor;
  200. QColor m_lineColor;
  201. QBrush m_graphColor;
  202. QColor m_vertexColor;
  203. QBrush m_scaleColor;
  204. QColor m_crossColor;
  205. QColor m_backgroundShade;
  206. friend class AutomationEditorWindow;
  207. signals:
  208. void currentPatternChanged();
  209. void positionChanged( const MidiTime & );
  210. } ;
  211. class AutomationEditorWindow : public Editor
  212. {
  213. Q_OBJECT
  214. static const int INITIAL_WIDTH = 860;
  215. static const int INITIAL_HEIGHT = 480;
  216. public:
  217. AutomationEditorWindow();
  218. ~AutomationEditorWindow();
  219. void setCurrentPattern(AutomationPattern* pattern);
  220. const AutomationPattern* currentPattern();
  221. void dropEvent( QDropEvent * _de ) override;
  222. void dragEnterEvent( QDragEnterEvent * _dee ) override;
  223. void open(AutomationPattern* pattern);
  224. AutomationEditor* m_editor;
  225. QSize sizeHint() const override;
  226. public slots:
  227. void clearCurrentPattern();
  228. signals:
  229. void currentPatternChanged();
  230. protected:
  231. void focusInEvent(QFocusEvent * event) override;
  232. protected slots:
  233. void play() override;
  234. void stop() override;
  235. private slots:
  236. void updateWindowTitle();
  237. private:
  238. QAction* m_discreteAction;
  239. QAction* m_linearAction;
  240. QAction* m_cubicHermiteAction;
  241. QAction* m_flipYAction;
  242. QAction* m_flipXAction;
  243. Knob * m_tensionKnob;
  244. ComboBox * m_zoomingXComboBox;
  245. ComboBox * m_zoomingYComboBox;
  246. ComboBox * m_quantizeComboBox;
  247. };
  248. #endif