Skip to content

Commit

Permalink
Ability to load a wavetable onto a patch in python
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Aug 18, 2024
1 parent 0f7f877 commit a5d4132
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/surge-python/surgepy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,25 @@ class SurgeSynthesizerWithPythonExtensions : public SurgeSynthesizer

void releaseNoteWithInts(int ch, int note, int vel) { releaseNote(ch, note, vel); }

bool loadWavetablePy(int scene, int osc, const std::string &s)
{
auto path = string_to_path(s);

if (scene < 0 || scene >= n_scenes || osc < 0 || osc >= n_oscs)
{
throw std::invalid_argument("OSC and SCENE out of range in loadWavetable");
}
if (!fs::exists(path))
{
throw std::invalid_argument((std::string("File not found: ") + s).c_str());
}
std::cout << "Would load " << scene << " " << osc << " with " << s << std::endl;
auto os = &(storage.getPatch().scene[scene].osc[osc]);
auto wt = &(os->wt);
storage.load_wt(s, wt, os);

return true;
}
bool loadPatchPy(const std::string &s)
{
auto path = string_to_path(s);
Expand Down Expand Up @@ -1111,6 +1130,11 @@ PYBIND11_MODULE(surgepy, m)
.def("savePatch", &SurgeSynthesizerWithPythonExtensions::savePatchPy,
"Save the current state of Surge XT to an .fxp file.", py::arg("path"))

.def("loadWavetable", &SurgeSynthesizerWithPythonExtensions::loadWavetablePy,
"Load a wavetable file directly into a scene and oscillator immediately on this "
"thread.",
py::arg("scene"), py::arg("osc"), py::arg("path"))

.def("getModSource", &SurgeSynthesizerWithPythonExtensions::getModSource,
"Given a constant from surge.constants.ms_*, provide a modulator object",
py::arg("modId"))
Expand Down
19 changes: 19 additions & 0 deletions src/surge-python/tests/write_wavetable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Tests for Surge XT Python bindings.
"""
import sys
sys.path.append('/Users/paul/dev/music/surge/cmake-build-debug/src/surge-python/')
import surgepy

def main():
s = surgepy.createSurge(44100)

patch = s.getPatch()
osc0 = patch["scene"][0]["osc"][0]
otype = osc0["type"]
s.setParamVal(otype, surgepy.constants.ot_wavetable)
s.loadWavetable(0, 0, "/Users/paul/dev/music/surge/resources/data/wavetables_3rdparty/A.Liv/Droplet/Droplet 2.wav")
s.savePatch("/Users/paul/Desktop/PythonGenerated.fxp")

if __name__ == "__main__":
main()

0 comments on commit a5d4132

Please sign in to comment.