diff --git a/SpiralSound/Plugins/Widgets/Fl_EventMap.C b/SpiralSound/Plugins/Widgets/Fl_EventMap.C index 62861b2..65cb28b 100644 --- a/SpiralSound/Plugins/Widgets/Fl_EventMap.C +++ b/SpiralSound/Plugins/Widgets/Fl_EventMap.C @@ -28,14 +28,14 @@ static const int BUTTON_COLOUR = 10; static const int EVENT_COLOUR = 0; -static const int BG_COLOUR = 139; -static const int LINE_COLOUR = 140; +int BG_COLOUR;// = 139; +int BLACK_KEY_COL;// = 141; +int LINE_COLOUR;// = 140; //////////////////////////////////////////////////////////////////// Fl_EventMap::Fl_EventMap(int x, int y, int w, int h, const char* label) : Fl_Group(x,y,w,h,label), -m_SeqPointer(NULL), m_Type(ARRANGE_MAP), m_Update(true), m_Zoom(1.0f), @@ -47,107 +47,145 @@ m_StartLoop(1.0f), m_EndLoop(2.0f), m_Pos(0), m_LastPos(0), -m_DrawBeats(false), -m_BarLength(100), -m_BeatsBar(8), -cb_NewEvent(NULL), -cb_RightMouse(NULL), -cb_CopyEvent(NULL), +m_DrawBeats(true), +m_BarLength(1), +m_BeatsBar(4), m_FirstUpdate(true) { + box(FL_FLAT_BOX); + + fl_color(0,100,161); + BG_COLOUR=fl_color(); + fl_color(0,90,150); + BLACK_KEY_COL=fl_color(); + fl_color(0,80,150); + LINE_COLOUR=fl_color(); + + fl_color(200,200,200); + int w=fl_color(); + fl_color(50,50,50); + int b=fl_color(); + // white/black keys for the melody - m_KeyColMap[0] = FL_YELLOW; - m_KeyColMap[1] = FL_BLUE; - m_KeyColMap[2] = FL_YELLOW; - m_KeyColMap[3] = FL_BLUE; - m_KeyColMap[4] = FL_YELLOW; - m_KeyColMap[5] = FL_BLUE; - m_KeyColMap[6] = FL_YELLOW; - m_KeyColMap[7] = FL_YELLOW; - m_KeyColMap[8] = FL_BLUE; - m_KeyColMap[9] = FL_YELLOW; - m_KeyColMap[10] = FL_BLUE; - m_KeyColMap[11] = FL_YELLOW; + m_KeyColMap[0] = w; + m_KeyColMap[1] = b; + m_KeyColMap[2] = w; + m_KeyColMap[3] = b; + m_KeyColMap[4] = w; + m_KeyColMap[5] = w; + m_KeyColMap[6] = b; + m_KeyColMap[7] = w; + m_KeyColMap[8] = b; + m_KeyColMap[9] = w; + m_KeyColMap[10] = b; + m_KeyColMap[11] = w; } - +void Fl_EventMap::SetCallbacks(const EventCallbacks &s) +{ + m_Callbacks.cb_NewEvent=s.cb_NewEvent; + m_Callbacks.cb_EventDoubleClicked=s.cb_EventDoubleClicked; + m_Callbacks.cb_CopyEvent=s.cb_CopyEvent; + m_Callbacks.cb_CloneEvent=s.cb_CloneEvent; + m_Callbacks.cb_InstanceEvent=s.cb_InstanceEvent; + m_Callbacks.cb_MoveEvent=s.cb_MoveEvent; + m_Callbacks.cb_EditEvent=s.cb_EditEvent; + m_Callbacks.cb_DelEvent=s.cb_DelEvent; + m_Callbacks.cb_RenameEvent=s.cb_RenameEvent; + m_Callbacks.cb_Recolour=s.cb_Recolour; +} void Fl_EventMap::CreateWindow() { - int yoff=0; - - //m_StartTri = new Fl_TriEvent(90, 5, 20, 10, ""); - //m_StartTri->LockY(); - //m_StartTri->SetResizeGrab(0); - //m_StartTri->SetPixelsPerSec(m_PixelsPerSec,true); - - m_PosTri = new Fl_TriEvent(90, 5, 30, 20, ""); - m_PosTri->LockY(); - m_PosTri->SetResizeGrab(0); - m_PosTri->SetPixelsPerSec(m_PixelsPerSec,true); - - m_EndTri = new Fl_TriEvent(50, 5, 20, 10, ""); - m_EndTri->LockY(); - m_EndTri->SetResizeGrab(0); - m_EndTri->SetPixelsPerSec(m_PixelsPerSec,true); - show(); } void Fl_EventMap::draw() { - clear_damage(FL_DAMAGE_ALL); + Fl_Widget*const* a = array(); + if (!(damage() & ~FL_DAMAGE_CHILD)) + { + for (int i=children(); i--;) update_child(**a++); + return; + } + + draw_box(); + m_FirstUpdate=true; fl_color(BG_COLOUR); fl_rectf(x(),y(),w(),h()); // draw the section markers - fl_color(LINE_COLOUR); if (m_GridSizeY) { + int c=0; // draw the snap points for (int n=y(); nGetStartTime(); - //m_EndLoop=m_EndTri->GetStartTime(); - + int StartPixels=(int)(m_StartLoop*(float)m_PixelsPerSec)+x(); int EndPixels=(int)(m_EndLoop*(float)m_PixelsPerSec)+x(); - fl_line(StartPixels,y()+15,StartPixels,y()+h()); + //fl_line(StartPixels,y()+15,StartPixels,y()+h()); fl_line(EndPixels,y()+15,EndPixels,y()+h()); } - Fl_Group::draw(); + for (int i=children(); i--;) { + Fl_Widget& o = **a++; + draw_child(o); + draw_outside_label(o); + } SetFirstUpdate(); } @@ -166,7 +204,7 @@ int Fl_EventMap::handle(int event) i!=m_EventMap.end(); i++) { Fl_SEvent *pEvent = i->second; - + if (pEvent->Killed()) { RemoveEvent(i->first); @@ -187,10 +225,7 @@ void Fl_EventMap::SetZoomLevel(float s) { i->second->SetPixelsPerSec(m_PixelsPerSec); } - - //m_StartTri->SetPixelsPerSec(m_PixelsPerSec); - m_EndTri->SetPixelsPerSec(m_PixelsPerSec); - + redraw(); } @@ -207,32 +242,42 @@ void Fl_EventMap::SetSnapGap(float s) redraw(); } -vector Fl_EventMap::GetEvents(float Time) -{ +void Fl_EventMap::SetTime(float Time) +{ assert(m_PixelsPerSec!=0); + + Time -= m_TimeOffset; + m_Pos = (int)(Time*m_PixelsPerSec); // line marker update // all in all, some orrible code... - if (m_Update && window()->visible() && m_Pos!=m_LastPos) + if (m_Update && window()->visible() && visible_r() && m_Pos!=m_LastPos) { window()->make_current(); int DrawPos=m_Pos+x(); - m_PosTri->resize(DrawPos,m_PosTri->y(),m_PosTri->w(),m_PosTri->h()); - redraw(); - -/* if (DrawPos>m_ClipX && DrawPosx(); + int Top=parent()->y(); + int Width=parent()->w(); + int Depth=parent()->h(); + + if (DrawPos>Left && DrawPosmake_current(); + } } m_FirstUpdate=false; +} + +vector Fl_EventMap::GetEvents(float Time) +{ + SetTime(Time); vector EventVec; for (map::iterator i=m_EventMap.begin(); @@ -290,6 +335,7 @@ int Fl_EventMap::AddEvent(int x, int y, int w, Fl_SEvent::Type EType, bool CallB NewEvent->color(EVENT_COLOUR); NewEvent->labelsize(10); NewEvent->SetID(m_NextID++); + NewEvent->SetType(EType); char Name[256]; if (m_Type==ARRANGE_MAP) @@ -316,6 +362,11 @@ int Fl_EventMap::AddEvent(int x, int y, int w, Fl_SEvent::Type EType, bool CallB } add(NewEvent); + + // can only build the menus after adding to the parent, as the features in the + // menu depend on which callbacks have been filled out by the parent. + NewEvent->BuildMenu(); + NewEvent->SnapX(); NewEvent->SnapY(); @@ -323,14 +374,14 @@ int Fl_EventMap::AddEvent(int x, int y, int w, Fl_SEvent::Type EType, bool CallB m_EventMap[NewEvent->GetID()]=NewEvent; - int ID = NewEvent->GetID(); - if (cb_NewEvent && CallBack) cb_NewEvent(NewEvent,&ID); + int pID = NewEvent->GetID(); + if (m_Callbacks.cb_NewEvent && CallBack) m_Callbacks.cb_NewEvent(NewEvent,&pID); redraw(); return NewEvent->GetID(); } -void Fl_EventMap::CopyEvent(int x, int y, int w, int ID, float LengthTime) +int Fl_EventMap::CopyEvent(int x, int y, int w, int ID, float LengthTime) { // make the new widget int NewID = AddEvent(x,y,w,m_EventMap[ID]->GetType(),false); @@ -343,8 +394,10 @@ void Fl_EventMap::CopyEvent(int x, int y, int w, int ID, float LengthTime) //GetEvent(NewID)->SetName(Name); GetEvent(NewID)->SetName(m_EventMap[ID]->GetName()); + GetEvent(NewID)->SetColour(m_EventMap[ID]->GetColour()); + GetEvent(NewID)->SetChannel(m_EventMap[ID]->GetChannel()); - if (cb_CopyEvent) cb_CopyEvent(GetEvent(NewID),&ID); + return NewID; } void Fl_EventMap::RemoveAllEvents() @@ -376,6 +429,8 @@ void Fl_EventMap::RemoveEvent(int ID) remove(e); m_EventMap.erase(i); delete(e); + + cerr<<"removed "< GetEvents(float Time); + void SetTime(float Time); void SetUpdate(bool s) {m_Update=s;} void SetZoomLevel(float s); void SetGridSizeX(int s) { m_GridSizeX=s; } @@ -71,34 +72,55 @@ public: void SetType(ModeType s) { m_Type=s; } ModeType GetType() { return m_Type; } - // Sort this hideaous mess out!! - void SetSeq(void* s) { m_SeqPointer=s; } - void *GetSeq() { return m_SeqPointer; } + void SetID(int ID) { m_ID=ID; } + int GetID() { return m_ID; } float GetStartTime() { return m_StartLoop;} float GetEndTime() { return m_EndLoop;} void SetEndTime(float s) { m_EndLoop=s;} + float GetTimeOffset() { return m_TimeOffset;} + void SetTimeOffset(float s) { m_TimeOffset=s;} void SetBeatsBar(int s) { m_BeatsBar=s; redraw();} void SetBarLength(float s) { m_BarLength=s; redraw(); } void SetSnapGap(float s); -// void SetKeyColMap(int *s) { m_KeyColMap=s; } int *GetKeyColMap() { return m_KeyColMap; } int GetX() { return x(); } int GetY() { return y(); } - void SetUpdateLineClip(int X, int Y, int W, int H) - { m_ClipX=X; m_ClipY=Y; m_ClipW=W; m_ClipH=H; } void DrawBeats(bool s) { m_DrawBeats=s; redraw(); } int AddEventTime(float st, int g, float lt, Fl_SEvent::Type EType, bool CallBack=true); void SetEventLength(int ID, float l); int AddEvent(int x, int y, int w, Fl_SEvent::Type EType, bool CallBack=true); - void CopyEvent(int x, int y, int w, int ID, float LengthTime); + int CopyEvent(int x, int y, int w, int ID, float LengthTime); void RemoveAllEvents(); void RemoveEvent(int ID); Fl_SEvent *GetEvent(int ID); void CopyFrom(Fl_EventMap *Other); - void SetNewEventCallback(Fl_Callback* s) { cb_NewEvent=s; } - void SetCopyEventCallback(Fl_Callback* s) { cb_CopyEvent=s; } - void SetRightMouseCallback(Fl_Callback* s) { cb_RightMouse=s; } + // called by the event widgets on the owner of this object + // if you're going to hack callbacks - do it in style ;) + class EventCallbacks + { + public: + EventCallbacks() + { + cb_NewEvent=cb_EventDoubleClicked=cb_CopyEvent=cb_CloneEvent= + cb_InstanceEvent=cb_MoveEvent=cb_EditEvent=cb_DelEvent= + cb_RenameEvent=cb_Recolour=NULL; + } + + void (*cb_NewEvent)(Fl_Widget*, void*); + void (*cb_EventDoubleClicked)(Fl_Widget*, void*); + void (*cb_CopyEvent)(Fl_Widget*, void*); + void (*cb_CloneEvent)(Fl_Widget*, void*); + void (*cb_InstanceEvent)(Fl_Widget*, void*); + void (*cb_MoveEvent)(Fl_Widget*, void*); + void (*cb_EditEvent)(Fl_Widget*, void*); + void (*cb_DelEvent)(Fl_Widget*, void*); + void (*cb_RenameEvent)(Fl_Widget*, void*); + void (*cb_Recolour)(Fl_Widget*, void*); + }; + + EventCallbacks m_Callbacks; + void SetCallbacks(const EventCallbacks &s); void TriggerStart(); void TriggerEnd(); @@ -110,13 +132,10 @@ protected: int GetGroupFromY(int y); private: - - void *m_SeqPointer; - ModeType m_Type; - bool m_Update; float m_Zoom; + int m_ID; int m_GridSizeX; int m_GridSizeY; int m_PixelsPerSec; @@ -124,28 +143,15 @@ private: float m_StartLoop; float m_EndLoop; int m_Pos; - int m_LastPos; - + int m_LastPos; bool m_DrawBeats; float m_BarLength; - int m_BeatsBar; + float m_TimeOffset; + int m_BeatsBar; - int m_ClipX,m_ClipY,m_ClipW,m_ClipH; - - Fl_TriEvent *m_StartTri; - Fl_TriEvent *m_PosTri; - Fl_TriEvent *m_EndTri; - int m_KeyColMap[12]; map m_EventMap; - - void (*cb_NewEvent)(Fl_Widget*, void*); -public: - // needed to be called by the event widgets - void (*cb_RightMouse)(Fl_Widget*, void*); - void (*cb_CopyEvent)(Fl_Widget*, void*); -private: bool m_FirstUpdate; diff --git a/SpiralSound/Plugins/Widgets/Fl_SEvent.C b/SpiralSound/Plugins/Widgets/Fl_SEvent.C index 2bdc792..0b193d7 100644 --- a/SpiralSound/Plugins/Widgets/Fl_SEvent.C +++ b/SpiralSound/Plugins/Widgets/Fl_SEvent.C @@ -25,6 +25,7 @@ static const int MELODY_WIDGET_COL = 142; static const int PERCUSSION_WIDGET_COL = 140; +static const int EVENT_RESIZE_GRAB = 10; Fl_SEvent::Fl_SEvent(int x, int y, int w, int h, const char* label) : Fl_Group(x,y,w,h,""), @@ -34,6 +35,7 @@ m_FirstUpdate(false), m_LastUpdate(false), m_Name(""), m_ID(-1), +m_Colour(PERCUSSION_WIDGET_COL), m_GridX(0), m_GridY(0), m_LockX(false), @@ -41,6 +43,7 @@ m_LockY(false), m_LockResize(true), m_ResizeGrab(8), m_PixelsPerSec(100), +m_Channel(0), m_StartTime(0.0f), m_LengthTime(0.0f), m_SnapGap(0.0f), @@ -49,17 +52,27 @@ m_DelMe(false) { Fl_Group::label(m_Name.c_str()); labelsize(8); - - m_Menu = new Fl_Menu_Button(x,y,w,h,""); - m_Menu->type(Fl_Menu_Button::POPUP2); +} + +void Fl_SEvent::BuildMenu() +{ + Fl_EventMap::EventCallbacks *cb =&((Fl_EventMap*)parent())->m_Callbacks; + + m_Menu = new Fl_Menu_Button(x(),y(),w(),h(),""); + m_Menu->type(Fl_Menu_Button::POPUP3); m_Menu->textsize(8); - m_Menu->add("copy", 0, NULL); - m_Menu->add("instance", 0, NULL); - m_Menu->add("edit", 0, NULL); - m_Menu->add("delete", 0, NULL); + + if (cb->cb_CopyEvent) m_Menu->add("copy", 0, cb->cb_CopyEvent,this); + if (cb->cb_CloneEvent) m_Menu->add("clone", 0, cb->cb_CloneEvent,this); + if (cb->cb_InstanceEvent) m_Menu->add("instance", 0, cb->cb_InstanceEvent,this); + if (cb->cb_DelEvent) m_Menu->add("delete", 0, cb->cb_DelEvent,this); + if (cb->cb_RenameEvent) m_Menu->add("rename", 0, cb->cb_RenameEvent,this); + if (cb->cb_Recolour) m_Menu->add("colour", 0, cb->cb_Recolour,this); + if (cb->cb_EditEvent) m_Menu->add("edit", 0, cb->cb_EditEvent,this); add(m_Menu); } + Fl_SEvent::Fl_SEvent(const Fl_SEvent &Other) : Fl_Group(Other.x(),Other.y(),Other.w(),Other.h(),Other.label()), m_Type(Other.m_Type), @@ -68,6 +81,7 @@ m_FirstUpdate(Other.m_FirstUpdate), m_LastUpdate(Other.m_LastUpdate), m_Name(Other.m_Name), m_ID(Other.m_ID), +m_Colour(Other.m_Colour), m_GridX(Other.m_GridX), m_GridY(Other.m_GridY), m_LockX(Other.m_LockX), @@ -75,6 +89,7 @@ m_LockY(Other.m_LockY), m_LockResize(Other.m_LockResize), m_ResizeGrab(Other.m_ResizeGrab), m_PixelsPerSec(Other.m_PixelsPerSec), +m_Channel(Other.m_Channel), m_StartTime(Other.m_StartTime), m_LengthTime(Other.m_LengthTime), m_SnapGap(Other.m_SnapGap), @@ -128,8 +143,7 @@ void Fl_SEvent::draw() } else { - if (m_Type==MELODY) fl_color(MELODY_WIDGET_COL); - else fl_color(PERCUSSION_WIDGET_COL); + fl_color(m_Colour); fl_rectf(x()+1,y()+1,w()-1,h()-1); @@ -153,14 +167,17 @@ int Fl_SEvent::handle(int event) int mx=Fl::event_x(); int my=Fl::event_y(); + m_Menu->resize(x(),y(),w(),h()); + + Fl_EventMap::EventCallbacks *cb =&((Fl_EventMap*)parent())->m_Callbacks; + static int offsx,offsy; if (Fl::event_button()==1 && event==FL_PUSH && Fl::event_clicks()==1) { - // a bit crap I suppose - if (((Fl_EventMap*)parent())->cb_EventDoubleClicked!=NULL) + if (cb->cb_EventDoubleClicked!=NULL) { - ((Fl_EventMap*)parent())->cb_EventDoubleClicked(this,NULL); + cb->cb_EventDoubleClicked(this,NULL); } } @@ -172,36 +189,24 @@ int Fl_SEvent::handle(int event) offsx=mx-x(); offsy=my-y(); - if (Fl::event_key(FL_BackSpace)) + /*if (Fl::event_key(FL_BackSpace)) { Fl_EventMap *p = (Fl_EventMap*)parent(); if (p && p->GetType()!=Fl_EventMap::ARRANGE_MAP) { + if (cb->cb_DelEvent!=NULL) cb->cb_DelEvent(this,NULL); m_DelMe=true; } - } + }*/ if (LastButtonPushed==1) - { - // if the last EVENT_RESIZE_GRAB pixels - // have been grabbed, resize. - m_CurrentDragMode=MOVING; - //} - - } - - /*if (LastButtonPushed==2) - { - // copy to end - Fl_EventMap *p = (Fl_EventMap*)parent(); - if (p) p->CopyEvent(x()+w(),y(),w(),m_ID,m_LengthTime); - }*/ - - if (LastButtonPushed==3) - { - m_CurrentDragMode=RESIZING; - } - + { + // if the last EVENT_RESIZE_GRAB pixels + // have been grabbed, resize. + if (offsx>w()-EVENT_RESIZE_GRAB) m_CurrentDragMode=RESIZING; + else m_CurrentDragMode=MOVING; + } + // fall through case FL_DRAG: { @@ -227,6 +232,7 @@ int Fl_SEvent::handle(int event) my=y(); SnapY(); + if (cb->cb_MoveEvent!=NULL) cb->cb_MoveEvent(this,NULL); parent()->redraw(); } } @@ -296,32 +302,6 @@ int Fl_SEvent::GetParentY() //////////////////////////////////////////////////////////////////// -Fl_TriEvent::Fl_TriEvent(int x, int y, int w, int h, const char* label) : -Fl_SEvent(x,y,w,h,label) -{ -} - -Fl_TriEvent::Fl_TriEvent(const Fl_TriEvent &Other) : -Fl_SEvent(Other) -{ -} - -void Fl_TriEvent::draw() -{ - // hackish way to override the zoon scale of the width - w(10); - h(1000); - - fl_color(FL_BLACK); - //fl_line(x(),y(),x()+10,y()); - //fl_line(x()+10,y(),x(),y()+10); - //fl_line(x(),y()+10,x(),y()); - - fl_line(x(),y(),x(),y()+1000); -} - -//////////////////////////////////////////////////////////////////// - Fl_CircEvent::Fl_CircEvent(int x, int y, int w, int h, const char* label) : Fl_SEvent(x,y,12,h,label) { diff --git a/SpiralSound/Plugins/Widgets/Fl_SEvent.h b/SpiralSound/Plugins/Widgets/Fl_SEvent.h index ba06437..1db1f30 100644 --- a/SpiralSound/Plugins/Widgets/Fl_SEvent.h +++ b/SpiralSound/Plugins/Widgets/Fl_SEvent.h @@ -48,12 +48,18 @@ public: virtual void draw(); virtual int handle(int event); + void BuildMenu(); + int GetID() { return m_ID; } + void SetID(int s) { m_ID=s; } + void SetChannel(int s) { m_Channel=s; } + int GetChannel() { return m_Channel; } + int GetColour() { return m_Colour; } + void SetColour(int s) { m_Colour=s; } void SnapX() { if (m_GridX) x(x()-((x()-GetParentX())%m_GridX)); redraw(); } void SnapY() { if (m_GridY) y(y()-((y()-GetParentY())%m_GridY)); redraw(); } void SetName(string s) { m_Name=s; } string GetName() { return m_Name; } - void SetID(int s) { m_ID=s; } void SetGridX(int s) { m_GridX=s; } void SetGridY(int s) { m_GridY=s; } void LockX() { m_LockX=true; } @@ -77,6 +83,7 @@ public: bool AtStart() { return m_FirstUpdate; } bool AtEnd() { return m_LastUpdate; } bool Killed() { return m_DelMe; } + void KillMe() { m_DelMe=true; } int GetX() { return x(); } int GetY() { return y(); } @@ -96,6 +103,7 @@ private: string m_Name; int m_ID; + int m_Colour; int m_GridX; int m_GridY; bool m_LockX; @@ -103,6 +111,7 @@ private: bool m_LockResize; int m_ResizeGrab; int m_PixelsPerSec; + int m_Channel; float m_StartTime; float m_LengthTime; @@ -117,17 +126,6 @@ private: ///////////////////////////////////////////////////////// -class Fl_TriEvent : public Fl_SEvent -{ -public: - Fl_TriEvent(int x, int y, int w, int h, const char* label=0); - Fl_TriEvent(const Fl_TriEvent &Other); - virtual void draw(); -private: -}; - -///////////////////////////////////////////////////////// - class Fl_CircEvent : public Fl_SEvent { public: