Skip to content

Commit

Permalink
improved mixer and patches implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkOates committed Apr 14, 2015
1 parent 79344cd commit 0745a1f
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,29 @@ class GUIMixer : public FGUIFramedWindow
public:
int channel_num;
int patch;
Channel(int channel_num, int patch)
: channel_num(channel_num)
, patch(patch)
{}
};

private:

class GUIPatchTextInput : public FGUITextInput
{
public:
int channel_num;
GUIPatchTextInput(FGUIParent *parent, int channel_num, float x, float y)
: FGUITextInput(parent, af::fonts["DroidSans.ttf 16"], "0", x, y, 50, 30)
, channel_num(channel_num)
{}
void on_change() override
{
GUIMixer *mixer = static_cast<GUIMixer *>(parent);
mixer->channels[channel_num].patch = atoi(get_text().c_str());
}
};

std::vector<Channel> channels;
public:
GUIMixer(FGUIParent *parent, float x_, float y_, int num_channels=8)
Expand All @@ -35,8 +54,8 @@ class GUIMixer : public FGUIFramedWindow
{
this->set_title("Mixer & Channel Settings");

// create 16 channels
channels.resize(num_channels);
// create the channels
for (unsigned i=0; i<num_channels; i++) channels.push_back(Channel(i, 0));

// create the input boxes
float x = 150;
Expand All @@ -47,7 +66,7 @@ class GUIMixer : public FGUIFramedWindow
FGUIText *text = new FGUIText(this, x-10, y, af::fonts["DroidSans.ttf 16"], "Channel " + tostring(c+1));
text->place.align = vec2d(1, 1);

FGUITextInput *text_input = new FGUITextInput(this, af::fonts["DroidSans.ttf 16"], "0", x, y, 50, 30);
FGUITextInput *text_input = new GUIPatchTextInput(this, c, x, y);
text_input->place.align = vec2d(0, 1);
text_input->attr.set("select_all_on_focus", "true");

Expand All @@ -59,6 +78,11 @@ class GUIMixer : public FGUIFramedWindow
if (channels.empty() || channel_num < 0 || channel_num >= channels.size()) return NULL;
return &channels[channel_num];
}
int get_patch_num(int channel_num)
{
if (channels.empty() || channel_num < 0 || channel_num >= channels.size()) return 0;
return channels[channel_num].patch;
}
};


Expand Down Expand Up @@ -151,7 +175,7 @@ class Project : public FGUIScreen

simple_notification_screen->spawn_notification("Press F1 for help");

create_help_window();
// create_help_window();
}
void create_help_window()
{
Expand Down Expand Up @@ -205,6 +229,12 @@ class Project : public FGUIScreen
break;
case ALLEGRO_KEY_SPACE:
{
// send the patches before play
PlaybackDeviceInterface *device = score_editor->playback_control.playback_device;
for (unsigned i=0; i<score_editor->measure_grid.get_num_staves(); i++)
{
device->patch_change(i, gui_mixer->get_patch_num(i));
}
// toggle playback
score_editor->playback_control.toggle_playback();
}
Expand Down

0 comments on commit 0745a1f

Please sign in to comment.