You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
4.3KB

  1. /* EventMap Widget
  2. * Copyleft (C) 2001 David Griffiths <dave@pawfal.org>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <FL/Fl.H>
  19. #include <FL/Fl_Group.H>
  20. #include <FL/Fl_Button.H>
  21. #include <FL/Fl_Window.H>
  22. #include <iostream>
  23. #include <map>
  24. #include <string>
  25. #include <vector>
  26. #include "Fl_SEvent.h"
  27. #ifndef EVENTMAP
  28. #define EVENTMAP
  29. using namespace std;
  30. /////////////////////////////////////////////////////////
  31. class EventInfo
  32. {
  33. public:
  34. enum Type{START,ON,END};
  35. EventInfo(int ID, int Group, Type t, float s)
  36. {m_ID=ID; m_Group=Group; m_Type=t; m_SectionStart=s;}
  37. int m_ID;
  38. int m_Group;
  39. Type m_Type;
  40. float m_SectionStart;
  41. };
  42. /////////////////////////////////////////////////////////
  43. class Fl_EventMap : public Fl_Group
  44. {
  45. public:
  46. enum ModeType {ARRANGE_MAP,MELODY_MAP,PERCUSSION_MAP};
  47. Fl_EventMap(int x, int y, int w, int h, const char* label=0);
  48. virtual void draw();
  49. virtual int handle(int event);
  50. void CreateWindow();
  51. vector<EventInfo> GetEvents(float Time);
  52. void SetUpdate(bool s) {m_Update=s;}
  53. void SetZoomLevel(float s);
  54. void SetGridSizeX(int s) { m_GridSizeX=s; }
  55. void SetGridSizeY(int s) { m_GridSizeY=s; }
  56. void SetType(ModeType s) { m_Type=s; }
  57. ModeType GetType() { return m_Type; }
  58. // Sort this hideaous mess out!!
  59. void SetSeq(void* s) { m_SeqPointer=s; }
  60. void *GetSeq() { return m_SeqPointer; }
  61. float GetStartTime() { return m_StartLoop;}
  62. float GetEndTime() { return m_EndLoop;}
  63. void SetEndTime(float s) { m_EndLoop=s;}
  64. void SetBeatsBar(int s) { m_BeatsBar=s; redraw();}
  65. void SetBarLength(float s) { m_BarLength=s; redraw(); }
  66. void SetSnapGap(float s);
  67. // void SetKeyColMap(int *s) { m_KeyColMap=s; }
  68. int *GetKeyColMap() { return m_KeyColMap; }
  69. int GetX() { return x(); }
  70. int GetY() { return y(); }
  71. void SetUpdateLineClip(int X, int Y, int W, int H)
  72. { m_ClipX=X; m_ClipY=Y; m_ClipW=W; m_ClipH=H; }
  73. void DrawBeats(bool s) { m_DrawBeats=s; redraw(); }
  74. int AddEventTime(float st, int g, float lt, Fl_SEvent::Type EType, bool CallBack=true);
  75. void SetEventLength(int ID, float l);
  76. int AddEvent(int x, int y, int w, Fl_SEvent::Type EType, bool CallBack=true);
  77. void CopyEvent(int x, int y, int w, int ID, float LengthTime);
  78. void RemoveAllEvents();
  79. void RemoveEvent(int ID);
  80. Fl_SEvent *GetEvent(int ID);
  81. void CopyFrom(Fl_EventMap *Other);
  82. void SetNewEventCallback(Fl_Callback* s) { cb_NewEvent=s; }
  83. void SetCopyEventCallback(Fl_Callback* s) { cb_CopyEvent=s; }
  84. void SetRightMouseCallback(Fl_Callback* s) { cb_RightMouse=s; }
  85. void TriggerStart();
  86. void TriggerEnd();
  87. void SetFirstUpdate() { m_FirstUpdate=true; }
  88. protected:
  89. int GetGroupFromY(int y);
  90. private:
  91. void *m_SeqPointer;
  92. ModeType m_Type;
  93. bool m_Update;
  94. float m_Zoom;
  95. int m_GridSizeX;
  96. int m_GridSizeY;
  97. int m_PixelsPerSec;
  98. int m_NextID;
  99. float m_StartLoop;
  100. float m_EndLoop;
  101. int m_Pos;
  102. int m_LastPos;
  103. bool m_DrawBeats;
  104. float m_BarLength;
  105. int m_BeatsBar;
  106. int m_ClipX,m_ClipY,m_ClipW,m_ClipH;
  107. Fl_TriEvent *m_StartTri;
  108. Fl_TriEvent *m_PosTri;
  109. Fl_TriEvent *m_EndTri;
  110. int m_KeyColMap[12];
  111. map<int,Fl_SEvent*> m_EventMap;
  112. void (*cb_NewEvent)(Fl_Widget*, void*);
  113. public:
  114. // needed to be called by the event widgets
  115. void (*cb_RightMouse)(Fl_Widget*, void*);
  116. void (*cb_CopyEvent)(Fl_Widget*, void*);
  117. private:
  118. bool m_FirstUpdate;
  119. friend istream &operator>>(istream &s, Fl_EventMap &o);
  120. friend ostream &operator<<(ostream &s, Fl_EventMap &o);
  121. };
  122. istream &operator>>(istream &s, Fl_EventMap &o);
  123. ostream &operator<<(ostream &s, Fl_EventMap &o);
  124. #endif