Skip to content

Commit 87b237c

Browse files
committed
WIP
1 parent 4540d3a commit 87b237c

File tree

13 files changed

+155
-78
lines changed

13 files changed

+155
-78
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ list(APPEND SOURCES
107107
src/core/waveFx.h
108108
src/core/kernelMidi.cpp
109109
src/core/kernelMidi.h
110+
src/core/patch.cpp
110111
src/core/patch.h
111112
src/core/actions/actionFactory.cpp
112113
src/core/actions/actionFactory.h

src/core/channels/channel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Channel::Channel(ChannelType type, ID id, ChannelShared& s)
6666

6767
/* -------------------------------------------------------------------------- */
6868

69-
Channel::Channel(const Patch::Channel& p, ChannelShared& s, float samplerateRatio, Wave* wave, std::vector<Plugin*> plugins)
69+
Channel::Channel(const Patch::Channel& p, ChannelShared& s, float samplerateRatio, std::vector<Wave*> waves, std::vector<Plugin*> plugins)
7070
: shared(&s)
7171
, id(p.id)
7272
, type(p.type)
@@ -92,7 +92,7 @@ Channel::Channel(const Patch::Channel& p, ChannelShared& s, float samplerateRati
9292
{
9393
case ChannelType::SAMPLE:
9494
case ChannelType::PREVIEW:
95-
sampleChannel.emplace(p, wave, samplerateRatio);
95+
sampleChannel.emplace(p, waves, samplerateRatio);
9696
break;
9797

9898
case ChannelType::MIDI:

src/core/channels/channel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Channel final
4343
{
4444
public:
4545
Channel(ChannelType t, ID id, ChannelShared&);
46-
Channel(const Patch::Channel&, ChannelShared&, float samplerateRatio, Wave*, std::vector<Plugin*>);
46+
Channel(const Patch::Channel&, ChannelShared&, float samplerateRatio, std::vector<Wave*>, std::vector<Plugin*>);
4747

4848
bool operator==(const Channel&) const;
4949

src/core/channels/channelFactory.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ Data create(const Channel& o, int bufferSize, Resampler::Quality quality)
104104

105105
/* -------------------------------------------------------------------------- */
106106

107-
Channel deserializeChannel(const Patch::Channel& pch, ChannelShared& shared, float samplerateRatio, Wave* wave, std::vector<Plugin*> plugins)
107+
Channel deserializeChannel(const Patch::Channel& pch, ChannelShared& shared, float samplerateRatio, std::vector<Wave*> waves, std::vector<Plugin*> plugins)
108108
{
109109
channelId_.set(pch.id);
110-
return Channel(pch, shared, samplerateRatio, wave, plugins);
110+
return Channel(pch, shared, samplerateRatio, waves, plugins);
111111
}
112112

113113
/* -------------------------------------------------------------------------- */
@@ -129,7 +129,6 @@ const Patch::Channel serializeChannel(const Channel& c)
129129
pc.id = c.id;
130130
pc.type = c.type;
131131
pc.height = c.height;
132-
pc.name = c.getName(0); // TODO - scenes
133132
pc.key = c.key;
134133
pc.mute = c.isMuted();
135134
pc.solo = c.isSoloed();
@@ -156,11 +155,14 @@ const Patch::Channel serializeChannel(const Channel& c)
156155
pc.midiOutLmute = c.midiLightning.mute.getValue();
157156
pc.midiOutLsolo = c.midiLightning.solo.getValue();
158157

158+
for (std::size_t i = 0; i < G_MAX_NUM_SCENES; i++)
159+
pc.names.push_back(c.getName(i));
160+
159161
if (c.type == ChannelType::SAMPLE)
160162
{
161-
pc.waveId = c.sampleChannel->getWaveId(0);
163+
for (std::size_t i = 0; i < G_MAX_NUM_SCENES; i++)
164+
pc.samples.push_back({c.sampleChannel->getWaveId(i), c.sampleChannel->getRange(i)});
162165
pc.mode = c.sampleChannel->mode;
163-
pc.range = c.sampleChannel->getRange(0);
164166
pc.pitch = c.sampleChannel->pitch;
165167
pc.shift = c.sampleChannel->shift;
166168
pc.midiInVeloAsVol = c.sampleChannel->velocityAsVol;

src/core/channels/channelFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Data create(const Channel& ch, int bufferSize, Resampler::Quality);
7070
/* (de)deserializeChannel
7171
Creates a new channel given the patch raw data and vice versa. */
7272

73-
Channel deserializeChannel(const Patch::Channel& c, ChannelShared&, float samplerateRatio, Wave*, std::vector<Plugin*>);
73+
Channel deserializeChannel(const Patch::Channel& c, ChannelShared&, float samplerateRatio, std::vector<Wave*> waves, std::vector<Plugin*>);
7474
const Patch::Channel serializeChannel(const Channel& c);
7575

7676
/* deserializeShared

src/core/channels/sampleChannel.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ SampleChannel::SampleChannel()
4242

4343
/* -------------------------------------------------------------------------- */
4444

45-
SampleChannel::SampleChannel(const Patch::Channel& p, Wave* w, float samplerateRatio)
45+
SampleChannel::SampleChannel(const Patch::Channel& p, std::vector<Wave*> waves, float samplerateRatio)
4646
: inputMonitor(p.inputMonitor)
4747
, overdubProtection(p.overdubProtection)
4848
, mode(p.mode)
4949
, pitch(p.pitch)
5050
, shift(p.shift)
5151
, velocityAsVol(p.midiInVeloAsVol)
5252
{
53-
setWave(w, 0, samplerateRatio);
53+
std::size_t scene = 0;
54+
for (Wave* wave : waves)
55+
setWave(wave, scene++, samplerateRatio);
5456
}
5557

5658
/* -------------------------------------------------------------------------- */

src/core/channels/sampleChannel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SampleChannel final
3737
{
3838
public:
3939
SampleChannel();
40-
SampleChannel(const Patch::Channel&, Wave*, float samplerateRatio);
40+
SampleChannel(const Patch::Channel&, std::vector<Wave*>, float samplerateRatio);
4141

4242
bool isAnyLoopMode() const;
4343
bool isAnyLoopOnceMode() const;

src/core/model/document.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,18 @@ void Document::load(const Patch& patch, Shared& shared, float sampleRateRatio)
4040
for (const Patch::Track& ptrack : patch.tracks)
4141
{
4242
Track& track = tracks.add(ptrack.width, ptrack.internal);
43-
4443
for (const ID channelId : ptrack.channels)
4544
{
46-
const Patch::Channel& pchannel = *u::vector::findIfSafe(patch.channels, channelId);
47-
Wave* wave = shared.findWave(pchannel.waveId);
48-
std::vector<Plugin*> plugins = shared.findPlugins(pchannel.pluginIds);
49-
ChannelShared* channelShared = shared.findChannel(pchannel.id);
45+
const Patch::Channel& pchannel = *u::vector::findIfSafe(patch.channels, channelId);
46+
const std::vector<ID> waveIds = pchannel.samples | std::views::transform([](const Patch::Sample& s)
47+
{ return s.waveId; }) | std::ranges::to<std::vector<ID>>();
48+
49+
std::vector<Wave*> waves = shared.findWaves(waveIds);
50+
std::vector<Plugin*> plugins = shared.findPlugins(pchannel.pluginIds);
51+
ChannelShared* channelShared = shared.findChannel(pchannel.id);
5052
assert(channelShared != nullptr);
5153

52-
Channel channel = channelFactory::deserializeChannel(pchannel, *channelShared, sampleRateRatio, wave, plugins);
54+
Channel channel = channelFactory::deserializeChannel(pchannel, *channelShared, sampleRateRatio, waves, plugins);
5355
track.addChannel(std::move(channel));
5456
}
5557
}

src/core/model/shared.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ auto* get_(S& source, ID id)
5555
return it == source.end() ? nullptr : it->get();
5656
}
5757

58+
template <typename S>
59+
auto get_(S& source, std::vector<ID> ids)
60+
{
61+
using RawPtr = decltype(source.front().get());
62+
std::vector<RawPtr> out;
63+
for (const ID id : ids)
64+
out.push_back(get_(source, id));
65+
return out;
66+
}
67+
5868
/* -------------------------------------------------------------------------- */
5969

6070
template <typename T>
@@ -174,9 +184,10 @@ std::vector<std::unique_ptr<ChannelShared>>& Shared::getAllChannels() { return m
174184

175185
/* -------------------------------------------------------------------------- */
176186

177-
Plugin* Shared::findPlugin(ID id) { return get_(m_plugins, id); }
178-
Wave* Shared::findWave(ID id) { return get_(m_waves, id); }
179-
ChannelShared* Shared::findChannel(ID id) { return get_(m_channels, id); }
187+
Plugin* Shared::findPlugin(ID id) { return get_(m_plugins, id); }
188+
Wave* Shared::findWave(ID id) { return get_(m_waves, id); }
189+
std::vector<Wave*> Shared::findWaves(std::vector<ID> ids) { return get_(m_waves, ids); }
190+
ChannelShared* Shared::findChannel(ID id) { return get_(m_channels, id); }
180191

181192
/* -------------------------------------------------------------------------- */
182193

src/core/model/shared.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ class Shared
7474
Finds something in the shared data given an ID. Returns nullptr if the
7575
object is not found. */
7676

77-
Plugin* findPlugin(ID);
78-
Wave* findWave(ID);
79-
ChannelShared* findChannel(ID);
77+
Plugin* findPlugin(ID);
78+
Wave* findWave(ID);
79+
std::vector<Wave*> findWaves(std::vector<ID>);
80+
ChannelShared* findChannel(ID);
8081

8182
/* add[*]
8283
Adds some shared data (by moving it). Returns a reference to the last added

0 commit comments

Comments
 (0)