@@ -14,7 +14,9 @@ | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | ||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
*/ | |||||
*/ | |||||
#include <stdio.h> | |||||
#include "MixerPlugin.h" | #include "MixerPlugin.h" | ||||
#include "MixerPluginGUI.h" | #include "MixerPluginGUI.h" | ||||
#include <FL/Fl_Button.h> | #include <FL/Fl_Button.h> | ||||
@@ -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; n<NUM_CHANNELS; n++) | |||||
{ | |||||
m_ChannelVal[n]=1.0f; | |||||
} | |||||
m_AudioCH->Register("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; n<MAX_CHANNELS; n++) m_ChannelVal[n]=1.0f; | |||||
m_AudioCH->Register("Value", &m_GUIArgs.Value); | |||||
m_AudioCH->Register("Num", &m_GUIArgs.Num); | |||||
} | } | ||||
MixerPlugin::~MixerPlugin() | MixerPlugin::~MixerPlugin() | ||||
@@ -71,7 +64,7 @@ MixerPlugin::~MixerPlugin() | |||||
} | } | ||||
PluginInfo &MixerPlugin::Initialise(const HostInfo *Host) | PluginInfo &MixerPlugin::Initialise(const HostInfo *Host) | ||||
{ | |||||
{ | |||||
return SpiralPlugin::Initialise(Host); | return SpiralPlugin::Initialise(Host); | ||||
} | } | ||||
@@ -82,44 +75,77 @@ SpiralGUIType *MixerPlugin::CreateGUI() | |||||
this,m_AudioCH,m_HostInfo); | this,m_AudioCH,m_HostInfo); | ||||
} | } | ||||
void MixerPlugin::Execute() | |||||
{ | |||||
// Mix the inputs | |||||
for (int n=0; n<m_HostInfo->BUFSIZE; 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; n<m_HostInfo->BUFSIZE; n++) { | |||||
float out = 0.0; | |||||
for (int c=0; c<m_NumChannels; c++) out += (GetInput (c, n) * m_ChannelVal[c]); | |||||
SetOutput (0, n, out); | |||||
} | |||||
} | } | ||||
void MixerPlugin::ExecuteCommands() | |||||
{ | |||||
if (m_AudioCH->IsCommandWaiting()) | |||||
{ | |||||
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<<m_Version<<" "; | |||||
for (int n=0; n<NUM_CHANNELS; n++) | |||||
{ | |||||
s<<m_ChannelVal[n]<<" "; | |||||
} | |||||
void MixerPlugin::SetChannels (int n) { | |||||
// once to clear the connections with the current info | |||||
// do we need this???? | |||||
UpdatePluginInfoWithHost(); | |||||
// Things can get a bit confused deleting and adding inputs | |||||
// so we just chuck away all the ports... | |||||
RemoveAllInputs (); | |||||
RemoveAllOutputs (); | |||||
m_PluginInfo.NumInputs = 0; | |||||
m_PluginInfo.NumOutputs = 0; | |||||
m_PluginInfo.PortTips.clear (); | |||||
// ... and then create some new ones | |||||
CreatePorts (n, true); | |||||
// do the actual update | |||||
UpdatePluginInfoWithHost (); | |||||
} | |||||
void MixerPlugin::CreatePorts (int n, bool AddPorts) { | |||||
int c; | |||||
m_PluginInfo.NumInputs = n; | |||||
m_NumChannels = n; | |||||
char t[256]; | |||||
for (c=1; c<=n; c++) { | |||||
sprintf (t, "Input %d", c); | |||||
m_PluginInfo.PortTips.push_back (t); | |||||
} | |||||
m_PluginInfo.NumOutputs = 1; | |||||
m_PluginInfo.PortTips.push_back ("Output"); | |||||
if (AddPorts) { | |||||
for (c=0; c<m_PluginInfo.NumInputs; c++) AddInput(); | |||||
for (c=0; c<m_PluginInfo.NumOutputs; c++) AddOutput(); | |||||
} | |||||
} | |||||
void MixerPlugin::StreamOut (ostream &s) { | |||||
s << m_Version << " "; | |||||
s << m_NumChannels << " "; | |||||
for (int n=0; n<m_NumChannels; n++) s << m_ChannelVal[n] << " "; | |||||
} | } | ||||
void MixerPlugin::StreamIn(istream &s) | |||||
{ | |||||
int version; | |||||
s>>version; | |||||
for (int n=0; n<NUM_CHANNELS; n++) | |||||
{ | |||||
s>>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_NumChannels; n++) s >> m_ChannelVal[n]; | |||||
} | } |
@@ -14,7 +14,7 @@ | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | ||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
*/ | |||||
*/ | |||||
#include "../SpiralPlugin.h" | #include "../SpiralPlugin.h" | ||||
#include <FL/Fl_Pixmap.H> | #include <FL/Fl_Pixmap.H> | ||||
@@ -22,39 +22,34 @@ | |||||
#ifndef MixerPLUGIN | #ifndef MixerPLUGIN | ||||
#define 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 | #endif |
@@ -14,7 +14,7 @@ | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | ||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
*/ | |||||
*/ | |||||
#include "MixerPluginGUI.h" | #include "MixerPluginGUI.h" | ||||
#include <FL/fl_draw.h> | #include <FL/fl_draw.h> | ||||
@@ -28,51 +28,105 @@ static const int GUIBG2_COLOUR = 145; | |||||
MixerPluginGUI::MixerPluginGUI(int w, int h,MixerPlugin *o,ChannelHandler *ch,const HostInfo *Info) : | MixerPluginGUI::MixerPluginGUI(int w, int h,MixerPlugin *o,ChannelHandler *ch,const HostInfo *Info) : | ||||
SpiralPluginGUI(w,h,o,ch) | SpiralPluginGUI(w,h,o,ch) | ||||
{ | |||||
int Width=20; | |||||
int Height=100; | |||||
for (int n=0; n<NUM_CHANNELS; n++) | |||||
{ | |||||
Numbers[n]=n; | |||||
m_Chan[n] = new Fl_Slider(10+(2+Width)*n, 22, Width, Height, ""); | |||||
m_Chan[n]->type(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; n<MAX_CHANNELS; n++) Numbers[n]=n; | |||||
m_MainPack = new Fl_Pack(0, 20, w, 100); | |||||
m_MainPack->type (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; n<NUM_CHANNELS; n++) | |||||
{ | |||||
m_Chan[n]->value(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<Fl_Slider*>::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; n<chans; n++) | |||||
m_SlidVec[n]->value (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){ | 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"; | |||||
} | } |
@@ -14,11 +14,12 @@ | |||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with this program; if not, write to the Free Software | * along with this program; if not, write to the Free Software | ||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
*/ | |||||
*/ | |||||
#include <FL/Fl.H> | #include <FL/Fl.H> | ||||
#include <FL/Fl_Window.H> | #include <FL/Fl_Window.H> | ||||
#include <FL/Fl_Group.H> | #include <FL/Fl_Group.H> | ||||
#include <FL/Fl_Pack.H> | |||||
#include <FL/Fl_Slider.H> | #include <FL/Fl_Slider.H> | ||||
#include "MixerPlugin.h" | #include "MixerPlugin.h" | ||||
@@ -27,27 +28,27 @@ | |||||
#ifndef MixerGUI | #ifndef MixerGUI | ||||
#define 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<Fl_Slider*> 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 | #endif |