From 6e5dd8c32a95e28dbad9a104f10e62fb69c20f05 Mon Sep 17 00:00:00 2001 From: edgeeffect Date: Sat, 15 Feb 2003 10:30:04 +0000 Subject: [PATCH] mixer - now has between 2 and 16 inputs not just 4 --- SpiralSound/Plugins/MixerPlugin/MixerPlugin.C | 136 +++++++++++------- SpiralSound/Plugins/MixerPlugin/MixerPlugin.h | 61 ++++---- .../Plugins/MixerPlugin/MixerPluginGUI.C | 136 ++++++++++++------ .../Plugins/MixerPlugin/MixerPluginGUI.h | 43 +++--- 4 files changed, 226 insertions(+), 150 deletions(-) diff --git a/SpiralSound/Plugins/MixerPlugin/MixerPlugin.C b/SpiralSound/Plugins/MixerPlugin/MixerPlugin.C index 5ca8dd9..d158e08 100644 --- a/SpiralSound/Plugins/MixerPlugin/MixerPlugin.C +++ b/SpiralSound/Plugins/MixerPlugin/MixerPlugin.C @@ -14,7 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ +*/ + +#include #include "MixerPlugin.h" #include "MixerPluginGUI.h" #include @@ -44,26 +46,17 @@ string GetGroupName() /////////////////////////////////////////////////////// -MixerPlugin::MixerPlugin() +MixerPlugin::MixerPlugin() : +m_NumChannels(0) { - m_PluginInfo.Name="Mixer"; - m_PluginInfo.Width=100; - m_PluginInfo.Height=125; - m_PluginInfo.NumInputs=4; - m_PluginInfo.NumOutputs=1; - m_PluginInfo.PortTips.push_back("Input one"); - m_PluginInfo.PortTips.push_back("Input two"); - m_PluginInfo.PortTips.push_back("Input three"); - m_PluginInfo.PortTips.push_back("Input four"); - m_PluginInfo.PortTips.push_back("Output"); - - for (int n=0; nRegister("Value",&m_GUIArgs.Value); - m_AudioCH->Register("Num",&m_GUIArgs.Num); + m_Version = 2; + m_PluginInfo.Name="Mixer"; + m_PluginInfo.Width=80; + m_PluginInfo.Height=145; + CreatePorts (); + for (int n=0; nRegister("Value", &m_GUIArgs.Value); + m_AudioCH->Register("Num", &m_GUIArgs.Num); } MixerPlugin::~MixerPlugin() @@ -71,7 +64,7 @@ MixerPlugin::~MixerPlugin() } PluginInfo &MixerPlugin::Initialise(const HostInfo *Host) -{ +{ return SpiralPlugin::Initialise(Host); } @@ -82,44 +75,77 @@ SpiralGUIType *MixerPlugin::CreateGUI() this,m_AudioCH,m_HostInfo); } -void MixerPlugin::Execute() -{ - // Mix the inputs - for (int n=0; nBUFSIZE; n++) - { - SetOutput(0,n,(GetInput(0,n)*m_ChannelVal[0])+ - (GetInput(1,n)*m_ChannelVal[1])+ - (GetInput(2,n)*m_ChannelVal[2])+ - (GetInput(3,n)*m_ChannelVal[3])); - } +void MixerPlugin::Execute () { + // Mix the inputs + for (int n=0; nBUFSIZE; n++) { + float out = 0.0; + for (int c=0; cIsCommandWaiting()) - { - switch (m_AudioCH->GetCommand()) - { - case (SETCH) : SetChannel(m_GUIArgs.Num,m_GUIArgs.Value); break; - } - } +void MixerPlugin::ExecuteCommands() { + if (m_AudioCH->IsCommandWaiting()) { + switch (m_AudioCH->GetCommand()) { + case SETCH: + SetChannel (m_GUIArgs.Num, m_GUIArgs.Value); + break; + case SETNUM: + SetChannels (m_GUIArgs.Num); + break; + } + } } -void MixerPlugin::StreamOut(ostream &s) -{ - s<>version; - for (int n=0; n>m_ChannelVal[n]; - } +void MixerPlugin::StreamIn (istream &s) { + int version, chans; + s >> version; + switch (version) { + case 1: SetChannels (4); + break; + case 2: s >> chans; + SetChannels (chans); + break; + } + for (int n=0; n> m_ChannelVal[n]; } diff --git a/SpiralSound/Plugins/MixerPlugin/MixerPlugin.h b/SpiralSound/Plugins/MixerPlugin/MixerPlugin.h index b60e972..78bb605 100644 --- a/SpiralSound/Plugins/MixerPlugin/MixerPlugin.h +++ b/SpiralSound/Plugins/MixerPlugin/MixerPlugin.h @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ +*/ #include "../SpiralPlugin.h" #include @@ -22,39 +22,34 @@ #ifndef MixerPLUGIN #define MixerPLUGIN -static const int NUM_CHANNELS = 4; +static const int MAX_CHANNELS = 16; -class MixerPlugin : public SpiralPlugin -{ -public: - MixerPlugin(); - virtual ~MixerPlugin(); - - virtual PluginInfo &Initialise(const HostInfo *Host); - virtual SpiralGUIType *CreateGUI(); - virtual void Execute(); - virtual void ExecuteCommands(); - virtual void StreamOut(ostream &s); - virtual void StreamIn(istream &s); - - // has to be defined in the plugin - virtual void UpdateGUI() { Fl::check(); } - - enum GUICommands{NONE,SETCH}; - struct GUIArgs - { - int Num; - float Value; - }; - - float GetChannel(int n) { return m_ChannelVal[n]; } - -private: - - GUIArgs m_GUIArgs; - - void SetChannel(int n, float s) { m_ChannelVal[n]=s; } - float m_ChannelVal[NUM_CHANNELS]; +class MixerPlugin : public SpiralPlugin { + public: + MixerPlugin(); + virtual ~MixerPlugin(); + virtual PluginInfo &Initialise(const HostInfo *Host); + virtual SpiralGUIType *CreateGUI(); + virtual void Execute(); + virtual void ExecuteCommands(); + virtual void StreamOut(ostream &s); + virtual void StreamIn(istream &s); + // has to be defined in the plugin + virtual void UpdateGUI() { Fl::check(); } + enum GUICommands { NONE, SETCH, SETNUM }; + struct GUIArgs { + int Num; + float Value; + }; + float GetChannel (int n) { return m_ChannelVal[n]; } + int GetChannels (void) { return m_NumChannels; } + private: + void CreatePorts (int n = 4, bool AddPorts = false); + GUIArgs m_GUIArgs; + int m_NumChannels; + void SetChannel (int n, float s) { m_ChannelVal[n]=s; } + void SetChannels (int n); + float m_ChannelVal[MAX_CHANNELS]; }; #endif diff --git a/SpiralSound/Plugins/MixerPlugin/MixerPluginGUI.C b/SpiralSound/Plugins/MixerPlugin/MixerPluginGUI.C index bf12943..b2d6f3c 100644 --- a/SpiralSound/Plugins/MixerPlugin/MixerPluginGUI.C +++ b/SpiralSound/Plugins/MixerPlugin/MixerPluginGUI.C @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ +*/ #include "MixerPluginGUI.h" #include @@ -28,51 +28,105 @@ static const int GUIBG2_COLOUR = 145; MixerPluginGUI::MixerPluginGUI(int w, int h,MixerPlugin *o,ChannelHandler *ch,const HostInfo *Info) : SpiralPluginGUI(w,h,o,ch) -{ - int Width=20; - int Height=100; - - for (int n=0; ntype(4); - m_Chan[n]->selection_color(GUI_COLOUR); - m_Chan[n]->labelsize(10); - m_Chan[n]->maximum(2); - m_Chan[n]->step(0.01); - m_Chan[n]->value(1.0); - m_Chan[n]->callback((Fl_Callback*)cb_Chan,(void*)&Numbers[n]); - add(m_Chan[n]); - } - - end(); +{ + for (int n=0; ntype (FL_HORIZONTAL); + add (m_MainPack); + + // start with four... + AddChan(); AddChan(); AddChan(); AddChan(); + + m_Buttons = new Fl_Pack (0, 122, 45, 20); + m_Buttons->type (FL_HORIZONTAL); + add (m_Buttons); + m_Delete = new Fl_Button (2, 0, 20, 20, "-"); + m_Delete->callback ((Fl_Callback*)cb_Delete); + m_Buttons->add (m_Delete); + m_Add = new Fl_Button (24, 0, 20, 20, "+"); + m_Add->callback ((Fl_Callback*)cb_Add); + m_Buttons->add (m_Add); } -void MixerPluginGUI::UpdateValues(SpiralPlugin *o) -{ - MixerPlugin *Plugin = (MixerPlugin *)o; - - for (int n=0; nvalue(2.0f-Plugin->GetChannel(n)); - } +void MixerPluginGUI::AddChan (bool SendData = false, bool ResizeIt = false) { + Fl_Slider *NewSlide = new Fl_Slider (0, 0, 20, 100, ""); + NewSlide->type (4); + NewSlide->selection_color (GUI_COLOUR); + NewSlide->labelsize (10); + NewSlide->maximum (2); + NewSlide->step (0.01); + NewSlide->value (1.0); + int num = (int)m_SlidVec.size(); + NewSlide->callback ((Fl_Callback*)cb_Chan, (void*)&Numbers[num]); + m_MainPack->add (NewSlide); + m_SlidVec.push_back (NewSlide); + if (ResizeIt) resize (x(), y(), w()+20, h()); + if (SendData) { + if (ResizeIt) redraw (); + m_GUICH->Set ("Num", ++num); + m_GUICH->SetCommand (MixerPlugin::SETNUM); + m_GUICH->Wait (); + m_GUICH->Set ("Num", num); + m_GUICH->Set ("Value", (float)(2.0f - NewSlide->value ())); + m_GUICH->SetCommand(MixerPlugin::SETCH); + } +} + +void MixerPluginGUI::DeleteChan (bool SendData = true, bool DrawIt = true) { + vector::iterator i = m_SlidVec.end (); + i--; + m_MainPack->remove (*i); + delete *i; + m_SlidVec.erase (i); + if (SendData) { + m_GUICH->Set ("Num", (int)m_SlidVec.size()); + m_GUICH->SetCommand (MixerPlugin::SETNUM); + } + resize (x(), y(), w()-20, h()); + if (DrawIt) redraw(); +} + +void MixerPluginGUI::UpdateValues(SpiralPlugin *o) { + MixerPlugin *Plugin = (MixerPlugin *)o; + unsigned int chans = Plugin->GetChannels(); + while (chans < m_SlidVec.size()) DeleteChan (false, false); + while (chans > m_SlidVec.size()) AddChan (false, true); + for (unsigned int n=0; nvalue (2.0f - Plugin->GetChannel (n)); + redraw(); +} + +inline void MixerPluginGUI::cb_Add_i(Fl_Button* o, void* v) { + if ((int)m_SlidVec.size() < MAX_CHANNELS) AddChan (true, true); } - -inline void MixerPluginGUI::cb_Chan_i(Fl_Slider* o, void* v) -{ - m_GUICH->Set("Num",(*(int*)(v))); - m_GUICH->Set("Value",(float)(2.0f-o->value())); - m_GUICH->SetCommand(MixerPlugin::SETCH); + +void MixerPluginGUI::cb_Add(Fl_Button* o, void* v) { + ((MixerPluginGUI*)(o->parent()->parent()))->cb_Add_i(o,v); } -void MixerPluginGUI::cb_Chan(Fl_Slider* o, void* v) -{ ((MixerPluginGUI*)(o->parent()))->cb_Chan_i(o,v);} +inline void MixerPluginGUI::cb_Delete_i(Fl_Button* o, void* v) { + if (m_SlidVec.size() > 2) DeleteChan (); +} + +void MixerPluginGUI::cb_Delete(Fl_Button* o, void* v) { + ((MixerPluginGUI*)(o->parent()->parent()))->cb_Delete_i(o,v); +} + +inline void MixerPluginGUI::cb_Chan_i(Fl_Slider* o, void* v) { + m_GUICH->Set("Num", (*(int*)(v))); + m_GUICH->Set("Value", (float)(2.0f-o->value())); + m_GUICH->SetCommand (MixerPlugin::SETCH); +} + +void MixerPluginGUI::cb_Chan(Fl_Slider* o, void* v) { + ((MixerPluginGUI*)(o->parent()->parent()))->cb_Chan_i(o,v); +} const string MixerPluginGUI::GetHelpText(const string &loc){ - return string("") - + "A general purpose 4 channel mixer, not much else to say\n" - + "really. Useful for mixing CV values as well as mono audio\n" - + "signals. \n"; + return string("") + + "A general purpose mixer, not much else to say really.\n" + + "Useful for mixing CV values as well as mono audio\n" + + "signals.\n" + + "Add up to 16 channels using the '+' button.\n" + + "Use the '-' button to remove unwanted channels.\n"; } diff --git a/SpiralSound/Plugins/MixerPlugin/MixerPluginGUI.h b/SpiralSound/Plugins/MixerPlugin/MixerPluginGUI.h index cbbbd27..dde5127 100644 --- a/SpiralSound/Plugins/MixerPlugin/MixerPluginGUI.h +++ b/SpiralSound/Plugins/MixerPlugin/MixerPluginGUI.h @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ +*/ #include #include #include +#include #include #include "MixerPlugin.h" @@ -27,27 +28,27 @@ #ifndef MixerGUI #define MixerGUI +static int Numbers[MAX_CHANNELS]; -class MixerPluginGUI : public SpiralPluginGUI -{ -public: - MixerPluginGUI(int w, int h, MixerPlugin *o,ChannelHandler *ch,const HostInfo *Info); - - virtual void UpdateValues(SpiralPlugin *o); - -protected: - const string GetHelpText(const string &loc); - -private: - - int Numbers[NUM_CHANNELS]; - - Fl_Slider* m_Chan[NUM_CHANNELS]; - - //// Callbacks //// - inline void cb_Chan_i(Fl_Slider* o, void* v); - static void cb_Chan(Fl_Slider* o, void* v); - +class MixerPluginGUI : public SpiralPluginGUI { + public: + MixerPluginGUI(int w, int h, MixerPlugin *o,ChannelHandler *ch,const HostInfo *Info); + virtual void UpdateValues(SpiralPlugin *o); + protected: + const string GetHelpText(const string &loc); + private: + void AddChan (bool SendData = false, bool ResizeIt = false); + void DeleteChan (bool SendData = true, bool DrawIt = true); + vector m_SlidVec; + Fl_Pack *m_MainPack, *m_Buttons; + Fl_Button *m_Add, *m_Delete; + //// Callbacks //// + inline void cb_Chan_i (Fl_Slider* o, void* v); + static void cb_Chan (Fl_Slider* o, void* v); + inline void cb_Add_i (Fl_Button* o, void* v); + static void cb_Add (Fl_Button* o, void* v); + inline void cb_Delete_i (Fl_Button* o, void* v); + static void cb_Delete (Fl_Button* o, void* v); }; #endif