-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsampler_playback_router.cpp
More file actions
104 lines (90 loc) · 3.84 KB
/
Copy pathsampler_playback_router.cpp
File metadata and controls
104 lines (90 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "sampler_playback_router.h"
#include "active_sample_registry.h"
#include "sample_ram_manager.h"
void SamplerPlaybackRouter::begin(Ui *ui,
const SampleLibrary::Catalog *catalog,
const SamplerRuntime *runtime,
TriggerEngine *triggerEngine) {
ui_ = ui;
catalog_ = catalog;
runtime_ = runtime;
triggerEngine_ = triggerEngine;
}
void SamplerPlaybackRouter::onPreviewSample(int sampleIndex) const {
if (!ui_ || !catalog_ || !triggerEngine_) return;
if (!catalog_->playable(sampleIndex)) return;
TriggerEvent event;
event.source = TriggerSourceType::StreamPath;
event.isPreview = true;
event.volume = static_cast<uint8_t>(ui_->sampleVolumeForSample(sampleIndex));
event.retriggerGroupId = static_cast<int16_t>(sampleIndex);
event.loopEnabled = ui_->sampleLoopPlaybackEnabled(sampleIndex);
const String &path = catalog_->paths[sampleIndex];
path.toCharArray(event.path, sizeof(event.path));
triggerEngine_->enqueue(event);
}
void SamplerPlaybackRouter::onAssignedMidiNoteOn(int midiNote) const {
if (!ui_ || !catalog_ || !runtime_ || !triggerEngine_) return;
if (ui_->panicMidiNote() == midiNote) {
triggerEngine_->panicAll();
return;
}
const int sampleIndex = ui_->assignedSampleForMidiNote(midiNote);
if (sampleIndex < 0 || sampleIndex >= catalog_->count) {
ui_->clearTriggeredSample();
return;
}
if (!catalog_->playable(sampleIndex)) return;
ui_->reportTriggeredSample(sampleIndex);
const String &assignedPath = catalog_->paths[sampleIndex];
const uint8_t assignedVolume = static_cast<uint8_t>(ui_->sampleVolumeForSample(sampleIndex));
const ActiveSampleRegistry::Entry *entry = runtime_->findRegistryEntryForNote(midiNote);
const bool hasPreparedEntry = (entry && entry->path == assignedPath);
if (hasPreparedEntry &&
entry->effectiveMode == ActiveSampleRegistry::EffectiveStorageMode::Unavailable) {
return;
}
if (hasPreparedEntry && entry->effectiveMode == ActiveSampleRegistry::EffectiveStorageMode::Ram) {
SampleRamManager::LoadedSampleData loadedData;
const SampleClassifier::AssignedSampleClassification *classified =
runtime_->findClassificationByPath(entry->path);
if (classified && SampleRamManager::getLoadedSampleDataByPath(entry->path, loadedData)) {
TriggerEvent event;
event.source = TriggerSourceType::RamData;
event.volume = assignedVolume;
event.retriggerGroupId = static_cast<int16_t>(sampleIndex);
event.loopEnabled = ui_->sampleLoopPlaybackEnabled(sampleIndex);
event.ramData = loadedData.data;
event.ramDataBytes = loadedData.dataBytes;
event.channelCount = classified->channelCount;
event.sampleRate = classified->sampleRate;
event.bitsPerSample = classified->bitsPerSample;
const bool played = triggerEngine_->enqueue(event);
if (played) {
return;
}
}
}
TriggerEvent event;
event.source = TriggerSourceType::StreamPath;
event.volume = assignedVolume;
event.retriggerGroupId = static_cast<int16_t>(sampleIndex);
event.loopEnabled = ui_->sampleLoopPlaybackEnabled(sampleIndex);
assignedPath.toCharArray(event.path, sizeof(event.path));
SampleRamManager::LoadedSampleData head;
if (hasPreparedEntry && SampleRamManager::getLoadedHeadByPath(assignedPath, head)) {
event.streamHead = head.data;
event.streamHeadBytes = head.dataBytes;
}
triggerEngine_->enqueue(event);
}
void SamplerPlaybackRouter::onPlaybackModeChanged(Ui::PlaybackMode mode, int sampleIndex) const {
if (!triggerEngine_) return;
if (sampleIndex < 0) return;
const int16_t groupId = static_cast<int16_t>(sampleIndex);
if (mode == Ui::PlaybackMode::Loop) {
triggerEngine_->setLoopEnabledForGroup(groupId, true);
return;
}
triggerEngine_->stopLoopingVoicesForGroup(groupId);
}