diff --git a/plugins/lv2/sfizz.cpp b/plugins/lv2/sfizz.cpp index e5f35024..d5ec2613 100644 --- a/plugins/lv2/sfizz.cpp +++ b/plugins/lv2/sfizz.cpp @@ -313,7 +313,7 @@ sfizz_lv2_update_timeinfo(sfizz_plugin_t *self, int delay, int updates) if (updates & SFIZZ_TIMEINFO_SIGNATURE) sfizz_send_time_signature(self->synth, delay, self->beats_per_bar, self->beat_unit); if (updates & SFIZZ_TIMEINFO_TEMPO) - sfizz_send_tempo(self->synth, delay, 60.0f / self->bpm_tempo); + sfizz_send_bpm_tempo(self->synth, delay, self->bpm_tempo); if (updates & SFIZZ_TIMEINFO_SPEED) sfizz_send_playback_state(self->synth, delay, self->speed > 0); } diff --git a/plugins/vst/SfizzVstProcessor.cpp b/plugins/vst/SfizzVstProcessor.cpp index d3b7156f..fb02ab5b 100644 --- a/plugins/vst/SfizzVstProcessor.cpp +++ b/plugins/vst/SfizzVstProcessor.cpp @@ -97,7 +97,7 @@ tresult PLUGIN_API SfizzVstProcessor::initialize(FUnknown* context) _currentStretchedTuning = 0.0; loadSfzFileOrDefault({}, false); - _synth->tempo(0, 0.5); + _synth->bpmTempo(0, 120); _timeSigNumerator = 4; _timeSigDenominator = 4; _synth->timeSignature(0, _timeSigNumerator, _timeSigDenominator); @@ -313,7 +313,7 @@ void SfizzVstProcessor::updateTimeInfo(const Vst::ProcessContext& context) sfz::Sfizz& synth = *_synth; if (context.state & context.kTempoValid) - synth.tempo(0, float(60.0 / context.tempo)); + synth.bpmTempo(0, context.tempo); if (context.state & context.kTimeSigValid) { _timeSigNumerator = context.timeSigNumerator; diff --git a/src/sfizz.h b/src/sfizz.h index 50202255..6ea2b39d 100644 --- a/src/sfizz.h +++ b/src/sfizz.h @@ -43,6 +43,12 @@ #define SFIZZ_EXPORTED_API #endif +#if defined _WIN32 + #define SFIZZ_DEPRECATED_API __declspec(deprecated) +#else + #define SFIZZ_DEPRECATED_API __attribute__ ((deprecated)) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -584,7 +590,25 @@ SFIZZ_EXPORTED_API void sfizz_send_hd_poly_aftertouch(sfizz_synth_t* synth, int * @par Thread-safety constraints * - @b RT: the function must be invoked from the Real-time thread */ -SFIZZ_EXPORTED_API void sfizz_send_tempo(sfizz_synth_t* synth, int delay, float seconds_per_beat); +SFIZZ_EXPORTED_API SFIZZ_DEPRECATED_API void sfizz_send_tempo(sfizz_synth_t* synth, int delay, float seconds_per_beat); + +/** + * @brief Send a tempo event. + * + * This command should be delay-ordered with all other time/signature commands, namely + * tempo(), timeSignature(), timePosition(), and playbackState(), otherwise the behavior + * of the synth is undefined. + * + * @since 0.6.0 + * + * @param synth The synth. + * @param delay The delay. + * @param beats_per_minute The new tempo, in beats per minute. + * + * @par Thread-safety constraints + * - @b RT: the function must be invoked from the Real-time thread + */ +SFIZZ_EXPORTED_API void sfizz_send_bpm_tempo(sfizz_synth_t* synth, int delay, float beats_per_minute); /** * @brief Send the time signature. diff --git a/src/sfizz.hpp b/src/sfizz.hpp index b96c9555..8891dd40 100644 --- a/src/sfizz.hpp +++ b/src/sfizz.hpp @@ -26,6 +26,12 @@ #define SFIZZ_EXPORTED_API #endif +#if defined _WIN32 + #define SFIZZ_DEPRECATED_API __declspec(deprecated) +#else + #define SFIZZ_DEPRECATED_API __attribute__ ((deprecated)) +#endif + struct sfizz_synth_t; namespace sfz @@ -623,7 +629,25 @@ public: * @par Thread-safety constraints * - @b RT: the function must be invoked from the Real-time thread */ - void tempo(int delay, float secondsPerBeat) noexcept; + SFIZZ_DEPRECATED_API void tempo(int delay, float secondsPerBeat) noexcept; + + /** + * @brief Send a tempo event to the synth. + * + * This command should be delay-ordered with all other time/signature commands, namely + * tempo(), timeSignature(), timePosition(), and playbackState(), otherwise the behavior + * of the synth is undefined. + * + * @since 0.6.0 + * + * @param delay the delay at which the event occurs; this should be lower + * than the size of the block in the next call to renderBlock(). + * @param beatsPerMinute the new tempo, in beats per minute. + * + * @par Thread-safety constraints + * - @b RT: the function must be invoked from the Real-time thread + */ + void bpmTempo(int delay, float beatsPerMinute) noexcept; /** * @brief Send the time signature. diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 9bdeb4a8..1ecba09a 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -1397,6 +1397,12 @@ void Synth::tempo(int delay, float secondsPerBeat) noexcept impl.resources_.beatClock.setTempo(delay, secondsPerBeat); } +void Synth::bpmTempo(int delay, float beatsPerMinute) noexcept +{ + // TODO make this the main tempo function and remove the deprecated other one + return tempo(delay, 60 / beatsPerMinute); +} + void Synth::timeSignature(int delay, int beatsPerBar, int beatUnit) { Impl& impl = *impl_; diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index 2c97effe..1dbb9405 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -464,6 +464,15 @@ public: * @param secondsPerQuarter the new period of the quarter note */ void tempo(int delay, float secondsPerQuarter) noexcept; + /** + * @brief Send a tempo event to the synth + * + * @param delay the delay at which the event occurs; this should be lower than the size of + * the block in the next call to renderBlock(), and ordered with respect to + * calls to tempo(), timeSignature(), timePosition(), and playbackState(). + * @param beatsPerMinute the new tempo, in beats per minute + */ + void bpmTempo(int delay, float beatsPerMinute) noexcept; /** * @brief Send a polyphonic aftertouch event to the synth * diff --git a/src/sfizz/sfizz.cpp b/src/sfizz/sfizz.cpp index 29f9303a..e67c3adc 100644 --- a/src/sfizz/sfizz.cpp +++ b/src/sfizz/sfizz.cpp @@ -230,6 +230,11 @@ void sfz::Sfizz::tempo(int delay, float secondsPerBeat) noexcept synth->synth.tempo(delay, secondsPerBeat); } +void sfz::Sfizz::bpmTempo(int delay, float beatsPerMinute) noexcept +{ + synth->synth.bpmTempo(delay, beatsPerMinute); +} + void sfz::Sfizz::timeSignature(int delay, int beatsPerBar, int beatUnit) { synth->synth.timeSignature(delay, beatsPerBar, beatUnit); diff --git a/src/sfizz/sfizz_wrapper.cpp b/src/sfizz/sfizz_wrapper.cpp index 76400227..9f584435 100644 --- a/src/sfizz/sfizz_wrapper.cpp +++ b/src/sfizz/sfizz_wrapper.cpp @@ -170,6 +170,10 @@ void sfizz_send_tempo(sfizz_synth_t* synth, int delay, float seconds_per_quarter { synth->synth.tempo(delay, seconds_per_quarter); } +void sfizz_send_bpm_tempo(sfizz_synth_t* synth, int delay, float beats_per_minute) +{ + synth->synth.bpmTempo(delay, beats_per_minute); +} void sfizz_send_time_signature(sfizz_synth_t* synth, int delay, int beats_per_bar, int beat_unit) { synth->synth.timeSignature(delay, beats_per_bar, beat_unit);