-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsynth.cpp
More file actions
86 lines (75 loc) · 2.1 KB
/
synth.cpp
File metadata and controls
86 lines (75 loc) · 2.1 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
// Copyright (C) 2012-2013 Samplecount S.L.
// Copyright (C) 2026 Methcla contributors
//
// SPDX-License-Identifier: Apache-2.0
#include "synth.hpp"
#include <methcla/plugins/sine.h>
#include <cassert>
thaddeus::Engine::Engine(Methcla::EngineOptions options,
Methcla_AudioDriver* audioDriver)
{
options.addLibrary(methcla_plugins_sine);
m_engine = new Methcla::Engine(options, audioDriver);
m_engine->start();
m_engine->setLogFlags(kMethcla_EngineLogDebug);
}
thaddeus::Engine::~Engine()
{
m_engine->stop();
delete m_engine;
}
void thaddeus::Engine::start()
{
m_engine->start();
}
void thaddeus::Engine::stop()
{
m_engine->stop();
}
void thaddeus::Engine::startVoice(VoiceId voice, float freq, float amp)
{
if (m_voices.find(voice) != m_voices.end())
{
stopVoice(voice);
}
Methcla::Request request(m_engine);
request.openBundle();
const Methcla::SynthId synth =
request.synth(METHCLA_PLUGINS_SINE_URI, m_engine->root(), {freq, amp});
request.activate(synth);
request.mapOutput(synth, 0, Methcla::AudioBusId(0),
Methcla::kBusMappingExternal);
request.closeBundle();
request.send();
// std::cout << "Synth " << synth << " started: freq=" << ps.freq <<
// " amp=" << ps.amp << std::endl;
m_voices[voice] = synth;
}
void thaddeus::Engine::updateVoice(VoiceId voice, float freq, float amp)
{
auto it = m_voices.find(voice);
if (it != m_voices.end())
{
auto synth = it->second;
Methcla::Request request(m_engine);
request.openBundle();
request.set(synth, 0, freq);
request.set(synth, 1, amp);
request.closeBundle();
request.send();
}
}
void thaddeus::Engine::stopVoice(VoiceId voice)
{
auto it = m_voices.find(voice);
if (it != m_voices.end())
{
auto synth = it->second;
Methcla::Request request(m_engine);
request.openBundle();
request.free(synth);
request.closeBundle();
request.send();
m_voices.erase(it);
}
}