AutomationEditor.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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 <QVector>
  28. #include <QWidget>
  29. #include "Editor.h"
  30. #include "lmms_basics.h"
  31. #include "JournallingObject.h"
  32. #include "TimePos.h"
  33. #include "AutomationClip.h"
  34. #include "ComboBoxModel.h"
  35. #include "Knob.h"
  36. class QPainter;
  37. class QPixmap;
  38. class QScrollBar;
  39. class ComboBox;
  40. class NotePlayHandle;
  41. class TimeLineWidget;
  42. class AutomationEditor : public QWidget, public JournallingObject
  43. {
  44. Q_OBJECT
  45. Q_PROPERTY(QColor barLineColor MEMBER m_barLineColor)
  46. Q_PROPERTY(QColor beatLineColor MEMBER m_beatLineColor)
  47. Q_PROPERTY(QColor lineColor MEMBER m_lineColor)
  48. Q_PROPERTY(QColor nodeInValueColor MEMBER m_nodeInValueColor)
  49. Q_PROPERTY(QColor nodeOutValueColor MEMBER m_nodeOutValueColor)
  50. Q_PROPERTY(QBrush scaleColor MEMBER m_scaleColor)
  51. Q_PROPERTY(QBrush graphColor MEMBER m_graphColor)
  52. Q_PROPERTY(QColor crossColor MEMBER m_crossColor)
  53. Q_PROPERTY(QColor backgroundShade MEMBER m_backgroundShade)
  54. public:
  55. void setCurrentClip(AutomationClip * new_clip);
  56. inline const AutomationClip * currentClip() const
  57. {
  58. return m_clip;
  59. }
  60. inline bool validClip() const
  61. {
  62. return m_clip != 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. enum EditModes
  71. {
  72. DRAW,
  73. ERASE,
  74. DRAW_OUTVALUES
  75. };
  76. public slots:
  77. void update();
  78. void updateAfterClipChange();
  79. protected:
  80. typedef AutomationClip::timeMap timeMap;
  81. void keyPressEvent(QKeyEvent * ke) override;
  82. void leaveEvent(QEvent * e) override;
  83. void mousePressEvent(QMouseEvent * mouseEvent) override;
  84. void mouseDoubleClickEvent(QMouseEvent * mouseEvent) override;
  85. void mouseReleaseEvent(QMouseEvent * mouseEvent) override;
  86. void mouseMoveEvent(QMouseEvent * mouseEvent) override;
  87. void paintEvent(QPaintEvent * pe) override;
  88. void resizeEvent(QResizeEvent * re) override;
  89. void wheelEvent(QWheelEvent * we) override;
  90. float getLevel( int y );
  91. int xCoordOfTick( int tick );
  92. float yCoordOfLevel( float level );
  93. inline void drawLevelTick(QPainter & p, int tick, float value);
  94. timeMap::iterator getNodeAt(int x, int y, bool outValue = false, int r = 5);
  95. void drawLine( int x0, float y0, int x1, float y1 );
  96. bool fineTuneValue(timeMap::iterator node, bool editingOutValue);
  97. protected slots:
  98. void play();
  99. void stop();
  100. void horScrolled( int new_pos );
  101. void verScrolled( int new_pos );
  102. void setEditMode(AutomationEditor::EditModes mode);
  103. void setEditMode(int mode);
  104. void setProgressionType(AutomationClip::ProgressionTypes type);
  105. void setProgressionType(int type);
  106. void setTension();
  107. void updatePosition( const TimePos & t );
  108. void zoomingXChanged();
  109. void zoomingYChanged();
  110. /// Updates the clip's quantization using the current user selected value.
  111. void setQuantization();
  112. private:
  113. enum Actions
  114. {
  115. NONE,
  116. MOVE_VALUE,
  117. ERASE_VALUES,
  118. MOVE_OUTVALUE,
  119. RESET_OUTVALUES,
  120. DRAW_LINE
  121. } ;
  122. // some constants...
  123. static const int SCROLLBAR_SIZE = 12;
  124. static const int TOP_MARGIN = 16;
  125. static const int DEFAULT_Y_DELTA = 6;
  126. static const int DEFAULT_STEPS_PER_BAR = 16;
  127. static const int DEFAULT_PPB = 12 * DEFAULT_STEPS_PER_BAR;
  128. static const int VALUES_WIDTH = 64;
  129. AutomationEditor();
  130. AutomationEditor( const AutomationEditor & );
  131. virtual ~AutomationEditor();
  132. static QPixmap * s_toolDraw;
  133. static QPixmap * s_toolErase;
  134. static QPixmap * s_toolDrawOut;
  135. static QPixmap * s_toolMove;
  136. static QPixmap * s_toolYFlip;
  137. static QPixmap * s_toolXFlip;
  138. ComboBoxModel m_zoomingXModel;
  139. ComboBoxModel m_zoomingYModel;
  140. ComboBoxModel m_quantizeModel;
  141. static const QVector<float> m_zoomXLevels;
  142. FloatModel * m_tensionModel;
  143. AutomationClip * m_clip;
  144. float m_minLevel;
  145. float m_maxLevel;
  146. float m_step;
  147. float m_scrollLevel;
  148. float m_bottomLevel;
  149. float m_topLevel;
  150. void centerTopBottomScroll();
  151. void updateTopBottomLevels();
  152. QScrollBar * m_leftRightScroll;
  153. QScrollBar * m_topBottomScroll;
  154. TimePos m_currentPosition;
  155. Actions m_action;
  156. int m_moveXOffset;
  157. float m_drawLastLevel;
  158. tick_t m_drawLastTick;
  159. int m_ppb;
  160. int m_y_delta;
  161. bool m_y_auto;
  162. // Time position (key) of automation node whose outValue is being dragged
  163. int m_draggedOutValueKey;
  164. EditModes m_editMode;
  165. bool m_mouseDownLeft;
  166. bool m_mouseDownRight; //true if right click is being held down
  167. TimeLineWidget * m_timeLine;
  168. bool m_scrollBack;
  169. void drawCross(QPainter & p );
  170. void drawAutomationPoint( QPainter & p, timeMap::iterator it );
  171. bool inPatternEditor();
  172. QColor m_barLineColor;
  173. QColor m_beatLineColor;
  174. QColor m_lineColor;
  175. QBrush m_graphColor;
  176. QColor m_nodeInValueColor;
  177. QColor m_nodeOutValueColor;
  178. QBrush m_scaleColor;
  179. QColor m_crossColor;
  180. QColor m_backgroundShade;
  181. friend class AutomationEditorWindow;
  182. signals:
  183. void currentClipChanged();
  184. void positionChanged( const TimePos & );
  185. } ;
  186. class AutomationEditorWindow : public Editor
  187. {
  188. Q_OBJECT
  189. static const int INITIAL_WIDTH = 860;
  190. static const int INITIAL_HEIGHT = 480;
  191. public:
  192. AutomationEditorWindow();
  193. ~AutomationEditorWindow();
  194. void setCurrentClip(AutomationClip* clip);
  195. const AutomationClip* currentClip();
  196. void dropEvent( QDropEvent * _de ) override;
  197. void dragEnterEvent( QDragEnterEvent * _dee ) override;
  198. void open(AutomationClip* clip);
  199. AutomationEditor* m_editor;
  200. QSize sizeHint() const override;
  201. public slots:
  202. void clearCurrentClip();
  203. signals:
  204. void currentClipChanged();
  205. protected:
  206. void focusInEvent(QFocusEvent * event) override;
  207. protected slots:
  208. void play() override;
  209. void stop() override;
  210. private slots:
  211. void updateWindowTitle();
  212. private:
  213. QAction* m_discreteAction;
  214. QAction* m_linearAction;
  215. QAction* m_cubicHermiteAction;
  216. QAction* m_flipYAction;
  217. QAction* m_flipXAction;
  218. Knob * m_tensionKnob;
  219. ComboBox * m_zoomingXComboBox;
  220. ComboBox * m_zoomingYComboBox;
  221. ComboBox * m_quantizeComboBox;
  222. };
  223. #endif