From 7dcd01d3a2a95edc3e7755dba51d5bf9fe6f3c8a Mon Sep 17 00:00:00 2001 From: Charbel Jacquin Date: Thu, 15 Jul 2021 22:03:15 +0200 Subject: [PATCH] expose adsr state --- src/bindings/h2core_module.cpp | 61 ++++++++++++++++++++++++++++++++-- src/core/Basics/Adsr.h | 28 +++++++++++----- 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/src/bindings/h2core_module.cpp b/src/bindings/h2core_module.cpp index b1b727d32..43f32d77b 100644 --- a/src/bindings/h2core_module.cpp +++ b/src/bindings/h2core_module.cpp @@ -1480,8 +1480,14 @@ PYBIND11_MODULE(h2core, m) { _Logger.def("should_log", &H2Core::Logger::should_log, "return true if the level is set in the bitmask", py::arg("lvl")); + _Logger.def_static("set_bit_mask", &H2Core::Logger::set_bit_mask, + "set the bitmask", + py::arg("msk")); _Logger.def_static("bit_mask", &H2Core::Logger::bit_mask, "return the current log level bit mask"); + _Logger.def("set_use_file", &H2Core::Logger::set_use_file, + "set use file flag", + py::arg("use")); _Logger.def("use_file", &H2Core::Logger::use_file, "return __use_file"); _Logger.def_static("parse_log_level", &H2Core::Logger::parse_log_level, @@ -1565,10 +1571,18 @@ PYBIND11_MODULE(h2core, m) { // [] _QColor.def_static("colorNames", &QColor::colorNames); _QColor.def("spec", &QColor::spec); _QColor.def("alpha", &QColor::alpha); + _QColor.def("setAlpha", &QColor::setAlpha, + py::arg("alpha")); _QColor.def("alphaF", &QColor::alphaF); _QColor.def("red", &QColor::red); _QColor.def("green", &QColor::green); _QColor.def("blue", &QColor::blue); + _QColor.def("setRed", &QColor::setRed, + py::arg("red")); + _QColor.def("setGreen", &QColor::setGreen, + py::arg("green")); + _QColor.def("setBlue", &QColor::setBlue, + py::arg("blue")); _QColor.def("redF", &QColor::redF); _QColor.def("greenF", &QColor::greenF); _QColor.def("blueF", &QColor::blueF); @@ -1596,6 +1610,8 @@ PYBIND11_MODULE(h2core, m) { py::arg("a")); _QColor.def("rgba64", &QColor::rgba64); _QColor.def("rgba", &QColor::rgba); + _QColor.def("setRgba", &QColor::setRgba, + py::arg("rgba")); _QColor.def("rgb", &QColor::rgb); _QColor.def("hue", &QColor::hue); _QColor.def("saturation", &QColor::saturation); @@ -1803,6 +1819,14 @@ PYBIND11_MODULE(h2core, m) { _QRgba64.def("green", &QRgba64::green); _QRgba64.def("blue", &QRgba64::blue); _QRgba64.def("alpha", &QRgba64::alpha); + _QRgba64.def("setRed", &QRgba64::setRed, + py::arg("_red")); + _QRgba64.def("setGreen", &QRgba64::setGreen, + py::arg("_green")); + _QRgba64.def("setBlue", &QRgba64::setBlue, + py::arg("_blue")); + _QRgba64.def("setAlpha", &QRgba64::setAlpha, + py::arg("_alpha")); _QRgba64.def("red8", &QRgba64::red8); _QRgba64.def("green8", &QRgba64::green8); _QRgba64.def("blue8", &QRgba64::blue8); @@ -1914,7 +1938,6 @@ PYBIND11_MODULE(h2core, m) { _Sampler.def_readwrite("m_pMainOut_R", &H2Core::Sampler::m_pMainOut_R); _Sampler.def_property_readonly("playing_notes_number", &H2Core::Sampler::getPlayingNotesNumber); _Sampler.def_property("interpolate_mode", &H2Core::Sampler::getInterpolateMode, &H2Core::Sampler::setInterpolateMode); - _Sampler.def_property_readonly("preview_instrument", &H2Core::Sampler::getPreviewInstrument); _Sampler.def_property_readonly("playback_track_instrument", &H2Core::Sampler::getPlaybackTrackInstrument); _Sampler.def_static("class_name", &H2Core::Sampler::class_name); _Sampler.def_static("ratioStraightPolygonalPanLaw", &H2Core::Sampler::ratioStraightPolygonalPanLaw, @@ -1973,12 +1996,15 @@ PYBIND11_MODULE(h2core, m) { _Sampler.def("preview_sample", &H2Core::Sampler::preview_sample, py::arg("pSample"), py::arg("length")); + _Sampler.def("preview_instrument", &H2Core::Sampler::preview_instrument, + py::arg("pInstr")); _Sampler.def("setPlayingNotelength", &H2Core::Sampler::setPlayingNotelength, py::arg("pInstrument"), py::arg("ticks"), py::arg("noteOnTick")); _Sampler.def("isInstrumentPlaying", &H2Core::Sampler::isInstrumentPlaying, py::arg("pInstr")); + _Sampler.def("getPreviewInstrument", &H2Core::Sampler::getPreviewInstrument); _Sampler.def("reinitializePlaybackTrack", &H2Core::Sampler::reinitializePlaybackTrack, "Loading of the playback track."); @@ -3414,8 +3440,16 @@ PYBIND11_MODULE(h2core, m) { "get the queued status of the instrument"); _Instrument.def("is_stop_notes", &H2Core::Instrument::is_stop_notes, "get the stop notes of the instrument"); + _Instrument.def("set_sample_selection_alg", &H2Core::Instrument::set_sample_selection_alg, + py::arg("selected_algo")); _Instrument.def("sample_selection_alg", &H2Core::Instrument::sample_selection_alg); + _Instrument.def("set_is_preview_instrument", &H2Core::Instrument::set_is_preview_instrument, + "Mark the instrument as hydrogen's preview instrument", + py::arg("isPreview")); _Instrument.def("is_preview_instrument", &H2Core::Instrument::is_preview_instrument); + _Instrument.def("set_is_metronome_instrument", &H2Core::Instrument::set_is_metronome_instrument, + "Mark the instrument as metronome instrument", + py::arg("isMetronome")); _Instrument.def("is_metronome_instrument", &H2Core::Instrument::is_metronome_instrument); _Instrument.def("get_component", &H2Core::Instrument::get_component, py::arg("DrumkitComponentID")); @@ -3434,14 +3468,27 @@ PYBIND11_MODULE(h2core, m) { py::class_> _ADSR(m, "ADSR"); _ADSR.def(py::init()); _ADSR.def(py::init>()); - _ADSR.def_property("attack", &H2Core::ADSR::get_attack, &H2Core::ADSR::set_attack); _ADSR.def_property("decay", &H2Core::ADSR::get_decay, &H2Core::ADSR::set_decay); _ADSR.def_property("sustain", &H2Core::ADSR::get_sustain, &H2Core::ADSR::set_sustain); - _ADSR.def_property("release", &H2Core::ADSR::get_release, &H2Core::ADSR::set_release); + _ADSR.def_property_readonly("state", &H2Core::ADSR::get_state); _ADSR.def_static("class_name", &H2Core::ADSR::class_name); + _ADSR.def("set_attack", &H2Core::ADSR::set_attack, + "__attack setter", + py::arg("value")); + _ADSR.def("get_attack", &H2Core::ADSR::get_attack, + "__attack accessor"); + _ADSR.def("set_release", &H2Core::ADSR::set_release, + "__release setter", + py::arg("value")); + _ADSR.def("get_release", &H2Core::ADSR::get_release, + "__release accessor"); + _ADSR.def("attack", &H2Core::ADSR::attack, + "sets state to ATTACK"); _ADSR.def("get_value", &H2Core::ADSR::get_value, "compute the value and return it", py::arg("step")); + _ADSR.def("release", &H2Core::ADSR::release, + "sets state to RELEASE, returns 0 if the state is IDLE, __value if the state is RELEASE, set state to RELEASE, save __release_value and return it."); _ADSR.def("toQString", &H2Core::ADSR::toQString, "Formatted string version for debugging purposes.", py::arg("sPrefix"), @@ -4193,6 +4240,14 @@ PYBIND11_MODULE(h2core, m) { .value("VELOCITY", H2Core::Instrument::SampleSelectionAlgo::VELOCITY) .value("ROUND_ROBIN", H2Core::Instrument::SampleSelectionAlgo::ROUND_ROBIN) .value("RANDOM", H2Core::Instrument::SampleSelectionAlgo::RANDOM); + // enum ADSRState + // + py::enum_(_ADSR, "ADSRState") + .value("ATTACK", H2Core::ADSR::ADSRState::ATTACK) + .value("DECAY", H2Core::ADSR::ADSRState::DECAY) + .value("SUSTAIN", H2Core::ADSR::ADSRState::SUSTAIN) + .value("RELEASE", H2Core::ADSR::ADSRState::RELEASE) + .value("IDLE", H2Core::ADSR::ADSRState::IDLE); // enum Timebase // py::enum_(_JackAudioDriver, "Timebase") diff --git a/src/core/Basics/Adsr.h b/src/core/Basics/Adsr.h index b9ff47bc0..459b4f19d 100644 --- a/src/core/Basics/Adsr.h +++ b/src/core/Basics/Adsr.h @@ -37,7 +37,13 @@ class ADSR : public Object { H2_OBJECT(ADSR) public: - + enum ADSRState { + ATTACK=0, + DECAY, + SUSTAIN, + RELEASE, + IDLE + }; /** * constructor * \param attack tick duration @@ -86,6 +92,10 @@ class ADSR : public Object * sets state to ATTACK */ void attack(); + /** + * get current state + */ + ADSRState get_state(); /** * compute the value and return it * \param step the increment to be added to __ticks @@ -114,13 +124,7 @@ class ADSR : public Object float __sustain; ///< Sustain level unsigned int __release; ///< Release tick count /** possible states */ - enum ADSRState { - ATTACK=0, - DECAY, - SUSTAIN, - RELEASE, - IDLE - }; + ADSRState __state; ///< current state float __ticks; ///< current tick count float __value; ///< current value @@ -170,7 +174,13 @@ inline unsigned int ADSR::get_release() return __release; } -}; + +inline ADSR::ADSRState ADSR::get_state() +{ + return __state; +} + +}; // namespace H2Core #endif // H2C_ADRS_H