Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to load a wavetable onto a patch in python #7765

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading