steps in the evolution of beatbox

This commit is contained in:
Paul Davis 2018-11-08 17:55:51 -05:00
parent 52fcb1d0da
commit 8fb67e15ea
5 changed files with 59 additions and 42 deletions

View File

@ -63,8 +63,6 @@ class BeatBox : public ARDOUR::Processor {
void stop ();
void clear ();
Timecode::BBT_Time get_last_time () const;
void add_note (int number, int velocity, Timecode::BBT_Time at);
void remove_note (int number, Timecode::BBT_Time at);
void edit_note_number (int old_number, int new_number);
@ -93,10 +91,8 @@ class BeatBox : public ARDOUR::Processor {
float _tempo_request;
int _meter_beats;
int _meter_beat_type;
superclock_t superclock_cnt;
superclock_t last_start;
superclock_t last_end;
Timecode::BBT_Time last_time;
samplepos_t last_start;
samplepos_t last_end;
int _sample_rate;
superclock_t whole_note_superclocks;

View File

@ -54,7 +54,7 @@ class Step : public PBD::Stateful {
typedef boost::rational<int> DurationRatio;
Step (StepSequence&, Temporal::Beats const & beat);
Step (StepSequence&, Temporal::Beats const & beat, int notenum);
~Step ();
void set_note (double note, double velocity = 0.5, int n = 0);
@ -159,7 +159,7 @@ class StepSequence : public PBD::Stateful
rd_random = 3
};
StepSequence (StepSequencer &myseq, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size);
StepSequence (StepSequencer &myseq, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size, int notenum);
~StepSequence ();
size_t nsteps() const { return _steps.size(); }
@ -184,6 +184,9 @@ class StepSequence : public PBD::Stateful
void shift_left (size_t n = 1);
void shift_right (size_t n = 1);
size_t start_step() const { return _start; }
size_t end_step() const { return _end; }
void set_start_step (size_t);
void set_end_step (size_t);
void set_start_and_end_step (size_t, size_t);
@ -221,12 +224,14 @@ class StepSequence : public PBD::Stateful
class StepSequencer : public PBD::Stateful
{
public:
StepSequencer (TempoMap&, size_t nseqs, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size);
StepSequencer (TempoMap&, size_t nseqs, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size, int notenum);
~StepSequencer ();
size_t nsteps() const { return _sequences.front()->nsteps(); }
size_t nsequences() const { return _sequences.size(); }
int last_step() const;
StepSequence& sequence (size_t n) const;
Temporal::Beats duration() const;
@ -261,6 +266,8 @@ class StepSequencer : public PBD::Stateful
Temporal::Beats _step_size;
int32_t _start;
int32_t _end;
Temporal::Beats _last_start;
int _last_step;
};
} /* namespace */

View File

@ -53,7 +53,6 @@ BeatBox::BeatBox (Session& s)
, _tempo (-1.0)
, _meter_beats (-1)
, _meter_beat_type (-1)
, superclock_cnt (0)
, last_start (0)
, whole_note_superclocks (0)
, tick_superclocks (0)
@ -65,7 +64,7 @@ BeatBox::BeatBox (Session& s)
, remove_queue (64)
{
_display_to_user = true;
_sequencer = new StepSequencer (s.tempo_map(), 1, 8, Temporal::Beats (0, Temporal::Beats::PPQN/4), Temporal::Beats (4, 0));
_sequencer = new StepSequencer (s.tempo_map(), 12, 32, Temporal::Beats (0, Temporal::Beats::PPQN/8), Temporal::Beats (4, 0), 40);
}
BeatBox::~BeatBox ()
@ -191,13 +190,6 @@ BeatBox::state()
return node;
}
Timecode::BBT_Time
BeatBox::get_last_time() const
{
/* need mutex */
return last_time;
}
void
BeatBox::edit_note_number (int old_number, int new_number)
{

View File

@ -30,9 +30,7 @@ using namespace PBD;
using namespace ARDOUR;
using namespace std;
static int notenum = 35;
Step::Step (StepSequence &s, Temporal::Beats const & b)
Step::Step (StepSequence &s, Temporal::Beats const & b, int base_note)
: _sequence (s)
, _enabled (true)
, _nominal_beat (b)
@ -41,14 +39,12 @@ Step::Step (StepSequence &s, Temporal::Beats const & b)
, _octave_shift (0)
, _duration (1)
{
std::cerr << "step @ " << b << std::endl;
_notes[0].number = base_note;
for (size_t n = 0; n < _notes_per_step; ++n) {
for (size_t n = 1; n < _notes_per_step; ++n) {
_notes[n].number = -1;
}
/* XXX HACK XXXX */
_notes[0].number = notenum;
for (size_t n = 0; n < _parameters_per_step; ++n) {
_parameters[n].parameter = -1;
@ -98,6 +94,25 @@ Step::set_velocity (double velocity, size_t n)
}
}
void
Step::set_octave_shift (int s)
{
if (s > 4) {
s = 4;
} else if (s < -4) {
s = -4;
}
if (s == _octave_shift) {
return;
}
_octave_shift = s;
PropertyChange pc;
PropertyChanged (pc);
}
void
Step::set_chord (size_t note_cnt, double* notes)
{
@ -179,17 +194,7 @@ Step::adjust_velocity (int amt)
void
Step::adjust_octave (int amt)
{
/* this is applied to all notes at once */
_octave_shift += amt;
if (_octave_shift > 4) {
_octave_shift = 4;
} else if (_octave_shift < -4) {
_octave_shift = -4;
}
PropertyChange pc;
PropertyChanged (pc);
set_octave_shift (_octave_shift + amt);
}
bool
@ -394,20 +399,20 @@ Step::set_state (XMLNode const &, int)
/**/
StepSequence::StepSequence (StepSequencer& s, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size)
StepSequence::StepSequence (StepSequencer& s, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size, int r)
: _sequencer (s)
, _start (0)
, _end (nsteps)
, _end (nsteps - 1)
, _channel (0)
, _step_size (step_size)
, _bar_size (bar_size)
, _root (64)
, _root (r)
, _mode (MusicalMode::IonianMajor)
{
Temporal::Beats beats;
for (size_t s = 0; s < nsteps; ++s) {
_steps.push_back (new Step (*this, beats));
_steps.push_back (new Step (*this, beats, _root));
beats += step_size;
}
@ -482,14 +487,16 @@ StepSequence::set_state (XMLNode const &, int)
/**/
StepSequencer::StepSequencer (TempoMap& tmap, size_t nseqs, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size)
StepSequencer::StepSequencer (TempoMap& tmap, size_t nseqs, size_t nsteps, Temporal::Beats const & step_size, Temporal::Beats const & bar_size, int notenum)
: _tempo_map (tmap)
, _step_size (step_size)
, _start (0)
, _end (nsteps)
, _last_step (0)
{
for (size_t n = 0; n < nseqs; ++n) {
_sequences.push_back (new StepSequence (*this, nsteps, step_size, bar_size));
_sequences.push_back (new StepSequence (*this, nsteps, step_size, bar_size, notenum));
notenum++;
}
}
@ -509,9 +516,20 @@ StepSequencer::run (MidiBuffer& buf, bool running, samplepos_t start_sample, sam
(*s)->run (buf, running, start_sample, end_sample, tracker);
}
const Temporal::Beats terminal_beat = Temporal::Beats (_tempo_map.beat_at_sample (end_sample - 1));
const size_t dur_ticks = duration().to_ticks();
const size_t step_ticks = _step_size.to_ticks();
_last_step = ((terminal_beat - _last_start).to_ticks() % dur_ticks) / step_ticks;
return true;
}
int
StepSequencer::last_step () const
{
return _last_step;
}
void
StepSequencer::sync ()
{
@ -537,6 +555,7 @@ StepSequencer::duration() const
void
StepSequencer::startup (Temporal::Beats const & start, Temporal::Beats const & offset)
{
_last_start = start;
{
Glib::Threads::Mutex::Lock lm1 (_sequence_lock);
for (StepSequences::iterator s = _sequences.begin(); s != _sequences.end(); ++s) {

View File

@ -103,6 +103,9 @@ Text::height () const
void
Text::_redraw () const
{
/* XXX we should try to remove this assertion someday. Nothing wrong
with empty text.
*/
assert (!_text.empty());
assert (_canvas);
Glib::RefPtr<Pango::Context> context = _canvas->get_pango_context();