-
Notifications
You must be signed in to change notification settings - Fork 1
/
embedded_module.cpp
87 lines (73 loc) · 2.77 KB
/
embedded_module.cpp
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
/*
Copyright (c) 2020 Christof Ruch. All rights reserved.
Dual licensed: Distributed under Affero GPL license by default, an MIT license is available for purchase
*/
#include "embedded_module.h"
#include "PyTschirpPatch.h"
#include "PyTschirpAttribute.h"
#include "PyTschirpSynth.h"
#include "Rev2.h"
#include "KawaiK3.h"
#include <pybind11/embed.h>
#include <pybind11/stl.h> // For vector to list
namespace py = pybind11;
template <typename T>
class SynthInstance : public PyTschirpSynth {
public:
SynthInstance() : PyTschirpSynth(std::make_shared<T>()) {
}
};
template <typename S, typename M>
void defineSynth(M m, const char *pythonClassName) {
py::class_<SynthInstance<S>> pyTschirpSynth(m, pythonClassName);
pyTschirpSynth
.def(py::init<>())
.def("detect", &PyTschirpSynth::detect)
.def("detected", &PyTschirpSynth::detected)
.def("location", &PyTschirpSynth::location)
.def("editBuffer", &PyTschirpSynth::editBuffer)
.def("loadSysex", &PyTschirpSynth::loadSysex)
.def("saveSysex", &PyTschirpSynth::saveSysex)
.def("saveEditBuffer", &PyTschirpSynth::saveEditBuffer)
.def("getGlobalSettings", &PyTschirpSynth::getGlobalSettings);
}
PYBIND11_EMBEDDED_MODULE(pytschirpee, m) {
m.doc() = "Provide PyTschirp bindings for the KnobKraft Orm";
py::class_<PyTschirp> rev2_tschirp(m, "Patch");
rev2_tschirp.def(py::init<std::shared_ptr<midikraft::Patch>>())
.def("attr", &PyTschirp::get_attr)
.def("__getattr__", &PyTschirp::get_attr)
.def("__setattr__", py::overload_cast<std::string const &, int>(&PyTschirp::set_attr))
.def("__setattr__", py::overload_cast<std::string const &, std::vector<int> const &>(&PyTschirp::set_attr))
.def("__setitem__", py::overload_cast<std::string const &, int>(&PyTschirp::set_attr))
.def("__setitem__", py::overload_cast<std::string const &, std::vector<int> const &>(&PyTschirp::set_attr))
.def("__getitem__", &PyTschirp::get_attr)
.def_property("name", &PyTschirp::getName, &PyTschirp::setName)
.def("layer", &PyTschirp::layer)
.def("parameterNames", &PyTschirp::parameterNames);
py::class_<PyTschirpAttribute> rev2_attribute(m, "Attribute");
rev2_attribute
.def("set", py::overload_cast<int>(&PyTschirpAttribute::set))
.def("set", py::overload_cast<std::vector<int>>(&PyTschirpAttribute::set))
.def("get", &PyTschirpAttribute::get)
.def("asText", &PyTschirpAttribute::asText)
.def("__repr__", &PyTschirpAttribute::asText)
;
defineSynth<midikraft::Rev2>(m, "Rev2");
defineSynth<midikraft::KawaiK3>(m, "K3");
}
void globalImportEmbeddedModules() {
py::module::import("pytschirpee");
}
std::string findPyTschirpModuleForSynth(std::string const &synthName)
{
midikraft::Rev2 rev2;
if (synthName == rev2.getName()) {
return "Rev2";
}
midikraft::KawaiK3 k3;
if (synthName == k3.getName()) {
return "K3";
}
return "";
}