Skip to content

Commit

Permalink
Ability to add new Channel Groups via UI
Browse files Browse the repository at this point in the history
  • Loading branch information
gvnnz committed May 25, 2024
1 parent dce5246 commit 589f134
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 12 deletions.
10 changes: 7 additions & 3 deletions src/glue/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Data::Data(const m::Channel& c, int columnIndex, int position)
, pan(c.pan)
, key(c.key)
, hasActions(c.hasActions)
, grouped(c.isGrouped())
, m_playStatus(&c.shared->playStatus)
, m_recStatus(&c.shared->recStatus)
, m_readActions(&c.shared->readActions)
Expand Down Expand Up @@ -180,10 +181,13 @@ void loadChannel(ID channelId, const std::string& fname)

/* -------------------------------------------------------------------------- */

void addChannel(int columnIndex, ChannelType type)
void addChannel(int columnIndex, ChannelType type, ID groupChannelId)
{
const m::Channel& ch = g_engine->getChannelsApi().add(type, /*groupChannelId=*/0);
g_ui->model.addChannelToColumn(ch.id, columnIndex);
const m::Channel& ch = g_engine->getChannelsApi().add(type, groupChannelId);
if (groupChannelId > 0)
g_ui->model.columns.addChannelToGroup(ch.id, groupChannelId);
else
g_ui->model.columns.addChannelToColumn(ch.id, columnIndex);
}

/* -------------------------------------------------------------------------- */
Expand Down
6 changes: 4 additions & 2 deletions src/glue/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct Data
float pan;
int key;
bool hasActions;
bool grouped;

std::optional<SampleData> sample;
std::optional<MidiData> midi;
Expand Down Expand Up @@ -133,9 +134,10 @@ described by Model::columns. */
std::vector<Column> getColumns();

/* addChannel
Adds an empty new channel to the stack. */
Adds an empty new channel to the stack. Pass groupChannelId > 0 to add it to
a Group Channel. */

void addChannel(int columnIndex, ChannelType type);
void addChannel(int columnIndex, ChannelType type, ID groupChannelId);

/* loadChannel
Fills an existing channel with a wave. */
Expand Down
26 changes: 21 additions & 5 deletions src/gui/elems/mainWindow/keyboard/column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "gui/elems/basics/menu.h"
#include "gui/elems/basics/resizerBar.h"
#include "gui/elems/basics/textButton.h"
#include "gui/elems/mainWindow/keyboard/groupChannel.h"
#include "gui/elems/mainWindow/keyboard/keyboard.h"
#include "gui/elems/mainWindow/keyboard/midiChannel.h"
#include "gui/elems/mainWindow/keyboard/sampleChannel.h"
Expand All @@ -52,6 +53,7 @@ enum class Menu
{
ADD_SAMPLE_CHANNEL = 0,
ADD_MIDI_CHANNEL,
ADD_GROUP_CHANNEL,
ADD_COLUMN,
REMOVE_COLUMN,
};
Expand All @@ -60,9 +62,18 @@ enum class Menu

geChannel* makeChannel_(const c::channel::Data& data)
{
if (data.type == ChannelType::SAMPLE)
switch (data.type)
{
case ChannelType::SAMPLE:
return new geSampleChannel(0, 0, 0, 0, data);
return new geMidiChannel(0, 0, 0, 0, data);
case ChannelType::MIDI:
return new geMidiChannel(0, 0, 0, 0, data);
case ChannelType::GROUP:
return new geGroupChannel(data);
default:
assert(false);
return nullptr;
}
}
} // namespace

Expand Down Expand Up @@ -113,6 +124,7 @@ void geColumn::showAddChannelMenu() const

menu.addItem((ID)Menu::ADD_SAMPLE_CHANNEL, g_ui->getI18Text(LangMap::MAIN_COLUMN_BUTTON_ADDSAMPLECHANNEL));
menu.addItem((ID)Menu::ADD_MIDI_CHANNEL, g_ui->getI18Text(LangMap::MAIN_COLUMN_BUTTON_ADDMIDICHANNEL));
menu.addItem((ID)Menu::ADD_GROUP_CHANNEL, "Add group channel"); // TODO add label
menu.addItem((ID)Menu::ADD_COLUMN, g_ui->getI18Text(LangMap::MAIN_COLUMN_BUTTON_ADD_COLUMN));
menu.addItem((ID)Menu::REMOVE_COLUMN, g_ui->getI18Text(LangMap::MAIN_COLUMN_BUTTON_REMOVE_COLUMN));

Expand All @@ -121,14 +133,18 @@ void geColumn::showAddChannelMenu() const
if (countChannels() > 0 || keyboard->countColumns() == 1)
menu.setEnabled((ID)Menu::REMOVE_COLUMN, false);

menu.onSelect = [this, keyboard](ID menuId) {
menu.onSelect = [this, keyboard](ID menuId)
{
switch (static_cast<Menu>(menuId))
{
case Menu::ADD_SAMPLE_CHANNEL:
c::channel::addChannel(index, ChannelType::SAMPLE);
c::channel::addChannel(index, ChannelType::SAMPLE, /*groupChannelId=*/0);
break;
case Menu::ADD_MIDI_CHANNEL:
c::channel::addChannel(index, ChannelType::MIDI);
c::channel::addChannel(index, ChannelType::MIDI, /*groupChannelId=*/0);
break;
case Menu::ADD_GROUP_CHANNEL:
c::channel::addChannel(index, ChannelType::GROUP, /*groupChannelId=*/0);
break;
case Menu::REMOVE_COLUMN:
keyboard->deleteColumn(index);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/elems/mainWindow/keyboard/groupChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ void geGroupChannel::openMenu()
switch (static_cast<Menu>(id))
{
case Menu::ADD_SAMPLE_CHANNEL:
c::channel::addChannel(data.columnIndex, ChannelType::SAMPLE);
c::channel::addChannel(data.columnIndex, ChannelType::SAMPLE, data.id);
break;
case Menu::ADD_MIDI_CHANNEL:
c::channel::addChannel(data.columnIndex, ChannelType::MIDI);
c::channel::addChannel(data.columnIndex, ChannelType::MIDI, data.id);
break;
case Menu::EDIT_ROUTING:
c::layout::openChannelRoutingWindow(data.id);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/elems/mainWindow/keyboard/midiChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "glue/main.h"
#include "gui/dialogs/warnings.h"
#include "gui/dispatcher.h"
#include "gui/elems/basics/box.h"
#include "gui/elems/basics/boxtypes.h"
#include "gui/elems/basics/dial.h"
#include "gui/elems/basics/imageButton.h"
Expand Down Expand Up @@ -80,6 +81,8 @@ geMidiChannel::geMidiChannel(int X, int Y, int W, int H, c::channel::Data d)
fx = new geImageButton(graphics::fxOff, graphics::fxOn);
vol = new geDial(0, 0, 0, 0);

if (m_channel.grouped)
addWidget(new geBox(), G_GUI_UNIT);
addWidget(playButton, G_GUI_UNIT);
addWidget(arm, G_GUI_UNIT);
addWidget(mainButton);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/elems/mainWindow/keyboard/sampleChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "glue/main.h"
#include "glue/storage.h"
#include "gui/dispatcher.h"
#include "gui/elems/basics/box.h"
#include "gui/elems/basics/boxtypes.h"
#include "gui/elems/basics/dial.h"
#include "gui/elems/basics/imageButton.h"
Expand Down Expand Up @@ -90,6 +91,8 @@ geSampleChannel::geSampleChannel(int X, int Y, int W, int H, c::channel::Data d)
fx = new geImageButton(graphics::fxOff, graphics::fxOn);
vol = new geDial(0, 0, 0, 0);

if (m_channel.grouped)
addWidget(new geBox(), G_GUI_UNIT);
addWidget(playButton, G_GUI_UNIT);
addWidget(arm, G_GUI_UNIT);
addWidget(progress, G_GUI_UNIT);
Expand Down
7 changes: 7 additions & 0 deletions src/gui/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ void Model::Columns::addChannelToColumn(ID channelId, int columnIndex, int posit

/* -------------------------------------------------------------------------- */

void Model::Columns::addChannelToGroup(ID channelId, ID groupId)
{
getColumnByChannelId(groupId).channels.push_back(channelId);
}

/* -------------------------------------------------------------------------- */

void Model::Columns::removeChannelFromColumn(ID channelId)
{
for (Column& column : m_columns) // Brute force!
Expand Down
1 change: 1 addition & 0 deletions src/gui/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct Model
void removeColumn(int columnIndex);
void moveChannel(ID channelId, int columnIndex, int newPosition);
void addChannelToColumn(ID channelId, int columnIndex, int position = -1);
void addChannelToGroup(ID channelId, ID groupId);
void removeChannelFromColumn(ID channelId);
void clear();

Expand Down

0 comments on commit 589f134

Please sign in to comment.