Skip to content

Commit b6fe7bf

Browse files
committed
Move 'shift' to Sample struct
Adds ability to have multiple shift values, one per sample.
1 parent 5f98733 commit b6fe7bf

File tree

11 files changed

+33
-24
lines changed

11 files changed

+33
-24
lines changed

src/core/api/sampleEditorApi.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,16 @@ void SampleEditorApi::trim(ID channelId, Frame a, Frame b)
208208

209209
void SampleEditorApi::shift(ID channelId, Frame offset)
210210
{
211+
assert(false); // TODO - scenes
212+
#if 0
211213
const Channel& ch = m_channelManager.getChannel(channelId);
212-
const Frame oldShift = ch.sampleChannel->shift;
214+
const Frame oldShift = ch.sampleChannel->getShift(/*scene=*/0);
213215

214216
m::model::SharedLock lock = m_model.lockShared();
215217
m::wfx::shift(getWave(channelId), offset - oldShift);
216218
// Model has been swapped by DataLock constructor, needs to get Channel again
217219
m_channelManager.getChannel(channelId).sampleChannel->shift = offset;
220+
#endif
218221
}
219222

220223
/* -------------------------------------------------------------------------- */

src/core/channels/channel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,14 @@ void Channel::setName(const std::string& name, std::size_t scene) { m_names[scen
233233

234234
/* -------------------------------------------------------------------------- */
235235

236-
void Channel::loadSample(const Sample& s, std::size_t scene, Frame newShift)
236+
void Channel::loadSample(const Sample& s, std::size_t scene)
237237
{
238238
assert(sampleChannel);
239239

240240
shared->tracker.store(0);
241241
shared->playStatus.store(s.wave != nullptr ? ChannelStatus::OFF : ChannelStatus::EMPTY);
242242

243-
sampleChannel->loadSample(s, scene, newShift);
243+
sampleChannel->loadSample(s, scene);
244244
}
245245

246246
/* -------------------------------------------------------------------------- */

src/core/channels/channel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class Channel final
8989

9090
/* loadWave
9191
Loads Wave and sets it up (name, markers, ...). Also updates Channel's shared
92-
state accordingly. Resets begin/end points shift if not specified. */
92+
state accordingly. Resets begin/end points shift if not specified (-1). */
9393

94-
void loadSample(const Sample&, std::size_t scene, Frame shift = -1);
94+
void loadSample(const Sample&, std::size_t scene);
9595

9696
/* setWave
9797
Just sets the pointer to a Wave object. Used during de-serialization. The

src/core/channels/channelFactory.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,9 @@ const Patch::Channel serializeChannel(const Channel& c)
160160
if (c.type == ChannelType::SAMPLE)
161161
{
162162
for (std::size_t i = 0; i < G_MAX_NUM_SCENES; i++)
163-
pc.samples[i] = {c.sampleChannel->getWaveId(i), c.sampleChannel->getRange(i)};
163+
pc.samples[i] = {c.sampleChannel->getWaveId(i), c.sampleChannel->getRange(i), c.sampleChannel->getShift(i)};
164164
pc.mode = c.sampleChannel->mode;
165165
pc.pitch = c.sampleChannel->pitch;
166-
pc.shift = c.sampleChannel->shift;
167166
pc.midiInVeloAsVol = c.sampleChannel->velocityAsVol;
168167
pc.inputMonitor = c.sampleChannel->inputMonitor;
169168
pc.overdubProtection = c.sampleChannel->overdubProtection;

src/core/channels/channelManager.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ void ChannelManager::cloneChannel(ID channelId, int bufferSize, const std::vecto
212212

213213
if (oldChannel.sampleChannel && oldChannel.sampleChannel->hasWave(0))
214214
{
215+
// TODO - scenes
215216
const Wave& oldWave = *oldChannel.sampleChannel->getWave(0);
216-
const Frame oldShift = oldChannel.sampleChannel->shift;
217+
const Frame oldShift = oldChannel.sampleChannel->getShift(0);
217218
const auto oldRange = oldChannel.sampleChannel->getRange(0);
218219
Wave& wave = m_model.addWave(waveFactory::createFromWave(oldWave));
219220

220-
newChannelData.channel.loadSample({&wave, oldRange}, 0, oldShift);
221+
newChannelData.channel.loadSample({&wave, oldRange, oldShift}, 0);
221222
}
222223

223224
newChannelData.channel.plugins = plugins;

src/core/channels/sampleChannel.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ SampleChannel::SampleChannel()
3535
, overdubProtection(false)
3636
, mode(SamplePlayerMode::SINGLE_BASIC)
3737
, pitch(G_DEFAULT_PITCH)
38-
, shift(0)
3938
, velocityAsVol(false)
4039
{
4140
}
@@ -47,7 +46,6 @@ SampleChannel::SampleChannel(const Patch::Channel& p, const SceneArray<Sample>&
4746
, overdubProtection(p.overdubProtection)
4847
, mode(p.mode)
4948
, pitch(p.pitch)
50-
, shift(p.shift)
5149
, velocityAsVol(p.midiInVeloAsVol)
5250
{
5351
std::size_t scene = 0;
@@ -109,6 +107,10 @@ SampleRange SampleChannel::getRange(std::size_t scene) const { return m_samples[
109107

110108
/* -------------------------------------------------------------------------- */
111109

110+
Frame SampleChannel::getShift(std::size_t scene) const { return m_samples[scene].shift; }
111+
112+
/* -------------------------------------------------------------------------- */
113+
112114
const SceneArray<Sample>& SampleChannel::getSamples() const { return m_samples; }
113115

114116
/* -------------------------------------------------------------------------- */
@@ -120,14 +122,13 @@ Frame SampleChannel::getWaveSize(std::size_t scene) const
120122

121123
/* -------------------------------------------------------------------------- */
122124

123-
void SampleChannel::loadSample(const Sample& s, std::size_t scene, Frame newShift)
125+
void SampleChannel::loadSample(const Sample& s, std::size_t scene)
124126
{
125127
m_samples[scene] = {s.wave, {}};
126-
shift = 0;
127128

128129
if (s.wave != nullptr)
129130
{
130-
shift = newShift == -1 ? 0 : newShift;
131+
m_samples[scene].shift = s.shift == -1 ? 0 : s.shift;
131132
m_samples[scene].range = s.range.isValid() ? s.range : SampleRange(0, s.wave->getBuffer().countFrames());
132133
}
133134
}
@@ -144,7 +145,7 @@ void SampleChannel::setWave(Wave* w, std::size_t scene, float samplerateRatio)
144145
if (samplerateRatio != 1.0f)
145146
{
146147
m_samples[scene].range *= samplerateRatio;
147-
shift *= samplerateRatio;
148+
m_samples[scene].shift *= samplerateRatio;
148149
}
149150
}
150151

@@ -162,4 +163,10 @@ void SampleChannel::setSample(const Sample& sample, std::size_t scene, float sam
162163
setWave(sample.wave, scene, samplerateRatio);
163164
setRange(sample.range, scene);
164165
}
166+
/* -------------------------------------------------------------------------- */
167+
168+
void SampleChannel::setShift(Frame shift, std::size_t scene)
169+
{
170+
m_samples[scene].shift = shift;
171+
}
165172
} // namespace giada::m

src/core/channels/sampleChannel.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ class SampleChannel final
4949
Frame getWaveSize(std::size_t scene) const;
5050
Wave* getWave(std::size_t scene) const;
5151
SampleRange getRange(std::size_t scene) const;
52+
Frame getShift(std::size_t scene) const;
5253

5354
const SceneArray<Sample>& getSamples() const;
5455

5556
/* loadSample
5657
Loads Wave and sets it up (name, markers, ...). Resets begin/end points
57-
and shift if not specified. */
58+
and shift if not specified (-1). */
5859

59-
void loadSample(const Sample&, std::size_t scene, Frame newShift = -1);
60+
void loadSample(const Sample&, std::size_t scene);
6061

6162
/* setWave
6263
Just sets the pointer to a Wave object. Used during de-serialization. The
@@ -67,12 +68,12 @@ class SampleChannel final
6768

6869
void setRange(SampleRange, std::size_t scene);
6970
void setSample(const Sample&, std::size_t scene, float samplerateRatio);
71+
void setShift(Frame, std::size_t scene);
7072

7173
bool inputMonitor;
7274
bool overdubProtection;
7375
SamplePlayerMode mode;
7476
float pitch;
75-
Frame shift;
7677
bool velocityAsVol; // Velocity drives volume
7778

7879
private:

src/core/patch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ struct Patch
5858
{
5959
ID waveId = 0;
6060
SampleRange range;
61+
Frame shift = 0;
6162
};
62-
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Sample, waveId, range);
63+
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Sample, waveId, range, shift);
6364

6465
struct Channel
6566
{
@@ -92,7 +93,6 @@ struct Patch
9293
// sample channel
9394
SceneArray<Sample> samples = {};
9495
SamplePlayerMode mode = SamplePlayerMode::SINGLE_BASIC;
95-
Frame shift = 0;
9696
bool readActions = false;
9797
float pitch = G_DEFAULT_PITCH;
9898
bool inputMonitor = false;

src/core/patchFactory.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ constexpr auto PATCH_KEY_CHANNEL_MIDI_OUT_L_SOLO = "midi_out_l_solo";
7878
constexpr auto PATCH_KEY_CHANNEL_KEY = "key";
7979
constexpr auto PATCH_KEY_CHANNEL_SAMPLES = "samples";
8080
constexpr auto PATCH_KEY_CHANNEL_MODE = "mode";
81-
constexpr auto PATCH_KEY_CHANNEL_SHIFT = "shift";
8281
constexpr auto PATCH_KEY_CHANNEL_HAS_ACTIONS = "has_actions";
8382
constexpr auto PATCH_KEY_CHANNEL_READ_ACTIONS = "read_actions";
8483
constexpr auto PATCH_KEY_CHANNEL_PITCH = "pitch";
@@ -244,7 +243,6 @@ void readChannels_(Patch& patch, const nlohmann::json& j)
244243
c.midiOutLsolo = jchannel.value(PATCH_KEY_CHANNEL_MIDI_OUT_L_SOLO, 0);
245244
c.armed = jchannel.value(PATCH_KEY_CHANNEL_ARMED, false);
246245
c.mode = static_cast<SamplePlayerMode>(jchannel.value(PATCH_KEY_CHANNEL_MODE, 1));
247-
c.shift = jchannel.value(PATCH_KEY_CHANNEL_SHIFT, 0);
248246
c.readActions = jchannel.value(PATCH_KEY_CHANNEL_READ_ACTIONS, false);
249247
c.pitch = jchannel.value(PATCH_KEY_CHANNEL_PITCH, G_DEFAULT_PITCH);
250248
c.inputMonitor = jchannel.value(PATCH_KEY_CHANNEL_INPUT_MONITOR, false);
@@ -402,7 +400,6 @@ void writeChannels_(const Patch& patch, nlohmann::json& j)
402400
jchannel[PATCH_KEY_CHANNEL_MIDI_OUT_L_SOLO] = c.midiOutLsolo;
403401
jchannel[PATCH_KEY_CHANNEL_KEY] = c.key;
404402
jchannel[PATCH_KEY_CHANNEL_MODE] = static_cast<int>(c.mode);
405-
jchannel[PATCH_KEY_CHANNEL_SHIFT] = c.shift;
406403
jchannel[PATCH_KEY_CHANNEL_READ_ACTIONS] = c.readActions;
407404
jchannel[PATCH_KEY_CHANNEL_PITCH] = c.pitch;
408405
jchannel[PATCH_KEY_CHANNEL_INPUT_MONITOR] = c.inputMonitor;

src/glue/sampleEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Data::Data(const m::Channel& c, std::size_t scene)
4141
, pan(c.pan.asFloat())
4242
, pitch(c.sampleChannel->pitch)
4343
, range(c.sampleChannel->getRange(scene))
44-
, shift(c.sampleChannel->shift)
44+
, shift(c.sampleChannel->getShift(scene))
4545
, waveSize(c.sampleChannel->getWave(scene)->getBuffer().countFrames())
4646
, waveBits(c.sampleChannel->getWave(scene)->getBits())
4747
, waveDuration(c.sampleChannel->getWave(scene)->getDuration())

0 commit comments

Comments
 (0)