| @@ -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; n<m_HostInfo->BUFSIZE; 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+1]) | |||
| if (m_Filter[(i+1)%12] && Freq>=NoteTable[i] && Freq<NoteTable[i+1]) | |||
| { | |||
| Out=NoteTable[i]; | |||
| m_Out=NoteTable[i]; | |||
| } | |||
| } | |||
| } | |||
| OldFreq=Freq; | |||
| SetOutputPitch(0,n,Out); | |||
| SetOutputPitch(0,n,m_Out); | |||
| } | |||
| } | |||
| int main() | |||
| void NoteSnapPlugin::ExecuteCommands() | |||
| { | |||
| Fl::visual(FL_DOUBLE|FL_RGB); | |||
| HostInfo host; | |||
| host.BUFSIZE=256; | |||
| host.SAMPLERATE=44100; | |||
| host.OUTPUTFILE="/dev/dsp"; | |||
| host.MIDIFILE="/dev/midi"; | |||
| host.POLY=1; | |||
| host.GUI_COLOUR=100; | |||
| SpiralPlugin* test = CreateInstance(); | |||
| test->Initialise(&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<<m_Version<<endl; | |||
| for (int n=0; n<12; n++) | |||
| { | |||
| s<<m_Filter[n]<<" "; | |||
| } | |||
| } | |||
| void NoteSnapPlugin::StreamIn(istream &s) | |||
| { | |||
| int version; | |||
| s>>version; | |||
| for (int n=0; n<12; n++) | |||
| { | |||
| s>>m_Filter[n]; | |||
| } | |||
| } | |||
| @@ -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 | |||
| @@ -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; n<NUM_KEYS; n++) | |||
| { | |||
| m_Num[n]=n; | |||
| Note = n%12; | |||
| if (Note!=1 && Note!=3 && Note!=6 && Note!=8 && Note!=10) | |||
| { | |||
| Count++; | |||
| Pos=Count*KeyWidth; | |||
| m_Key[n] = new Fl_Button(Pos,20,KeyWidth,50,""); | |||
| m_Key[n]->type(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; n<NUM_KEYS; n++) | |||
| { | |||
| Note = n%12; | |||
| if (Note==1 || Note==3 || Note==6 || Note==8 || Note==10) | |||
| { | |||
| m_Key[n] = new Fl_Button(Pos+5,20,KeyWidth,30,""); | |||
| m_Key[n]->type(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"; | |||
| } | |||
| @@ -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 | |||