diff --git a/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPlugin.C b/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPlugin.C index 79743d5..ec5fab5 100644 --- a/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPlugin.C +++ b/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPlugin.C @@ -40,15 +40,23 @@ int GetID() /////////////////////////////////////////////////////// -NoteSnapPlugin::NoteSnapPlugin() +NoteSnapPlugin::NoteSnapPlugin() : +m_Out(0) { m_PluginInfo.Name="Note Snap"; - m_PluginInfo.Width=220; - m_PluginInfo.Height=125; + m_PluginInfo.Width=90; + m_PluginInfo.Height=80; m_PluginInfo.NumInputs=1; m_PluginInfo.NumOutputs=1; m_PluginInfo.PortTips.push_back("Input"); m_PluginInfo.PortTips.push_back("Output"); + + for (int n=0; n<12; n++) + { + m_Filter[n]=true; + } + + m_AudioCH->Register("Note",&m_Note); } NoteSnapPlugin::~NoteSnapPlugin() @@ -62,13 +70,14 @@ PluginInfo &NoteSnapPlugin::Initialise(const HostInfo *Host) SpiralGUIType *NoteSnapPlugin::CreateGUI() { - return NULL; + return new NoteSnapPluginGUI(m_PluginInfo.Width, + m_PluginInfo.Height, + this,m_AudioCH,m_HostInfo); } void NoteSnapPlugin::Execute() { float Freq=0, OldFreq=0; - float Out=0; for (int n=0; nBUFSIZE; n++) { @@ -78,42 +87,46 @@ void NoteSnapPlugin::Execute() { for (int i=0; i<131; i++) // for every note { - if (Freq>=NoteTable[i] && Freq=NoteTable[i] && FreqInitialise(&host); - test->CreateGUI(); - - for (;;) + if (m_AudioCH->IsCommandWaiting()) { - if (!Fl::check()) break; - test->Execute(); - } - - delete test; + switch (m_AudioCH->GetCommand()) + { + case NOTE_ON : m_Filter[m_Note]=true; break; + case NOTE_OFF : m_Filter[m_Note]=false; break; + } + } +} - return 1; +void NoteSnapPlugin::StreamOut(ostream &s) +{ + s<>version; + for (int n=0; n<12; n++) + { + s>>m_Filter[n]; + } } diff --git a/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPlugin.h b/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPlugin.h index c465e1b..be2382c 100644 --- a/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPlugin.h +++ b/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPlugin.h @@ -31,10 +31,19 @@ public: virtual PluginInfo& Initialise(const HostInfo *Host); virtual SpiralGUIType* CreateGUI(); virtual void Execute(); - virtual void StreamOut(ostream &s) {} - virtual void StreamIn(istream &s) {} + virtual void ExecuteCommands(); + virtual void StreamOut(ostream &s); + virtual void StreamIn(istream &s); + + bool GetFilter(int n) { return m_Filter[n]; } + + enum GUICommands{NONE,NOTE_ON,NOTE_OFF}; private: + + int m_Note; + bool m_Filter[12]; + float m_Out; }; #endif diff --git a/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPluginGUI.C b/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPluginGUI.C index 6014517..3737f05 100644 --- a/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPluginGUI.C +++ b/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPluginGUI.C @@ -29,6 +29,53 @@ static const int GUIBG2_COLOUR = 145; NoteSnapPluginGUI::NoteSnapPluginGUI(int w, int h,NoteSnapPlugin *o,ChannelHandler *ch,const HostInfo *Info) : SpiralPluginGUI(w,h,o,ch) { + int KeyWidth=10,Note,Pos=0,Count=0; + + for (int n=0; ntype(1); + m_Key[n]->selection_color(FL_RED); + m_Key[n]->box(FL_THIN_UP_BOX); + m_Key[n]->labelsize(10); + m_Key[n]->when(FL_WHEN_CHANGED); + + m_Key[n]->color(FL_WHITE); + m_Key[n]->callback((Fl_Callback*)cb_Key, &m_Num[n]); + add(m_Key[n]); + } + } + + Count=0; + for (int n=0; ntype(1); + m_Key[n]->selection_color(FL_RED); + m_Key[n]->box(FL_THIN_UP_BOX); + m_Key[n]->labelsize(10); + m_Key[n]->when(FL_WHEN_CHANGED); + m_Key[n]->color(FL_BLACK); + m_Key[n]->callback((Fl_Callback*)cb_Key, &m_Num[n]); + add(m_Key[n]); + } + else + { + Count++; + Pos=Count*KeyWidth; + } + } + end(); } @@ -36,10 +83,36 @@ SpiralPluginGUI(w,h,o,ch) void NoteSnapPluginGUI::UpdateValues(SpiralPlugin *o) { + NoteSnapPlugin *Plugin = (NoteSnapPlugin *)o; + for (int n=0; n<12; n++) + { + m_Key[n]->value(!Plugin->GetFilter(n)); + } +} + +//// Callbacks //// +inline void NoteSnapPluginGUI::cb_Key_i(Fl_Button* o, void* v) +{ + int k=*(int*)(v); + if (o->value()) + { + m_GUICH->Set("Note",k); + m_GUICH->SetCommand(NoteSnapPlugin::NOTE_OFF); + } + else + { + m_GUICH->Set("Note",k); + m_GUICH->SetCommand(NoteSnapPlugin::NOTE_ON); + } + parent()->redraw(); } +void NoteSnapPluginGUI::cb_Key(Fl_Button* o, void* v) +{ ((NoteSnapPluginGUI*)(o->parent()))->cb_Key_i(o,v);} const string NoteSnapPluginGUI::GetHelpText(const string &loc){ return string("") + "Quantises the input value into a note frequency\n" - + "(using the midi note data).\n"; + + "(using the midi note data).\n" + + "Use the keyboard to select notes to be filtered out\n" + + "for generating scales and chords"; } diff --git a/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPluginGUI.h b/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPluginGUI.h index 0531530..581aff0 100644 --- a/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPluginGUI.h +++ b/SpiralSound/Plugins/NoteSnapPlugin/NoteSnapPluginGUI.h @@ -29,7 +29,7 @@ #ifndef SplitterGUI #define SplitterGUI - +static const int NUM_KEYS = 12; class NoteSnapPluginGUI : public SpiralPluginGUI { public: @@ -41,8 +41,12 @@ protected: const string GetHelpText(const string &loc); private: - + int m_Num[NUM_KEYS]; + Fl_Button* m_Key[NUM_KEYS]; + //// Callbacks //// + inline void cb_Key_i(Fl_Button* o, void* v); + static void cb_Key(Fl_Button* o, void* v); }; #endif