Skip to content

Commit

Permalink
Add group support to Channel class
Browse files Browse the repository at this point in the history
  • Loading branch information
gvnnz committed May 19, 2024
1 parent 7c5afcb commit 500c8b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
22 changes: 20 additions & 2 deletions src/core/channels/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* -------------------------------------------------------------------------- */

#include "core/channels/channel.h"
#include "core/model/channels.h"
#include <cassert>
#ifdef G_DEBUG_MODE
#include "utils/string.h"
Expand All @@ -36,6 +37,7 @@ namespace giada::m
Channel::Channel(ChannelType type, ID id, ChannelShared& s)
: shared(&s)
, id(id)
, parentId(0)
, type(type)
, volume(G_DEFAULT_VOL)
, pan(G_DEFAULT_PAN)
Expand All @@ -57,6 +59,10 @@ Channel::Channel(ChannelType type, ID id, ChannelShared& s)
midiChannel.emplace();
break;

case ChannelType::GROUP:
groupChannel.emplace();
break;

default:
break;
}
Expand All @@ -67,6 +73,7 @@ Channel::Channel(ChannelType type, ID id, ChannelShared& s)
Channel::Channel(const Patch::Channel& p, ChannelShared& s, float samplerateRatio, Wave* wave, std::vector<Plugin*> plugins)
: shared(&s)
, id(p.id)
, parentId(0) // TODO
, type(p.type)
, volume(p.volume)
, pan(p.pan)
Expand Down Expand Up @@ -95,6 +102,10 @@ Channel::Channel(const Patch::Channel& p, ChannelShared& s, float samplerateRati
midiChannel.emplace(p);
break;

case ChannelType::GROUP:
groupChannel.emplace(); // TODO
break;

default:
break;
}
Expand Down Expand Up @@ -156,6 +167,11 @@ bool Channel::hasWave() const
return sampleChannel && sampleChannel->hasWave();
}

bool Channel::isGrouped() const
{
return parentId != 0;
}

bool Channel::isPlaying() const
{
ChannelStatus s = shared->playStatus.load();
Expand All @@ -167,15 +183,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), isGrouped(), (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={}", groupChannel->getChildren().size());

return out;
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/channels/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define G_CHANNEL_H

#include "core/channels/channelShared.h"
#include "core/channels/groupChannel.h"
#include "core/channels/midiChannel.h"
#include "core/channels/midiInput.h"
#include "core/channels/midiLightning.h"
Expand All @@ -53,6 +54,7 @@ class Channel final
bool canInputRec() const;
bool canActionRec() const;
bool hasWave() const;
bool isGrouped() const;

/* canReceiveAudio
Tells if the sample channel can receive audio as input monitor. */
Expand All @@ -65,7 +67,7 @@ class Channel final
bool canSendMidi() const;

/* isAudible
True if this channel is currently audible: not muted or not included in a
True if this channel is currently audible: not muted or not included in a
solo session. */

bool isAudible(bool mixerHasSolos) const;
Expand Down Expand Up @@ -98,6 +100,7 @@ class Channel final

ChannelShared* shared;
ID id;
ID parentId;
ChannelType type;
float volume;
float pan;
Expand All @@ -113,6 +116,7 @@ class Channel final

std::optional<SampleChannel> sampleChannel;
std::optional<MidiChannel> midiChannel;
std::optional<GroupChannel> groupChannel;

private:
bool m_mute;
Expand Down

0 comments on commit 500c8b8

Please sign in to comment.