Browse Source

Add Distributer GUI with the ability to change number of channels,

fix Distributer save/version information
Add Reset CV to Distributer to reset to first channel to eg. keep in sync with a matrix
master
aj_genius 21 years ago
parent
commit
5dfbb982c9
4 changed files with 229 additions and 49 deletions
  1. +156
    -37
      SpiralSound/Plugins/DistributorPlugin/DistributorPlugin.C
  2. +29
    -11
      SpiralSound/Plugins/DistributorPlugin/DistributorPlugin.h
  3. +35
    -0
      SpiralSound/Plugins/DistributorPlugin/DistributorPluginGUI.C
  4. +9
    -1
      SpiralSound/Plugins/DistributorPlugin/DistributorPluginGUI.h

+ 156
- 37
SpiralSound/Plugins/DistributorPlugin/DistributorPlugin.C View File

@@ -44,58 +44,177 @@ string SpiralPlugin_GetGroupName() {

///////////////////////////////////////////////////////

DistributorPlugin::DistributorPlugin() :
DistributorPlugin::DistributorPlugin():
m_Triggered (false),
m_ChannelSelect (0),
m_TrigDelay (0)
{

m_PluginInfo.Name = "Distributor";
m_PluginInfo.Width = 220;
m_PluginInfo.Height = 250;
m_PluginInfo.NumInputs = 2;
m_PluginInfo.NumOutputs = 8;
m_PluginInfo.Width=80;
m_PluginInfo.Height=40;

m_Version = 2;
m_GUIArgs.ChannelCount = 2;
CreatePorts ();

m_AudioCH->Register("ChannelCount", &m_GUIArgs.ChannelCount);
}

DistributorPlugin::~DistributorPlugin()
{
}

void DistributorPlugin::CreatePorts (int n, bool AddPorts)
{
int c;
char t[256];
m_PluginInfo.NumInputs = 3;
m_PluginInfo.PortTips.push_back ("Stream");
m_PluginInfo.PortTips.push_back ("Switcher");
m_PluginInfo.PortTips.push_back ("Stream 1");
m_PluginInfo.PortTips.push_back ("Switcher 1");
m_PluginInfo.PortTips.push_back ("Stream 2");
m_PluginInfo.PortTips.push_back ("Switcher 2");
m_PluginInfo.PortTips.push_back ("Stream 3");
m_PluginInfo.PortTips.push_back ("Switcher 3");
m_PluginInfo.PortTips.push_back ("Stream 4");
m_PluginInfo.PortTips.push_back ("Switcher 4");
m_PluginInfo.PortTips.push_back ("Reset CV");

m_PluginInfo.NumOutputs = n*2;
for (c=1; c<=n; c++) {
sprintf (t, "Stream %d", c);
m_PluginInfo.PortTips.push_back (t);

sprintf (t, "Switcher %d", c);
m_PluginInfo.PortTips.push_back (t);
}

if (AddPorts) {
for (int c=0; c<m_PluginInfo.NumInputs; c++) AddInput();
for (int c=0; c<m_PluginInfo.NumOutputs; c++) AddOutput();
}
}

DistributorPlugin::~DistributorPlugin() {
void DistributorPlugin::SetChannelCount (int count)
{
m_GUIArgs.ChannelCount = count;

UpdatePluginInfoWithHost();

RemoveAllInputs ();
RemoveAllOutputs ();
m_PluginInfo.NumInputs = 0;
m_PluginInfo.NumOutputs = 0;
m_PluginInfo.PortTips.clear ();

CreatePorts (count, true);
UpdatePluginInfoWithHost ();
}

PluginInfo &DistributorPlugin::Initialise (const HostInfo *Host) {

PluginInfo &DistributorPlugin::Initialise (const HostInfo *Host)
{
return SpiralPlugin::Initialise (Host);
}

SpiralGUIType *DistributorPlugin::CreateGUI() {
return NULL;
SpiralGUIType *DistributorPlugin::CreateGUI()
{
return new DistributorPluginGUI (m_PluginInfo.Width, m_PluginInfo.Height, this, m_AudioCH, m_HostInfo);
}

void DistributorPlugin::Execute() {
const int Stream = 0;
const int Switch = 1;
for (int n=0; n<m_HostInfo->BUFSIZE; n++) {
float InpStream = InputExists (Stream) ? GetInput (Stream, n) : 0.0;
float InpSwitch = InputExists (Switch) ? GetInput (Switch, n) : 0.0;
if (InpSwitch <= 0.0) m_Triggered = false;
if (! m_Triggered && (InpSwitch > 0.0)) {
m_Triggered = true;
SetOutput (m_ChannelSelect+Switch, n, 0);
m_ChannelSelect = m_ChannelSelect + 2;
if (m_ChannelSelect > 6) m_ChannelSelect = 0;
m_TrigDelay = 0;
}
SetOutput (m_ChannelSelect+Stream, n, InpStream);
if (m_TrigDelay < 10) {
m_TrigDelay++;
SetOutput (m_ChannelSelect+Switch, n, InpSwitch);
}
else SetOutput (m_ChannelSelect+Switch, n, 0);
}
const int Stream = 0;
const int Switch = 1;
const int Reset = 2;

for (int n=0; n<m_HostInfo->BUFSIZE; n++) {
float InpStream = InputExists (Stream) ? GetInput (Stream, n) : 0.0;
float InpSwitch = InputExists (Switch) ? GetInput (Switch, n) : 0.0;
float InpReset = InputExists (Reset) ? GetInput (Reset, n) : 0;
if (InpReset)
{
m_Triggered = false;
m_ChannelSelect = false;
m_TrigDelay = 0;
}

if (InpSwitch <= 0.0)
m_Triggered = false;

if (! m_Triggered && (InpSwitch > 0.0))
{
m_Triggered = true;
SetOutput (m_ChannelSelect+Switch, n, 0);
m_ChannelSelect = m_ChannelSelect + 2;
if (m_ChannelSelect >= (GetChannelCount()*2))
m_ChannelSelect = 0;
m_TrigDelay = 0;
}
SetOutput (m_ChannelSelect+Stream, n, InpStream);

if (m_TrigDelay < 10)
{
m_TrigDelay++;
SetOutput (m_ChannelSelect+Switch, n, InpSwitch);
}
else
{
SetOutput (m_ChannelSelect+Switch, n, 0);
}
}
}

void DistributorPlugin::ExecuteCommands ()
{
if (m_AudioCH->IsCommandWaiting ())
{
switch (m_AudioCH->GetCommand()) {
case SETCHANNELCOUNT :
{
SetChannelCount(GetChannelCount());
}
break;
}
}
}

void DistributorPlugin::StreamOut (ostream &s)
{
s << m_Version << " " << GetChannelCount() << " ";
}

void DistributorPlugin::StreamIn (istream &s)
{
char Test;
int Version, Channels;

s.seekg (2, ios_base::cur );//skip to next line
Test = s.peek();//peek first char
s.seekg (-2, ios_base::cur );//jump back to prior line
if ( (Test >= '0') && (Test <= '9') )
{
s >> Version;
}
else
{
//No Version, so use Version 1
Version = 1;
}
switch (Version)
{
case 2:
{
s >> Channels;
SetChannelCount (Channels);
}
break;
case 1:
{
//use original fixed defaults
SetChannelCount (4);
}
break;
}
}

+ 29
- 11
SpiralSound/Plugins/DistributorPlugin/DistributorPlugin.h View File

@@ -23,17 +23,35 @@
#include <FL/Fl_Pixmap.H>

class DistributorPlugin : public SpiralPlugin {
public:
DistributorPlugin();
virtual ~DistributorPlugin();
virtual PluginInfo& Initialise (const HostInfo *Host);
virtual SpiralGUIType* CreateGUI();
virtual void Execute();
virtual void StreamOut (std::ostream &s) { }
virtual void StreamIn (std::istream &s) { }
private:
bool m_Triggered;
int m_ChannelSelect, m_TrigDelay;
public:
DistributorPlugin();
virtual ~DistributorPlugin();

virtual PluginInfo& Initialise(const HostInfo *Host);
virtual SpiralGUIType* CreateGUI ();
virtual void Execute();
virtual void ExecuteCommands();
virtual void StreamOut(std::ostream &s);
virtual void StreamIn(std::istream &s);
int GetChannelCount (void) { return m_GUIArgs.ChannelCount; }
void SetChannelCount (int count);

enum GUICommands { NONE, SETCHANNELCOUNT };
struct GUIArgs {
int ChannelCount;
};
private:
GUIArgs m_GUIArgs;

int m_Version;

bool m_Triggered;
int m_ChannelSelect, m_TrigDelay;

void CreatePorts (int n = 2, bool AddPorts = false);
};

#endif


+ 35
- 0
SpiralSound/Plugins/DistributorPlugin/DistributorPluginGUI.C View File

@@ -27,13 +27,48 @@ using namespace std;
DistributorPluginGUI::DistributorPluginGUI(int w, int h,DistributorPlugin *o,ChannelHandler *ch,const HostInfo *Info) :
SpiralPluginGUI(w,h,o,ch)
{
m_Chans = new Fl_Counter (15, 20, 50, 15, "Channels");
m_Chans->labelsize (8);
m_Chans->textsize (8);
m_Chans->type (FL_SIMPLE_COUNTER);
m_Chans->box (FL_PLASTIC_UP_BOX);
m_Chans->color (Info->GUI_COLOUR);
m_Chans->selection_color (Info->GUI_COLOUR);
m_Chans->step (1);
m_Chans->value (2);
m_Chans->callback ((Fl_Callback*) cb_Chans, this);
add (m_Chans);

end();
}


void DistributorPluginGUI::Update()
{
}

void DistributorPluginGUI::UpdateValues(SpiralPlugin *o)
{
DistributorPlugin* Plugin = (DistributorPlugin*)o;
m_Chans->value (Plugin->GetChannelCount());
}
inline void DistributorPluginGUI::cb_Chans_i (Fl_Counter* o)
{
if (o->value() < 2)
{
o->value(2);
}
else {
m_GUICH->Set ("ChannelCount", int (o->value ()));
m_GUICH->SetCommand (DistributorPlugin::SETCHANNELCOUNT);
m_GUICH->Wait ();
Resize (w(), h());
}
}

const string DistributorPluginGUI::GetHelpText(const string &loc)
{
return string("")
+ "The Distributor plugin is for polyphony. NEED MORE INFO HERE.\n";
}

+ 9
- 1
SpiralSound/Plugins/DistributorPlugin/DistributorPluginGUI.h View File

@@ -17,6 +17,7 @@
*/

#include <FL/Fl.H>
#include <FL/Fl_Counter.H>
#include "DistributorPlugin.h"
#include "../SpiralPluginGUI.h"

@@ -27,11 +28,18 @@ class DistributorPluginGUI : public SpiralPluginGUI
{
public:
DistributorPluginGUI(int w, int h, DistributorPlugin *o,ChannelHandler *ch,const HostInfo *Info);
virtual void UpdateValues(SpiralPlugin *o);
virtual void Update ();

protected:
const std::string GetHelpText(const std::string &loc);

private:
Fl_Counter *m_Chans;

//// Callbacks ////
inline void cb_Chans_i (Fl_Counter* o);
static void cb_Chans(Fl_Counter* o, DistributorPluginGUI* v) {v->cb_Chans_i(o);}
};

#endif


Loading…
Cancel
Save