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.

166 lines
4.6KB

  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 SetTime(float Time);
  53. void SetUpdate(bool s) {m_Update=s;}
  54. void SetZoomLevel(float s);
  55. void SetGridSizeX(int s) { m_GridSizeX=s; }
  56. void SetGridSizeY(int s) { m_GridSizeY=s; }
  57. void SetType(ModeType s) { m_Type=s; }
  58. ModeType GetType() { return m_Type; }
  59. void SetID(int ID) { m_ID=ID; }
  60. int GetID() { return m_ID; }
  61. float GetStartTime() { return m_StartLoop;}
  62. float GetEndTime() { return m_EndLoop;}
  63. void SetEndTime(float s) { m_EndLoop=s;}
  64. float GetTimeOffset() { return m_TimeOffset;}
  65. void SetTimeOffset(float s) { m_TimeOffset=s;}
  66. void SetBeatsBar(int s) { m_BeatsBar=s; redraw();}
  67. void SetBarLength(float s) { m_BarLength=s; redraw(); }
  68. void SetSnapGap(float s);
  69. int *GetKeyColMap() { return m_KeyColMap; }
  70. int GetX() { return x(); }
  71. int GetY() { return y(); }
  72. void DrawBeats(bool s) { m_DrawBeats=s; redraw(); }
  73. int AddEventTime(float st, int g, float lt, Fl_SEvent::Type EType, bool CallBack=true);
  74. void SetEventLength(int ID, float l);
  75. int AddEvent(int x, int y, int w, Fl_SEvent::Type EType, bool CallBack=true);
  76. int CopyEvent(int x, int y, int w, int ID, float LengthTime);
  77. void RemoveAllEvents();
  78. void RemoveEvent(int ID);
  79. Fl_SEvent *GetEvent(int ID);
  80. void CopyFrom(Fl_EventMap *Other);
  81. // called by the event widgets on the owner of this object
  82. // if you're going to hack callbacks - do it in style ;)
  83. class EventCallbacks
  84. {
  85. public:
  86. EventCallbacks()
  87. {
  88. cb_NewEvent=cb_EventDoubleClicked=cb_CopyEvent=cb_CloneEvent=
  89. cb_InstanceEvent=cb_MoveEvent=cb_EditEvent=cb_DelEvent=
  90. cb_RenameEvent=cb_Recolour=NULL;
  91. }
  92. void (*cb_NewEvent)(Fl_Widget*, void*);
  93. void (*cb_EventDoubleClicked)(Fl_Widget*, void*);
  94. void (*cb_CopyEvent)(Fl_Widget*, void*);
  95. void (*cb_CloneEvent)(Fl_Widget*, void*);
  96. void (*cb_InstanceEvent)(Fl_Widget*, void*);
  97. void (*cb_MoveEvent)(Fl_Widget*, void*);
  98. void (*cb_EditEvent)(Fl_Widget*, void*);
  99. void (*cb_DelEvent)(Fl_Widget*, void*);
  100. void (*cb_RenameEvent)(Fl_Widget*, void*);
  101. void (*cb_Recolour)(Fl_Widget*, void*);
  102. };
  103. EventCallbacks m_Callbacks;
  104. void SetCallbacks(const EventCallbacks &s);
  105. void TriggerStart();
  106. void TriggerEnd();
  107. void SetFirstUpdate() { m_FirstUpdate=true; }
  108. protected:
  109. int GetGroupFromY(int y);
  110. private:
  111. ModeType m_Type;
  112. bool m_Update;
  113. float m_Zoom;
  114. int m_ID;
  115. int m_GridSizeX;
  116. int m_GridSizeY;
  117. int m_PixelsPerSec;
  118. int m_NextID;
  119. float m_StartLoop;
  120. float m_EndLoop;
  121. int m_Pos;
  122. int m_LastPos;
  123. bool m_DrawBeats;
  124. float m_BarLength;
  125. float m_TimeOffset;
  126. int m_BeatsBar;
  127. int m_KeyColMap[12];
  128. map<int,Fl_SEvent*> m_EventMap;
  129. bool m_FirstUpdate;
  130. friend istream &operator>>(istream &s, Fl_EventMap &o);
  131. friend ostream &operator<<(ostream &s, Fl_EventMap &o);
  132. };
  133. istream &operator>>(istream &s, Fl_EventMap &o);
  134. ostream &operator<<(ostream &s, Fl_EventMap &o);
  135. #endif