-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathswe_synth_modular.cpp
More file actions
102 lines (78 loc) · 2.07 KB
/
swe_synth_modular.cpp
File metadata and controls
102 lines (78 loc) · 2.07 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
#include "swe_synth_modular.h"
namespace olc::sound::synth
{
///[OLC_HM] START SYNTH_MODULAR_CPP
Property::Property(double f)
{
value = std::clamp(f, -1.0, 1.0);
}
Property& Property::operator =(const double f)
{
value = std::clamp(f, -1.0, 1.0);
return *this;
}
ModularSynth::ModularSynth()
{
}
bool ModularSynth::AddModule(Module* pModule)
{
// Check if module already added
if (std::find(m_vModules.begin(), m_vModules.end(), pModule) == std::end(m_vModules))
{
m_vModules.push_back(pModule);
return true;
}
return false;
}
bool ModularSynth::RemoveModule(Module* pModule)
{
if (std::find(m_vModules.begin(), m_vModules.end(), pModule) != std::end(m_vModules))
{
m_vModules.erase(std::remove(m_vModules.begin(), m_vModules.end(), pModule), m_vModules.end());
return true;
}
return false;
}
bool ModularSynth::AddPatch(Property* pInput, Property* pOutput)
{
// Does patch exist?
std::pair<Property*, Property*> newPatch = std::pair<Property*, Property*>(pInput, pOutput);
if (std::find(m_vPatches.begin(), m_vPatches.end(), newPatch) == std::end(m_vPatches))
{
// Patch doesnt exist, now check if either are null
if (pInput != nullptr && pOutput != nullptr)
{
m_vPatches.push_back(newPatch);
return true;
}
}
return false;
}
bool ModularSynth::RemovePatch(Property* pInput, Property* pOutput)
{
std::pair<Property*, Property*> newPatch = std::pair<Property*, Property*>(pInput, pOutput);
if (std::find(m_vPatches.begin(), m_vPatches.end(), newPatch) != std::end(m_vPatches))
{
m_vPatches.erase(std::remove(m_vPatches.begin(), m_vPatches.end(), newPatch), m_vPatches.end());
return true;
}
return false;
}
void ModularSynth::UpdatePatches()
{
// Update patches
for (auto& patch : m_vPatches)
{
patch.second->value = patch.first->value;
}
}
void ModularSynth::Update(uint32_t nChannel, double dTime, double dTimeStep)
{
// Now update synth
for (auto& pModule : m_vModules)
{
pModule->Update(nChannel, dTime, dTimeStep);
}
}
///[OLC_HM] END SYNTH_MODULAR_CPP
}