mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-06 14:54:56 +01:00
add tempo adjustment
This commit is contained in:
parent
be03ec370e
commit
ab6ab082dd
4 changed files with 51 additions and 9 deletions
|
|
@ -144,6 +144,7 @@ BeatBox::BeatBox (int sr)
|
||||||
, _running (false)
|
, _running (false)
|
||||||
, _measures (2)
|
, _measures (2)
|
||||||
, _tempo (120)
|
, _tempo (120)
|
||||||
|
, _tempo_request (0)
|
||||||
, _meter_beats (4)
|
, _meter_beats (4)
|
||||||
, _meter_beat_type (4)
|
, _meter_beat_type (4)
|
||||||
, _input (0)
|
, _input (0)
|
||||||
|
|
@ -182,20 +183,20 @@ BeatBox::register_ports (jack_client_t* jack)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BeatBox::compute_tempo_clocks ()
|
||||||
|
{
|
||||||
|
whole_note_superclocks = (superclock_ticks_per_second * 60) / (_tempo / _meter_beat_type);
|
||||||
|
beat_superclocks = whole_note_superclocks / _meter_beat_type;
|
||||||
|
measure_superclocks = beat_superclocks * _meter_beats;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BeatBox::start ()
|
BeatBox::start ()
|
||||||
{
|
{
|
||||||
/* compute tempo, beat steps etc. */
|
/* compute tempo, beat steps etc. */
|
||||||
|
|
||||||
/*
|
compute_tempo_clocks ();
|
||||||
superclocks_per_minute = superclock_ticks_per_second * 60;
|
|
||||||
beats_per_minute = _tempo;
|
|
||||||
whole_notes_per_minute = beats_per_minute / _meter_beat_type;
|
|
||||||
*/
|
|
||||||
|
|
||||||
whole_note_superclocks = (superclock_ticks_per_second * 60) / (_tempo / _meter_beat_type);
|
|
||||||
beat_superclocks = whole_note_superclocks / _meter_beat_type;
|
|
||||||
measure_superclocks = beat_superclocks * _meter_beats;
|
|
||||||
|
|
||||||
/* we can start */
|
/* we can start */
|
||||||
|
|
||||||
|
|
@ -208,6 +209,12 @@ BeatBox::stop ()
|
||||||
_start_requested = false;
|
_start_requested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BeatBox::set_tempo (float bpm)
|
||||||
|
{
|
||||||
|
_tempo_request = bpm;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
BeatBox::process (int nsamples)
|
BeatBox::process (int nsamples)
|
||||||
{
|
{
|
||||||
|
|
@ -230,6 +237,18 @@ BeatBox::process (int nsamples)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_tempo_request) {
|
||||||
|
double ratio = _tempo / _tempo_request;
|
||||||
|
_tempo = _tempo_request;
|
||||||
|
_tempo_request = 0;
|
||||||
|
|
||||||
|
compute_tempo_clocks ();
|
||||||
|
|
||||||
|
for (Events::iterator ee = _current_events.begin(); ee != _current_events.end(); ++ee) {
|
||||||
|
(*ee)->time = llrintf ((*ee)->time * ratio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
superclock_t process_start = superclock_cnt - last_start;
|
superclock_t process_start = superclock_cnt - last_start;
|
||||||
superclock_t process_end = process_start + superclocks;
|
superclock_t process_end = process_start + superclocks;
|
||||||
const superclock_t loop_length = _measures * measure_superclocks;
|
const superclock_t loop_length = _measures * measure_superclocks;
|
||||||
|
|
@ -324,6 +343,7 @@ BeatBox::process (int nsamples)
|
||||||
event_pool.pop_back ();
|
event_pool.pop_back ();
|
||||||
|
|
||||||
e->time = quantized_time;
|
e->time = quantized_time;
|
||||||
|
e->whole_note_superclocks = whole_note_superclocks;
|
||||||
e->size = in_event.size;
|
e->size = in_event.size;
|
||||||
memcpy (e->buf, in_event.buffer, in_event.size);
|
memcpy (e->buf, in_event.buffer, in_event.size);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ class BeatBox {
|
||||||
bool _running;
|
bool _running;
|
||||||
int _measures;
|
int _measures;
|
||||||
float _tempo;
|
float _tempo;
|
||||||
|
float _tempo_request;
|
||||||
int _meter_beats;
|
int _meter_beats;
|
||||||
int _meter_beat_type;
|
int _meter_beat_type;
|
||||||
jack_port_t* _input;
|
jack_port_t* _input;
|
||||||
|
|
@ -60,6 +61,7 @@ class BeatBox {
|
||||||
|
|
||||||
struct Event {
|
struct Event {
|
||||||
superclock_t time;
|
superclock_t time;
|
||||||
|
superclock_t whole_note_superclocks;
|
||||||
size_t size;
|
size_t size;
|
||||||
unsigned char buf[24];
|
unsigned char buf[24];
|
||||||
|
|
||||||
|
|
@ -77,6 +79,8 @@ class BeatBox {
|
||||||
|
|
||||||
typedef std::vector<Event*> EventPool;
|
typedef std::vector<Event*> EventPool;
|
||||||
EventPool event_pool;
|
EventPool event_pool;
|
||||||
|
|
||||||
|
void compute_tempo_clocks ();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ BBGUI::BBGUI (int* argc, char** argv[], jack_client_t* j, BeatBox* bb)
|
||||||
, quantize_whole (quantize_group, "Whole")
|
, quantize_whole (quantize_group, "Whole")
|
||||||
, play_button ("Run")
|
, play_button ("Run")
|
||||||
, clear_button ("Clear")
|
, clear_button ("Clear")
|
||||||
|
, tempo_adjustment (bb->tempo(), 1, 300, 1, 10)
|
||||||
|
, tempo_spinner (tempo_adjustment)
|
||||||
{
|
{
|
||||||
quantize_off.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &BBGUI::set_quantize), 0));
|
quantize_off.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &BBGUI::set_quantize), 0));
|
||||||
quantize_32nd.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &BBGUI::set_quantize), 32));
|
quantize_32nd.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &BBGUI::set_quantize), 32));
|
||||||
|
|
@ -37,6 +39,10 @@ BBGUI::BBGUI (int* argc, char** argv[], jack_client_t* j, BeatBox* bb)
|
||||||
misc_button_box.pack_start (play_button);
|
misc_button_box.pack_start (play_button);
|
||||||
misc_button_box.pack_start (clear_button);
|
misc_button_box.pack_start (clear_button);
|
||||||
|
|
||||||
|
tempo_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &BBGUI::tempo_changed));
|
||||||
|
|
||||||
|
misc_button_box.pack_start (tempo_spinner);
|
||||||
|
|
||||||
global_vbox.pack_start (misc_button_box);
|
global_vbox.pack_start (misc_button_box);
|
||||||
global_vbox.pack_start (quantize_button_box, true, true);
|
global_vbox.pack_start (quantize_button_box, true, true);
|
||||||
window.add (global_vbox);
|
window.add (global_vbox);
|
||||||
|
|
@ -54,6 +60,13 @@ BBGUI::run ()
|
||||||
main.run ();
|
main.run ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
BBGUI::tempo_changed ()
|
||||||
|
{
|
||||||
|
float t = tempo_adjustment.get_value();
|
||||||
|
bbox->set_tempo (t);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BBGUI::set_quantize (int divisor)
|
BBGUI::set_quantize (int divisor)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,18 @@ class BBGUI {
|
||||||
Gtk::ToggleButton play_button;
|
Gtk::ToggleButton play_button;
|
||||||
Gtk::Button clear_button;
|
Gtk::Button clear_button;
|
||||||
|
|
||||||
|
Gtk::Adjustment tempo_adjustment;
|
||||||
|
Gtk::SpinButton tempo_spinner;
|
||||||
|
|
||||||
Gtk::VBox global_vbox;
|
Gtk::VBox global_vbox;
|
||||||
Gtk::VBox quantize_button_box;
|
Gtk::VBox quantize_button_box;
|
||||||
Gtk::HBox misc_button_box;
|
Gtk::HBox misc_button_box;
|
||||||
|
|
||||||
|
|
||||||
void set_quantize (int divisor);
|
void set_quantize (int divisor);
|
||||||
void toggle_play ();
|
void toggle_play ();
|
||||||
void clear ();
|
void clear ();
|
||||||
|
void tempo_changed ();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __bb_gui_h__ */
|
#endif /* __bb_gui_h__ */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue