, _running (false)
, _measures (2)
, _tempo (120)
+ , _tempo_request (0)
, _meter_beats (4)
, _meter_beat_type (4)
, _input (0)
}
void
-BeatBox::start ()
+BeatBox::compute_tempo_clocks ()
{
- /* compute tempo, beat steps etc. */
-
- /*
- 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;
+}
+
+void
+BeatBox::start ()
+{
+ /* compute tempo, beat steps etc. */
+
+ compute_tempo_clocks ();
/* we can start */
_start_requested = false;
}
+void
+BeatBox::set_tempo (float bpm)
+{
+ _tempo_request = bpm;
+}
+
int
BeatBox::process (int nsamples)
{
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_end = process_start + superclocks;
const superclock_t loop_length = _measures * measure_superclocks;
event_pool.pop_back ();
e->time = quantized_time;
+ e->whole_note_superclocks = whole_note_superclocks;
e->size = in_event.size;
memcpy (e->buf, in_event.buffer, in_event.size);
bool _running;
int _measures;
float _tempo;
+ float _tempo_request;
int _meter_beats;
int _meter_beat_type;
jack_port_t* _input;
struct Event {
superclock_t time;
+ superclock_t whole_note_superclocks;
size_t size;
unsigned char buf[24];
typedef std::vector<Event*> EventPool;
EventPool event_pool;
+
+ void compute_tempo_clocks ();
};
, quantize_whole (quantize_group, "Whole")
, play_button ("Run")
, 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_32nd.signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &BBGUI::set_quantize), 32));
misc_button_box.pack_start (play_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 (quantize_button_box, true, true);
window.add (global_vbox);
main.run ();
}
+void
+BBGUI::tempo_changed ()
+{
+ float t = tempo_adjustment.get_value();
+ bbox->set_tempo (t);
+}
+
void
BBGUI::set_quantize (int divisor)
{
Gtk::ToggleButton play_button;
Gtk::Button clear_button;
+ Gtk::Adjustment tempo_adjustment;
+ Gtk::SpinButton tempo_spinner;
+
Gtk::VBox global_vbox;
Gtk::VBox quantize_button_box;
Gtk::HBox misc_button_box;
+
void set_quantize (int divisor);
void toggle_play ();
void clear ();
+ void tempo_changed ();
};
#endif /* __bb_gui_h__ */