Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gvnnz committed Jan 16, 2024
1 parent fa5eb2e commit 9ac5e71
Show file tree
Hide file tree
Showing 19 changed files with 305 additions and 23 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ list(APPEND SOURCES
src/gui/elems/mainWindow/keyboard/column.cpp
src/gui/elems/mainWindow/keyboard/sampleChannel.cpp
src/gui/elems/mainWindow/keyboard/midiChannel.cpp
src/gui/elems/mainWindow/keyboard/groupChannel.cpp
src/gui/elems/mainWindow/keyboard/channel.cpp
src/gui/elems/mainWindow/keyboard/sampleChannelButton.cpp
src/gui/elems/mainWindow/keyboard/midiChannelButton.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/core/api/channelsApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ std::vector<Channel>& ChannelsApi::getAll()

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

Channel& ChannelsApi::add(ChannelType type)
Channel& ChannelsApi::add(ChannelType type, ID groupChannelId)
{
const int bufferSize = m_kernelAudio.getBufferSize();
return m_channelManager.addChannel(type, bufferSize);
return m_channelManager.addChannel(type, bufferSize, groupChannelId);
}

int ChannelsApi::loadSampleChannel(ID channelId, const std::string& filePath)
Expand Down
2 changes: 1 addition & 1 deletion src/core/api/channelsApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ChannelsApi
Channel& get(ID);
std::vector<Channel>& getAll();

Channel& add(ChannelType);
Channel& add(ChannelType, ID groupChannelId);
int loadSampleChannel(ID channelId, const std::string& filePath);
void loadSampleChannel(ID channelId, Wave&);
void remove(ID);
Expand Down
7 changes: 3 additions & 4 deletions src/core/api/sampleEditorApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ void SampleEditorApi::shift(ID channelId, Frame offset)

const Channel& SampleEditorApi::toNewChannel(ID channelId, Frame a, Frame b)
{
const int bufferSize = m_kernelAudio.getBufferSize();
Wave& wave = m_model.addWave(waveFactory::createFromWave(getWave(channelId), a, b));

const Channel& ch = m_channelManager.addChannel(ChannelType::SAMPLE, bufferSize);
const int bufferSize = m_kernelAudio.getBufferSize();
Wave& wave = m_model.addWave(waveFactory::createFromWave(getWave(channelId), a, b));
const Channel& ch = m_channelManager.addChannel(ChannelType::SAMPLE, bufferSize, /*groupChannelId=*/0);
m_channelManager.loadSampleChannel(ch.id, wave);

return ch;
Expand Down
20 changes: 18 additions & 2 deletions src/core/channels/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Channel::Channel(ChannelType type, ID id, ChannelShared& s)
, armed(false)
, key(0)
, hasActions(false)
, grouped(false)
, height(G_GUI_UNIT)
, m_mute(false)
, m_solo(false)
Expand Down Expand Up @@ -73,6 +74,7 @@ Channel::Channel(const Patch::Channel& p, ChannelShared& s, float samplerateRati
, armed(p.armed)
, key(p.key)
, hasActions(p.hasActions)
, grouped(false) // TODO
, name(p.name)
, height(p.height)
, plugins(plugins)
Expand Down Expand Up @@ -168,15 +170,17 @@ bool Channel::isPlaying() const
#ifdef G_DEBUG_MODE
std::string Channel::debug() const
{
std::string out = fmt::format("ID={} name='{}' type={} channelShared={}",
id, name, u::string::toString(type), (void*)&shared);
std::string out = fmt::format("ID={} name='{}' type={} grouped={} channelShared={}",
id, name, u::string::toString(type), grouped, (void*)&shared);

if (type == ChannelType::SAMPLE || type == ChannelType::PREVIEW)
out += fmt::format(" wave={} mode={} begin={} end={}",
(void*)sampleChannel->getWave(),
u::string::toString(sampleChannel->mode),
sampleChannel->begin,
sampleChannel->end);
else if (type == ChannelType::GROUP)
out += fmt::format(" channels={}", channels.size());

return out;
}
Expand Down Expand Up @@ -210,6 +214,18 @@ void Channel::setSolo(bool v)

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

void Channel::addChild(Channel&& child)
{
assert(type == ChannelType::GROUP);
assert(child.type != ChannelType::GROUP); // No infinite recursion (groups inside groups)
assert(!child.grouped); // No belonging to multiple groups

channels.push_back(std::move(child));
child.grouped = true;
}

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

void Channel::loadWave(Wave* w, Frame newBegin, Frame newEnd, Frame newShift)
{
assert(sampleChannel);
Expand Down
4 changes: 4 additions & 0 deletions src/core/channels/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class Channel final
void setMute(bool);
void setSolo(bool);

void addChild(Channel&&);

/* loadWave
Loads Wave and sets it up (name, markers, ...). Also updates Channel's shared
state accordingly. Resets begin/end points shift if not specified. */
Expand Down Expand Up @@ -104,9 +106,11 @@ class Channel final
bool armed;
int key; // TODO - move this to v::Model
bool hasActions;
bool grouped;
std::string name; // TODO - move this to v::Model
Pixel height; // TODO - move this to v::Model
std::vector<Plugin*> plugins;
std::vector<Channel> channels;

MidiInput midiInput;
MidiLightning midiLightning;
Expand Down
12 changes: 10 additions & 2 deletions src/core/channels/channelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void ChannelManager::setBufferSize(int bufferSize)

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

Channel& ChannelManager::addChannel(ChannelType type, int bufferSize)
Channel& ChannelManager::addChannel(ChannelType type, int bufferSize, ID groupChannelId)
{
const bool overdubProtectionDefaultOn = m_model.get().behaviors.overdubProtectionDefaultOn;
const Resampler::Quality rsmpQuality = m_model.get().kernelAudio.rsmpQuality;
Expand All @@ -113,7 +113,15 @@ Channel& ChannelManager::addChannel(ChannelType type, int bufferSize)

setupChannelCallbacks(data.channel, *data.shared);

m_model.get().channels.add(data.channel);
if (groupChannelId != 0)
{
Channel& child = data.channel;
Channel& parent = m_model.get().channels.get(groupChannelId);
parent.addChild(std::move(child));
}
else
m_model.get().channels.add(data.channel);

m_model.addChannelShared(std::move(data.shared));
m_model.swap(model::SwapType::HARD);

Expand Down
5 changes: 3 additions & 2 deletions src/core/channels/channelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ class ChannelManager final
void setBufferSize(int);

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

Channel& addChannel(ChannelType, int bufferSize);
Channel& addChannel(ChannelType, int bufferSize, ID groupChannelId);

/* loadSampleChannel (1)
Creates a new Wave from a file path and loads it inside a Sample Channel. */
Expand Down
3 changes: 3 additions & 0 deletions src/core/model/channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ void Channels::debug() const
for (int i = 0; const Channel& c : m_channels)
{
fmt::print("\t{} - {}\n", i++, c.debug());
if (c.type == ChannelType::GROUP)
for (const Channel& child : c.channels)
fmt::print("\t\t{} - {}\n", i++, child.debug());

if (c.plugins.size() > 0)
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/rendering/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class Renderer

void renderNormalChannels(const std::vector<Channel>& channels, mcl::AudioBuffer& out,
const mcl::AudioBuffer& in, bool hasSolos, bool seqIsRunning) const;
void renderGroupedChannels(const std::vector<Channel*>& channels, mcl::AudioBuffer& out,
const mcl::AudioBuffer& in, bool hasSolos, bool seqIsRunning) const;
void renderNormalChannel(const Channel& ch, mcl::AudioBuffer& out,
const mcl::AudioBuffer& in, bool mixerHasSolos, bool seqIsRunning) const;
void renderMasterIn(const Channel&, mcl::AudioBuffer& in) const;
Expand Down
3 changes: 2 additions & 1 deletion src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ enum class ChannelType : int
SAMPLE = 1,
MIDI,
MASTER,
PREVIEW
PREVIEW,
GROUP
};

enum class ChannelStatus : int
Expand Down
7 changes: 4 additions & 3 deletions src/glue/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Data::Data(const m::Channel& c, int columnIndex, int position)
, pan(c.pan)
, key(c.key)
, hasActions(c.hasActions)
, grouped(c.grouped)
, m_playStatus(&c.shared->playStatus)
, m_recStatus(&c.shared->recStatus)
, m_readActions(&c.shared->readActions)
Expand Down Expand Up @@ -179,9 +180,9 @@ 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);
const m::Channel& ch = g_engine->getChannelsApi().add(type, groupChannelId);
g_ui->model.addChannelToColumn(ch.id, columnIndex);
}

Expand All @@ -198,7 +199,7 @@ void addAndLoadChannels(int columnIndex, const std::vector<std::string>& fnames)
{
progress.setProgress(++i / static_cast<float>(fnames.size()));

const m::Channel& ch = channelsApi.add(ChannelType::SAMPLE);
const m::Channel& ch = channelsApi.add(ChannelType::SAMPLE, /*groupChannelId=*/0);
const int res = channelsApi.loadSampleChannel(ch.id, f);
if (res != G_RES_OK)
errors = true;
Expand Down
6 changes: 4 additions & 2 deletions src/glue/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct Data
float pan;
int key;
bool hasActions;
bool grouped;

std::optional<SampleData> sample;
std::optional<MidiData> midi;
Expand Down Expand Up @@ -132,9 +133,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
23 changes: 19 additions & 4 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 channel-groups
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 @@ -125,10 +137,13 @@ void geColumn::showAddChannelMenu() const
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
Loading

0 comments on commit 9ac5e71

Please sign in to comment.