1
0

View_ins.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. * view_ins.h
  3. * ----------
  4. * Purpose: Instrument tab, lower panel.
  5. * Notes : (currently none)
  6. * Authors: Olivier Lapicque
  7. * OpenMPT Devs
  8. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  9. */
  10. #pragma once
  11. #include "openmpt/all/BuildSettings.hpp"
  12. OPENMPT_NAMESPACE_BEGIN
  13. #define INSSTATUS_DRAGGING 0x01
  14. #define INSSTATUS_NCLBTNDOWN 0x02
  15. #define INSSTATUS_SPLITCURSOR 0x04
  16. // Non-Client toolbar buttons
  17. #define ENV_LEFTBAR_BUTTONS 22
  18. enum DragPoints
  19. {
  20. ENV_DRAGLOOPSTART = (MAX_ENVPOINTS + 1),
  21. ENV_DRAGLOOPEND = (MAX_ENVPOINTS + 2),
  22. ENV_DRAGSUSTAINSTART = (MAX_ENVPOINTS + 3),
  23. ENV_DRAGSUSTAINEND = (MAX_ENVPOINTS + 4),
  24. ENV_DRAGPREVIOUS = (MAX_ENVPOINTS + 5),
  25. ENV_DRAGNEXT = (MAX_ENVPOINTS + 6),
  26. };
  27. class CViewInstrument: public CModScrollView
  28. {
  29. protected:
  30. CImageList m_bmpEnvBar;
  31. CPoint m_ptMenu;
  32. CRect m_rcClient, m_rcOldClient;
  33. CBitmap m_bmpGrid;
  34. CBitmap m_bmpMemMain;
  35. HBITMAP m_pbmpOldGrid = nullptr;
  36. HBITMAP oldBitmap = nullptr;
  37. EnvelopeType m_nEnv = ENV_VOLUME;
  38. uint32 m_nDragItem = 1, m_nBtnMouseOver = 0xFFFF;
  39. DWORD m_dwStatus = 0;
  40. DWORD m_NcButtonState[ENV_LEFTBAR_BUTTONS];
  41. INSTRUMENTINDEX m_nInstrument = 1;
  42. CDC m_dcMemMain;
  43. CDC m_dcGrid;
  44. int m_GridScrollPos = -1;
  45. int m_GridSpeed = -1;
  46. float m_zoom = 4;
  47. int m_envPointSize = 4;
  48. bool m_bGrid = true;
  49. bool m_bGridForceRedraw = false;
  50. bool m_mouseMoveModified = false;
  51. std::bitset<128> m_baPlayingNote;
  52. CModDoc::NoteToChannelMap m_noteChannel; // Note -> Preview channel assignment
  53. std::array<uint32, MAX_CHANNELS> m_dwNotifyPos;
  54. public:
  55. CViewInstrument();
  56. DECLARE_SERIAL(CViewInstrument)
  57. protected:
  58. void PrepareUndo(const char *description);
  59. ////////////////////////
  60. // Envelope get stuff
  61. // Flags
  62. bool EnvGetFlag(const EnvelopeFlags dwFlag) const;
  63. bool EnvGetLoop() const { return EnvGetFlag(ENV_LOOP); };
  64. bool EnvGetSustain() const { return EnvGetFlag(ENV_SUSTAIN); };
  65. bool EnvGetCarry() const { return EnvGetFlag(ENV_CARRY); };
  66. // Misc.
  67. uint32 EnvGetTick(int nPoint) const;
  68. uint32 EnvGetValue(int nPoint) const;
  69. uint32 EnvGetLastPoint() const;
  70. uint32 EnvGetNumPoints() const;
  71. // Get loop points
  72. uint32 EnvGetLoopStart() const;
  73. uint32 EnvGetLoopEnd() const;
  74. uint32 EnvGetSustainStart() const;
  75. uint32 EnvGetSustainEnd() const;
  76. // Get envelope status
  77. bool EnvGetVolEnv() const;
  78. bool EnvGetPanEnv() const;
  79. bool EnvGetPitchEnv() const;
  80. bool EnvGetFilterEnv() const;
  81. ////////////////////////
  82. // Envelope set stuff
  83. // Flags
  84. bool EnvSetFlag(EnvelopeFlags flag, bool enable);
  85. bool EnvSetLoop(bool enable) {return EnvSetFlag(ENV_LOOP, enable);};
  86. bool EnvSetSustain(bool enable) {return EnvSetFlag(ENV_SUSTAIN, enable);};
  87. bool EnvSetCarry(bool enable) {return EnvSetFlag(ENV_CARRY, enable);};
  88. // Misc.
  89. bool EnvSetValue(int nPoint, int32 nTick = int32_min, int32 nValue = int32_min, bool moveTail = false);
  90. bool CanMovePoint(uint32 envPoint, int step);
  91. // Set loop points
  92. bool EnvSetLoopStart(int nPoint);
  93. bool EnvSetLoopEnd(int nPoint);
  94. bool EnvSetSustainStart(int nPoint);
  95. bool EnvSetSustainEnd(int nPoint);
  96. bool EnvToggleReleaseNode(int nPoint);
  97. // Set envelope status
  98. bool EnvToggleEnv(EnvelopeType envelope, CSoundFile &sndFile, ModInstrument &ins, bool enable, EnvelopeNode::value_t defaultValue, EnvelopeFlags extraFlags = EnvelopeFlags(0));
  99. bool EnvSetVolEnv(bool enable);
  100. bool EnvSetPanEnv(bool enable);
  101. bool EnvSetPitchEnv(bool enable);
  102. bool EnvSetFilterEnv(bool enable);
  103. // Keyboard envelope control
  104. void EnvKbdSelectPoint(DragPoints point);
  105. void EnvKbdMovePointLeft(int stepsize);
  106. void EnvKbdMovePointRight(int stepsize);
  107. void EnvKbdMovePointVertical(int stepsize);
  108. void EnvKbdInsertPoint();
  109. void EnvKbdRemovePoint();
  110. void EnvKbdSetLoopStart();
  111. void EnvKbdSetLoopEnd();
  112. void EnvKbdSetSustainStart();
  113. void EnvKbdSetSustainEnd();
  114. void EnvKbdToggleReleaseNode();
  115. bool IsDragItemEnvPoint() const { return m_nDragItem >= 1 && m_nDragItem <= EnvGetNumPoints(); }
  116. ////////////////////////
  117. // Misc stuff
  118. void UpdateScrollSize();
  119. void SetModified(InstrumentHint hint, bool updateAll);
  120. BOOL SetCurrentInstrument(INSTRUMENTINDEX nIns, EnvelopeType m_nEnv = ENV_VOLUME);
  121. ModInstrument *GetInstrumentPtr() const;
  122. InstrumentEnvelope *GetEnvelopePtr() const;
  123. bool InsertAtPoint(CPoint pt);
  124. uint32 EnvInsertPoint(int nTick, int nValue);
  125. bool EnvRemovePoint(uint32 nPoint);
  126. uint32 DragItemToEnvPoint() const;
  127. int TickToScreen(int nTick) const;
  128. int PointToScreen(int nPoint) const;
  129. int ScreenToTick(int x) const;
  130. int ScreenToPoint(int x, int y) const;
  131. int ValueToScreen(int val) const { return m_rcClient.bottom - 1 - (val * (m_rcClient.bottom - 1)) / 64; }
  132. int ScreenToValue(int y) const;
  133. void InvalidateEnvelope() { InvalidateRect(NULL, FALSE); }
  134. void DrawPositionMarks();
  135. void DrawNcButton(CDC *pDC, UINT nBtn);
  136. bool GetNcButtonRect(UINT button, CRect &rect) const;
  137. UINT GetNcButtonAtPoint(CPoint point, CRect *outRect = nullptr) const;
  138. void UpdateNcButtonState();
  139. void PlayNote(ModCommand::NOTE note);
  140. void DrawGrid(CDC *memDC, uint32 speed);
  141. void UpdateIndicator();
  142. void UpdateIndicator(int tick, int val);
  143. CString EnvValueToString(int tick, int val) const;
  144. void OnEnvZoomIn() { EnvSetZoom(m_zoom + 1); };
  145. void OnEnvZoomOut() { EnvSetZoom(m_zoom - 1); };
  146. void EnvSetZoom(float fNewZoom);
  147. public:
  148. //{{AFX_VIRTUAL(CViewInstrument)
  149. void OnDraw(CDC *) override;
  150. void OnInitialUpdate() override;
  151. void UpdateView(UpdateHint hint, CObject *pObj = nullptr) override;
  152. BOOL PreTranslateMessage(MSG *pMsg) override;
  153. BOOL OnDragonDrop(BOOL, const DRAGONDROP *) override;
  154. LRESULT OnModViewMsg(WPARAM, LPARAM) override;
  155. LRESULT OnPlayerNotify(Notification *) override;
  156. HRESULT get_accName(VARIANT varChild, BSTR *pszName) override;
  157. INT_PTR OnToolHitTest(CPoint point, TOOLINFO *pTI) const override;
  158. //}}AFX_VIRTUAL
  159. protected:
  160. //{{AFX_MSG(CViewInstrument)
  161. afx_msg BOOL OnEraseBkgnd(CDC *) { return TRUE; }
  162. afx_msg void OnSetFocus(CWnd *pOldWnd);
  163. afx_msg void OnSize(UINT nType, int cx, int cy);
  164. afx_msg LRESULT OnDPIChanged(WPARAM = 0, LPARAM = 0);
  165. afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp);
  166. afx_msg LRESULT OnNcHitTest(CPoint point);
  167. afx_msg void OnNcPaint();
  168. afx_msg void OnPrevInstrument();
  169. afx_msg void OnNextInstrument();
  170. afx_msg void OnMouseMove(UINT, CPoint);
  171. afx_msg void OnLButtonDown(UINT, CPoint);
  172. afx_msg void OnLButtonUp(UINT, CPoint);
  173. afx_msg void OnLButtonDblClk(UINT /*nFlags*/, CPoint point) { InsertAtPoint(point); }
  174. afx_msg void OnRButtonDown(UINT, CPoint);
  175. afx_msg void OnMButtonDown(UINT, CPoint);
  176. afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);
  177. afx_msg void OnNcLButtonDown(UINT, CPoint);
  178. afx_msg void OnNcLButtonUp(UINT, CPoint);
  179. afx_msg void OnNcLButtonDblClk(UINT, CPoint);
  180. afx_msg void OnEnvLoopChanged();
  181. afx_msg void OnEnvSustainChanged();
  182. afx_msg void OnEnvCarryChanged();
  183. afx_msg void OnEnvToggleReleasNode();
  184. afx_msg void OnEnvInsertPoint();
  185. afx_msg void OnEnvRemovePoint();
  186. afx_msg void OnSelectVolumeEnv();
  187. afx_msg void OnSelectPanningEnv();
  188. afx_msg void OnSelectPitchEnv();
  189. afx_msg void OnEnvVolChanged();
  190. afx_msg void OnEnvPanChanged();
  191. afx_msg void OnEnvPitchChanged();
  192. afx_msg void OnEnvFilterChanged();
  193. afx_msg void OnEnvToggleGrid();
  194. afx_msg void OnEnvLoad();
  195. afx_msg void OnEnvSave();
  196. afx_msg void OnEditCopy();
  197. afx_msg void OnEditPaste();
  198. afx_msg void OnEditSampleMap();
  199. afx_msg void OnEnvelopeScalePoints();
  200. afx_msg void OnDropFiles(HDROP hDropInfo);
  201. afx_msg LRESULT OnCustomKeyMsg(WPARAM, LPARAM);
  202. afx_msg LRESULT OnMidiMsg(WPARAM, LPARAM);
  203. afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
  204. afx_msg void OnXButtonUp(UINT nFlags, UINT nButton, CPoint point);
  205. afx_msg void OnEditUndo();
  206. afx_msg void OnEditRedo();
  207. afx_msg void OnUpdateUndo(CCmdUI *pCmdUI);
  208. afx_msg void OnUpdateRedo(CCmdUI *pCmdUI);
  209. //}}AFX_MSG
  210. DECLARE_MESSAGE_MAP()
  211. private:
  212. uint8 EnvGetReleaseNode();
  213. };
  214. OPENMPT_NAMESPACE_END