-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpytschirp.cpp
116 lines (95 loc) · 3.86 KB
/
pytschirp.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
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 "Logger.h"
#include "Rev2.h"
#include "Rev2Patch.h"
#include "PyTschirpPatch.h"
#include "PyTschirpAttribute.h"
#include "PyTschirpSynth.h"
#ifdef _MSC_VER
#pragma warning ( push )
#pragma warning ( disable: 4100 )
#endif
#include <pybind11/pybind11.h>
#include <pybind11/stl.h> // For vector to list
#ifdef _MSC_VER
#pragma warning(pop)
#endif
namespace py = pybind11;
// We will need a PythonLogger to get any debug output
class PythonLogger : public SimpleLogger {
public:
virtual void postMessage(const String& message) override {
std::cout << message << std::endl;
}
virtual void postMessageOncePerRun(const String& message) override {
// ignore the once per run here
postMessage(message);
}
};
midikraft::MidiController *correctMidiController() {
return midikraft::MidiController::instance();
}
template <typename T>
class SynthInstance : public PyTschirpSynth {
public:
SynthInstance() : PyTschirpSynth(std::make_shared<T>()) {
}
};
PYBIND11_MODULE(pytschirp, m) {
m.doc() = "Provide PyTschirp bindings for the Sequential Prophet Rev2";
py::class_<midikraft::MidiController> midiController(m, "MidiController");
midiController.def(py::init<>());
m.def("midiControllerInstance", &correctMidiController, py::return_value_policy::reference);
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);
//TODO
// set name of patch/layer
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)
;
py::class_<SynthInstance<midikraft::Rev2>> pyTschirpSynth(m, "Rev2");
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);
// TODO
// sendPatchToEditBuffer
// sendPatchToStoragePlace
// get specific patch at specific location from synth
// Fire up Singletons used by the frameworks we need
new PythonLogger();
// For use in PyTschirp, we need to lazily create the MidiController Singleton so it is in the right heap
if (!midikraft::MidiController::instance()) {
// Also, by default install a MIDI logger on stderr so we can see what is being sent and received
midikraft::MidiController::instance()->setMidiLogFunction([](MidiMessage const &message, String const &source, bool isOut) {
ignoreUnused(source);
py::print(isOut ? "O: " : "I: ", message.getDescription().toStdString());
});
}
// And JUCE itself might not be fired up, so let's do that!
juce::MessageManager::getInstance();
}