/*
Copyright (C) 2006 Paul Davis
- By Dave Robillard, 2006
+ Author: David Robillard
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+
#include "pbd/error.h"
#include "pbd/enumwriter.h"
void
MidiTrack::set_record_enabled (bool yn, void *src)
{
- if (_step_editing) {
- return;
- }
+ if (_step_editing) {
+ return;
+ }
- Track::set_record_enabled (yn, src);
+ Track::set_record_enabled (yn, src);
}
void
_diskstream_data_recorded_connection.disconnect ();
boost::shared_ptr<MidiDiskstream> mds = boost::dynamic_pointer_cast<MidiDiskstream> (ds);
- mds->DataRecorded.connect_same_thread (_diskstream_data_recorded_connection, boost::bind (&MidiTrack::diskstream_data_recorded, this, _1, _2));
+ mds->DataRecorded.connect_same_thread (
+ _diskstream_data_recorded_connection,
+ boost::bind (&MidiTrack::diskstream_data_recorded, this, _1, _2));
DiskstreamChanged (); /* EMIT SIGNAL */
}
}
}
- /* set rec-enable control *AFTER* setting up diskstream, because it may want to operate
- on the diskstream as it sets its own state
- */
+ /* set rec-enable control *AFTER* setting up diskstream, because it may
+ want to operate on the diskstream as it sets its own state
+ */
for (niter = nlist.begin(); niter != nlist.end(); ++niter){
child = *niter;
- if (child->name() == Controllable::xml_node_name && (prop = child->property ("name")) != 0) {
- if (prop->value() == X_("recenable")) {
- _rec_enable_control->set_state (*child, version);
- }
- }
+ if (child->name() == Controllable::xml_node_name && (prop = child->property ("name")) != 0) {
+ if (prop->value() == X_("recenable")) {
+ _rec_enable_control->set_state (*child, version);
+ }
+ }
}
pending_state = const_cast<XMLNode*> (&node);
if (_session.state_of_the_state() & Session::Loading) {
- _session.StateReady.connect_same_thread (*this, boost::bind (&MidiTrack::set_state_part_two, this));
+ _session.StateReady.connect_same_thread (
+ *this, boost::bind (&MidiTrack::set_state_part_two, this));
} else {
set_state_part_two ();
}
process_output_buffers (bufs, start_frame, end_frame, nframes,
(!_session.get_record_enabled() || !Config->get_do_not_record_plugins()), declick,
- (!diskstream->record_enabled() && !_session.transport_stopped()));
+ (!diskstream->record_enabled() && !_session.transport_stopped()));
}
_main_outs->flush_buffers (nframes, end_frame - start_frame - 1);
const Evoral::MIDIEvent<framepos_t> ev(*e, false);
- /* note on, since for step edit, note length is determined
- elsewhere
- */
-
- if (ev.is_note_on()) {
- /* we don't care about the time for this purpose */
- _step_edit_ring_buffer.write (0, ev.type(), ev.size(), ev.buffer());
- }
+ /* note on, since for step edit, note length is determined
+ elsewhere
+ */
+
+ if (ev.is_note_on()) {
+ /* we don't care about the time for this purpose */
+ _step_edit_ring_buffer.write (0, ev.type(), ev.size(), ev.buffer());
+ }
}
}
}
{
// Append immediate events
MidiBuffer& buf (bufs.get_midi (0));
- if (_immediate_events.read_space()) {
- DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of immediate events to deliver\n",
- name(), _immediate_events.read_space()));
- }
+ if (_immediate_events.read_space()) {
+ DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of immediate events to deliver\n",
+ name(), _immediate_events.read_space()));
+ }
_immediate_events.read (buf, 0, 1, nframes-1); // all stamps = 0
-
+
// MIDI thru: send incoming data "through" output
if (_midi_thru && _session.transport_speed() != 0.0f && _input->n_ports().n_midi()) {
buf.merge_in_place (_input->midi(0)->get_midi_buffer(nframes));
void
MidiTrack::midi_panic()
{
- DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 delivers panic data\n", name()));
+ DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 delivers panic data\n", name()));
for (uint8_t channel = 0; channel <= 0xF; channel++) {
uint8_t ev[3] = { MIDI_CMD_CONTROL | channel, MIDI_CTL_SUSTAIN, 0 };
write_immediate_event(3, ev);
void
MidiTrack::set_step_editing (bool yn)
{
- if (_session.record_status() != Session::Disabled) {
- return;
- }
+ if (_session.record_status() != Session::Disabled) {
+ return;
+ }
- if (yn != _step_editing) {
- _step_editing = yn;
- StepEditStatusChange (yn);
- }
+ if (yn != _step_editing) {
+ _step_editing = yn;
+ StepEditStatusChange (yn);
+ }
}
void
bool
MidiTrack::should_monitor () const
{
- return true;
+ return true;
}
bool
MidiTrack::send_silence () const
{
- return false;
+ return false;
}
frame_diff = frame - metric.frame();
- bbt.ticks = metric.start().ticks + (uint32_t)round((double)frame_diff / ticks_per_frame);
- uint32_t xtra_beats = bbt.ticks / (uint32_t)BBT_Time::ticks_per_beat;
- bbt.ticks %= (uint32_t)BBT_Time::ticks_per_beat;
-
- bbt.beats = metric.start().beats + xtra_beats - 1; // correction for 1-based counting, see below for matching operation.
- bbt.bars = metric.start().bars + (uint32_t)floor((double)bbt.beats / beats_per_bar);
- bbt.beats = (uint32_t)fmod((double)bbt.beats, beats_per_bar);
-
- /* if we have a fractional number of beats per bar, we see if
- we're in the last beat (the fractional one). if so, we
- round ticks appropriately and bump to the next bar. */
- double beat_fraction = beats_per_bar - floor(beats_per_bar);
- /* XXX one problem here is that I'm not sure how to handle
- fractional beats that don't evenly divide ticks_per_beat.
- If they aren't handled consistently, I would guess we'll
- continue to have strange discrepancies occuring. Perhaps
- this will also behave badly in the case of meters like
- 0.1/4, but I can't be bothered to test that.
- */
- uint32_t ticks_on_last_beat = (uint32_t)floor(BBT_Time::ticks_per_beat * beat_fraction);
-
- if (bbt.beats > (uint32_t)floor(beats_per_bar) && bbt.ticks >= ticks_on_last_beat) {
+ bbt.ticks = metric.start().ticks + (uint32_t)round((double)frame_diff / ticks_per_frame);
+ uint32_t xtra_beats = bbt.ticks / (uint32_t)BBT_Time::ticks_per_beat;
+ bbt.ticks %= (uint32_t)BBT_Time::ticks_per_beat;
+
+ bbt.beats = metric.start().beats + xtra_beats - 1; // correction for 1-based counting, see below for matching operation.
+ bbt.bars = metric.start().bars + (uint32_t)floor((double)bbt.beats / beats_per_bar);
+ bbt.beats = (uint32_t)fmod((double)bbt.beats, beats_per_bar);
+
+ /* if we have a fractional number of beats per bar, we see if
+ we're in the last beat (the fractional one). if so, we
+ round ticks appropriately and bump to the next bar. */
+ double beat_fraction = beats_per_bar - floor(beats_per_bar);
+ /* XXX one problem here is that I'm not sure how to handle
+ fractional beats that don't evenly divide ticks_per_beat.
+ If they aren't handled consistently, I would guess we'll
+ continue to have strange discrepancies occuring. Perhaps
+ this will also behave badly in the case of meters like
+ 0.1/4, but I can't be bothered to test that.
+ */
+ uint32_t ticks_on_last_beat = (uint32_t)floor(BBT_Time::ticks_per_beat * beat_fraction);
+
+ if (bbt.beats > (uint32_t)floor(beats_per_bar) && bbt.ticks >= ticks_on_last_beat) {
bbt.ticks -= ticks_on_last_beat;
bbt.beats = 0;
bbt.bars++;
- }
+ }
- bbt.beats++; // correction for 1-based counting, see above for matching operation.
+ bbt.beats++; // correction for 1-based counting, see above for matching operation.
// cerr << "-----\t RETURN " << bbt << endl;
}
framecnt_t
TempoMap::count_frames_between (const BBT_Time& start, const BBT_Time& end) const
{
- /* for this to work with fractional measure types, start and end have to be "legal" BBT types,
- that means that the beats and ticks should be inside a bar
+ /* for this to work with fractional measure types, start and end have to be
+ "legal" BBT types, that means that the beats and ticks should be inside
+ a bar
*/
framecnt_t frames = 0;
framecnt_t
TempoMap::count_frames_between_metrics (const Meter& meter, const Tempo& tempo, const BBT_Time& start, const BBT_Time& end) const
{
- /* this is used in timestamping the metrics by actually counting the beats */
+ /* this is used in timestamping the metrics by actually counting the beats */
framecnt_t frames = 0;
uint32_t bar = start.bars;
TempoMetric metric = metric_at(result);
beats_per_bar = metric.meter().beats_per_bar();
-
-
- /*reduce things to legal bbt values
- we have to handle possible fractional=shorter beats at the end of measures
- and things like 0|11|9000 as a duration in a 4.5/4 measure
- the musical decision is that the fractional beat is also a beat , although a shorter one
+ /* Reduce things to legal bbt values we have to handle possible
+ fractional=shorter beats at the end of measures and things like 0|11|9000
+ as a duration in a 4.5/4 measure the musical decision is that the
+ fractional beat is also a beat , although a shorter one
*/
-
if (dir >= 0) {
result.beats = when.beats + bbt.beats;
result.ticks = when.ticks + bbt.ticks;
beats_per_bar = metric.meter().beats_per_bar();
}
- /*we now counted the beats and landed in the target measure, now deal with ticks
- this seems complicated, but we want to deal with the corner case of a sequence of time signatures like 0.2/4-0.7/4
- and with request like bbt = 3|2|9000 ,so we repeat the same loop but add ticks
+
+ /* We now counted the beats and landed in the target measure, now deal
+ with ticks this seems complicated, but we want to deal with the
+ corner case of a sequence of time signatures like 0.2/4-0.7/4 and
+ with request like bbt = 3|2|9000 ,so we repeat the same loop but add
+ ticks
*/
/* of course gtk_ardour only allows bar with at least 1.0 beats .....
} else {
uint32_t b = bbt.beats;
- /* count beats */
+ /* count beats */
while( b > when.beats ) {
result.bars = max(1U,result.bars-- ) ;
}
result.beats = when.beats - b;
- /*count ticks */
+ /* count ticks */
if (bbt.ticks <= when.ticks) {
result.ticks = when.ticks - bbt.ticks;
framepos_t
TempoMap::round_to_bar (framepos_t fr, int dir)
{
- {
- Glib::RWLock::ReaderLock lm (lock);
+ {
+ Glib::RWLock::ReaderLock lm (lock);
return round_to_type (fr, dir, Bar);
}
}
framepos_t
TempoMap::round_to_beat (framepos_t fr, int dir)
{
- {
- Glib::RWLock::ReaderLock lm (lock);
+ {
+ Glib::RWLock::ReaderLock lm (lock);
return round_to_type (fr, dir, Beat);
}
}
difference = mod;
}
- try {
- the_beat = bbt_subtract (the_beat, BBT_Time (0, 0, difference));
- } catch (...) {
- /* can't go backwards from wherever pos is, so just return it */
- return fr;
- }
-
+ try {
+ the_beat = bbt_subtract (the_beat, BBT_Time (0, 0, difference));
+ } catch (...) {
+ /* can't go backwards from wherever pos is, so just return it */
+ return fr;
+ }
} else {
/* round to nearest */
XMLNode *root = new XMLNode ("TempoMap");
{
- Glib::RWLock::ReaderLock lm (lock);
+ Glib::RWLock::ReaderLock lm (lock);
for (i = metrics->begin(); i != metrics->end(); ++i) {
- root->add_child_nocopy ((*i)->get_state());
+ root->add_child_nocopy ((*i)->get_state());
}
}
const MeterSection* m;
const TempoSection* tempo;
const TempoSection* t;
- framecnt_t frames_per_beat;
+ framecnt_t frames_per_beat;
meter = &first_meter ();
tempo = &first_tempo ();
- assert (meter);
- assert (tempo);
+ assert (meter);
+ assert (tempo);
/* find the starting metrics for tempo & meter */
for (i = metrics->begin(); i != metrics->end(); ++i) {
-
+
if ((*i)->frame() > pos) {
break;
}
-
+
if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
tempo = t;
} else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
checking for a new metric on every beat.
*/
- frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
+ frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
- while (op.bars) {
+ while (op.bars) {
- pos += llrint (frames_per_beat * meter->beats_per_bar());
+ pos += llrint (frames_per_beat * meter->beats_per_bar());
op.bars--;
/* check if we need to use a new metric section: has adding frames moved us
to or after the start of the next metric section? in which case, use it.
*/
-
- if (i != metrics->end()) {
- if ((*i)->frame() <= pos) {
- if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
- tempo = t;
- } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
- meter = m;
- }
- ++i;
- frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
+ if (i != metrics->end()) {
+ if ((*i)->frame() <= pos) {
- }
+ if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
+ tempo = t;
+ } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
+ meter = m;
+ }
+ ++i;
+ frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
+
+ }
}
- }
+ }
while (op.beats) {
/* given the current meter, have we gone past the end of the bar ? */
-
- pos += frames_per_beat;
+
+ pos += frames_per_beat;
op.beats--;
/* check if we need to use a new metric section: has adding frames moved us
to or after the start of the next metric section? in which case, use it.
*/
-
- if (i != metrics->end()) {
- if ((*i)->frame() <= pos) {
-
- if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
- tempo = t;
- } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
- meter = m;
- }
- ++i;
- frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
- }
- }
- }
-
- if (op.ticks) {
- if (op.ticks >= BBT_Time::ticks_per_beat) {
- pos += frames_per_beat;
- pos += llrint (frames_per_beat * ((op.ticks % (uint32_t) BBT_Time::ticks_per_beat) / (double) BBT_Time::ticks_per_beat));
- } else {
- pos += llrint (frames_per_beat * (op.ticks / (double) BBT_Time::ticks_per_beat));
- }
- }
+
+ if (i != metrics->end()) {
+ if ((*i)->frame() <= pos) {
+
+ if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
+ tempo = t;
+ } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
+ meter = m;
+ }
+ ++i;
+ frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
+ }
+ }
+ }
+
+ if (op.ticks) {
+ if (op.ticks >= BBT_Time::ticks_per_beat) {
+ pos += frames_per_beat;
+ pos += llrint (frames_per_beat * ((op.ticks % (uint32_t) BBT_Time::ticks_per_beat) / (double) BBT_Time::ticks_per_beat));
+ } else {
+ pos += llrint (frames_per_beat * (op.ticks / (double) BBT_Time::ticks_per_beat));
+ }
+ }
return pos;
}
TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const
{
Metrics::const_iterator i;
- double beats = 0;
+ double beats = 0;
const MeterSection* meter;
const MeterSection* m;
const TempoSection* tempo;
const TempoSection* t;
- double frames_per_beat;
+ double frames_per_beat;
- double ddist = distance;
- double dpos = pos;
+ double ddist = distance;
+ double dpos = pos;
meter = &first_meter ();
tempo = &first_tempo ();
- assert (meter);
- assert (tempo);
+ assert (meter);
+ assert (tempo);
/* find the starting metrics for tempo & meter */
for (i = metrics->begin(); i != metrics->end(); ++i) {
-
+
if ((*i)->frame() > pos) {
break;
}
-
+
if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
tempo = t;
} else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
checking for a new metric on every beat.
*/
- frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
-
- while (ddist > 0) {
+ frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
+
+ while (ddist > 0) {
- /* if we're nearly at the end, but have a fractional beat left,
- compute the fraction and then its all over
- */
+ /* if we're nearly at the end, but have a fractional beat left,
+ compute the fraction and then its all over
+ */
- if (ddist < frames_per_beat) {
- beats += ddist / frames_per_beat;
- break;
- }
+ if (ddist < frames_per_beat) {
+ beats += ddist / frames_per_beat;
+ break;
+ }
- /* walk one beat */
+ /* walk one beat */
- ddist -= frames_per_beat;
- dpos += frames_per_beat;
- beats += 1.0;
+ ddist -= frames_per_beat;
+ dpos += frames_per_beat;
+ beats += 1.0;
/* check if we need to use a new metric section: has adding frames moved us
to or after the start of the next metric section? in which case, use it.
*/
-
- if (i != metrics->end()) {
- if ((*i)->frame() <= (framepos_t) dpos) {
- if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
- tempo = t;
- } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
- meter = m;
- }
- ++i;
- frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
- }
+ if (i != metrics->end()) {
+ if ((*i)->frame() <= (framepos_t) dpos) {
+
+ if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
+ tempo = t;
+ } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
+ meter = m;
+ }
+ ++i;
+ frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
+ }
}
- }
+ }
return beats;
}