13
0

Fix more broken whitespace.

git-svn-id: svn://localhost/ardour2/branches/3.0@9152 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2011-03-15 01:16:24 +00:00
parent 148c1f805b
commit be3002c239
7 changed files with 215 additions and 210 deletions

View File

@ -100,9 +100,9 @@ MidiBuffer::read_from (const Buffer& src, framecnt_t nframes, framecnt_t dst_off
if (ev.time() >= src_offset && ev.time() < (nframes+src_offset)) { if (ev.time() >= src_offset && ev.time() < (nframes+src_offset)) {
push_back (ev); push_back (ev);
} else { } else {
cerr << "MIDI event @ " << ev.time() << " skipped, not within range " << src_offset << " .. " cerr << "MIDI event @ " << ev.time() << " skipped, not within range "
<< (nframes + src_offset) << endl; << src_offset << " .. " << (nframes + src_offset) << endl;
} }
} }
_silent = src.silent(); _silent = src.silent();
@ -137,7 +137,7 @@ MidiBuffer::push_back(const Evoral::MIDIEvent<TimeType>& ev)
cerr << "MidiBuffer::push_back failed (buffer is full)" << endl; cerr << "MidiBuffer::push_back failed (buffer is full)" << endl;
return false; return false;
} }
if (!Evoral::midi_event_is_valid(ev.buffer(), ev.size())) { if (!Evoral::midi_event_is_valid(ev.buffer(), ev.size())) {
cerr << "WARNING: MidiBuffer ignoring illegal MIDI event" << endl; cerr << "WARNING: MidiBuffer ignoring illegal MIDI event" << endl;
return false; return false;
@ -159,16 +159,16 @@ MidiBuffer::push_back(TimeType time, size_t size, const uint8_t* data)
#ifndef NDEBUG #ifndef NDEBUG
if (DEBUG::MidiIO & PBD::debug_bits) { if (DEBUG::MidiIO & PBD::debug_bits) {
DEBUG_STR_DECL(a); DEBUG_STR_DECL(a);
DEBUG_STR_APPEND(a, string_compose ("midibuffer %1 push event @ %2 sz %3 ", this, time, size)); DEBUG_STR_APPEND(a, string_compose ("midibuffer %1 push event @ %2 sz %3 ", this, time, size));
for (size_t i=0; i < size; ++i) { for (size_t i=0; i < size; ++i) {
DEBUG_STR_APPEND(a,hex); DEBUG_STR_APPEND(a,hex);
DEBUG_STR_APPEND(a,"0x"); DEBUG_STR_APPEND(a,"0x");
DEBUG_STR_APPEND(a,(int)data[i]); DEBUG_STR_APPEND(a,(int)data[i]);
DEBUG_STR_APPEND(a,' '); DEBUG_STR_APPEND(a,' ');
} }
DEBUG_STR_APPEND(a,'\n'); DEBUG_STR_APPEND(a,'\n');
DEBUG_TRACE (DEBUG::MidiIO, DEBUG_STR(a).str()); DEBUG_TRACE (DEBUG::MidiIO, DEBUG_STR(a).str());
} }
#endif #endif
@ -324,7 +324,7 @@ MidiBuffer::merge_in_place(const MidiBuffer &other)
++them; ++them;
} }
#if 0 #if 0
if (us != end()) if (us != end())
cerr << "us @ " << (*us).time() << endl; cerr << "us @ " << (*us).time() << endl;
if (them != other.end()) if (them != other.end())

View File

@ -171,7 +171,7 @@ MidiDiskstream::non_realtime_input_change ()
get_input_sources (); get_input_sources ();
set_capture_offset (); set_capture_offset ();
set_align_style_from_io (); set_align_style_from_io ();
input_change_pending.type = IOChange::NoChange; input_change_pending.type = IOChange::NoChange;
@ -882,8 +882,8 @@ MidiDiskstream::do_flush (RunContext /*context*/, bool force_flush)
assert(!destructive()); assert(!destructive());
if (record_enabled() && if (record_enabled() &&
((_session.transport_frame() - _last_flush_frame > disk_io_chunk_frames) || ((_session.transport_frame() - _last_flush_frame > disk_io_chunk_frames) ||
force_flush)) { force_flush)) {
if ((!_write_source) || _write_source->midi_write (*_capture_buf, get_capture_start_frame (0), to_write) != to_write) { if ((!_write_source) || _write_source->midi_write (*_capture_buf, get_capture_start_frame (0), to_write) != to_write) {
error << string_compose(_("MidiDiskstream %1: cannot write to disk"), _id) << endmsg; error << string_compose(_("MidiDiskstream %1: cannot write to disk"), _id) << endmsg;
return -1; return -1;
@ -1255,9 +1255,9 @@ MidiDiskstream::set_state (const XMLNode& node, int version)
} }
} }
if (Diskstream::set_state (node, version)) { if (Diskstream::set_state (node, version)) {
return -1; return -1;
} }
ChannelMode channel_mode = AllChannels; ChannelMode channel_mode = AllChannels;
if ((prop = node.property ("channel-mode")) != 0) { if ((prop = node.property ("channel-mode")) != 0) {
@ -1273,9 +1273,9 @@ MidiDiskstream::set_state (const XMLNode& node, int version)
} }
if (capture_pending_node) { if (capture_pending_node) {
use_pending_capture_data (*capture_pending_node); use_pending_capture_data (*capture_pending_node);
} }
set_channel_mode (channel_mode, channel_mask); set_channel_mode (channel_mode, channel_mask);
@ -1383,9 +1383,9 @@ MidiDiskstream::set_align_style_from_io ()
{ {
bool have_physical = false; bool have_physical = false;
if (_alignment_choice != Automatic) { if (_alignment_choice != Automatic) {
return; return;
} }
if (_io == 0) { if (_io == 0) {
return; return;

View File

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2007 Paul Davis Copyright (C) 2007 Paul Davis
Author: Dave Robillard Author: David Robillard
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -164,7 +164,7 @@ MidiModel::NoteDiffCommand::change (const NotePtr note, Property prop,
assert (note); assert (note);
NoteChange change; NoteChange change;
switch (prop) { switch (prop) {
case NoteNumber: case NoteNumber:
if (new_value == note->note()) { if (new_value == note->note()) {
@ -1345,7 +1345,7 @@ MidiModel::write_to (boost::shared_ptr<MidiSource> source)
source->mark_streaming_write_completed(); source->mark_streaming_write_completed();
set_edited(false); set_edited(false);
return true; return true;
} }
@ -1375,7 +1375,7 @@ MidiModel::sync_to_source ()
ms->mark_streaming_write_completed (); ms->mark_streaming_write_completed ();
set_edited (false); set_edited (false);
return true; return true;
} }
@ -1606,8 +1606,9 @@ MidiModel::resolve_overlaps_unlocked (const NotePtr note, void* arg)
continue; continue;
} }
DEBUG_TRACE (DEBUG::Sequence, string_compose ("\toverlap is %1 for (%2,%3) vs (%4,%5)\n", enum_2_string(overlap), DEBUG_TRACE (DEBUG::Sequence, string_compose (
sa, ea, sb, eb)); "\toverlap is %1 for (%2,%3) vs (%4,%5)\n",
enum_2_string(overlap), sa, ea, sb, eb));
if (insert_merge_policy() == InsertMergeReject) { if (insert_merge_policy() == InsertMergeReject) {
DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 just reject\n", this)); DEBUG_TRACE (DEBUG::Sequence, string_compose ("%1 just reject\n", this));
@ -1762,7 +1763,7 @@ MidiModel::insert_merge_policy () const
return ms->session().config.get_insert_merge_policy (); return ms->session().config.get_insert_merge_policy ();
} }
void void
MidiModel::set_midi_source (boost::shared_ptr<MidiSource> s) MidiModel::set_midi_source (boost::shared_ptr<MidiSource> s)
{ {

View File

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2006 Paul Davis Copyright (C) 2006 Paul Davis
Written by Dave Robillard, 2006 Author: David Robillard
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -426,7 +426,7 @@ MidiPlaylist::region_changed (const PBD::PropertyChange& what_changed, boost::sh
} }
PBD::PropertyChange our_interests; PBD::PropertyChange our_interests;
our_interests.add (Properties::midi_data); our_interests.add (Properties::midi_data);
bool parent_wants_notify = Playlist::region_changed (what_changed, region); bool parent_wants_notify = Playlist::region_changed (what_changed, region);

View File

@ -41,7 +41,7 @@ MidiPort::~MidiPort()
void void
MidiPort::cycle_start (pframes_t nframes) MidiPort::cycle_start (pframes_t nframes)
{ {
Port::cycle_start (nframes); Port::cycle_start (nframes);
_buffer->clear (); _buffer->clear ();
@ -76,20 +76,20 @@ MidiPort::get_midi_buffer (pframes_t nframes)
jack_midi_event_get (&ev, jack_buffer, i); jack_midi_event_get (&ev, jack_buffer, i);
if (ev.buffer[0] == 0xfe) { if (ev.buffer[0] == 0xfe) {
/* throw away active sensing */ /* throw away active sensing */
continue; continue;
} }
/* check that the event is in the acceptable time range */ /* check that the event is in the acceptable time range */
if ((ev.time >= (_global_port_buffer_offset + _port_buffer_offset)) && if ((ev.time >= (_global_port_buffer_offset + _port_buffer_offset)) &&
(ev.time < (_global_port_buffer_offset + _port_buffer_offset + nframes))) { (ev.time < (_global_port_buffer_offset + _port_buffer_offset + nframes))) {
_buffer->push_back (ev); _buffer->push_back (ev);
} else { } else {
cerr << "Dropping incoming MIDI at time " << ev.time << "; offset=" cerr << "Dropping incoming MIDI at time " << ev.time << "; offset="
<< _global_port_buffer_offset << " limit=" << _global_port_buffer_offset << " limit="
<< (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n"; << (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n";
} }
} }
@ -145,13 +145,13 @@ MidiPort::flush_buffers (pframes_t nframes, framepos_t time)
if (ev.time() >= _global_port_buffer_offset + _port_buffer_offset) { if (ev.time() >= _global_port_buffer_offset + _port_buffer_offset) {
if (jack_midi_event_write (jack_buffer, (jack_nframes_t) ev.time(), ev.buffer(), ev.size()) != 0) { if (jack_midi_event_write (jack_buffer, (jack_nframes_t) ev.time(), ev.buffer(), ev.size()) != 0) {
cerr << "write failed, drop flushed note off on the floor, time " cerr << "write failed, drop flushed note off on the floor, time "
<< ev.time() << " > " << _global_port_buffer_offset + _port_buffer_offset << endl; << ev.time() << " > " << _global_port_buffer_offset + _port_buffer_offset << endl;
} }
} else { } else {
cerr << "drop flushed event on the floor, time " << ev.time() cerr << "drop flushed event on the floor, time " << ev.time()
<< " < " << _global_port_buffer_offset + _port_buffer_offset << endl; << " < " << _global_port_buffer_offset + _port_buffer_offset << endl;
} }
} }
} }
} }

View File

@ -1,6 +1,6 @@
/* /*
Copyright (C) 2006 Paul Davis Copyright (C) 2006 Paul Davis
By Dave Robillard, 2006 Author: David Robillard
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -16,6 +16,7 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/enumwriter.h" #include "pbd/enumwriter.h"
@ -87,11 +88,11 @@ MidiTrack::use_new_diskstream ()
void void
MidiTrack::set_record_enabled (bool yn, void *src) MidiTrack::set_record_enabled (bool yn, void *src)
{ {
if (_step_editing) { if (_step_editing) {
return; return;
} }
Track::set_record_enabled (yn, src); Track::set_record_enabled (yn, src);
} }
void void
@ -107,7 +108,9 @@ MidiTrack::set_diskstream (boost::shared_ptr<Diskstream> ds)
_diskstream_data_recorded_connection.disconnect (); _diskstream_data_recorded_connection.disconnect ();
boost::shared_ptr<MidiDiskstream> mds = boost::dynamic_pointer_cast<MidiDiskstream> (ds); 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 */ DiskstreamChanged (); /* EMIT SIGNAL */
} }
@ -165,24 +168,25 @@ MidiTrack::_set_state (const XMLNode& node, int version, bool call_base)
} }
} }
/* set rec-enable control *AFTER* setting up diskstream, because it may want to operate /* set rec-enable control *AFTER* setting up diskstream, because it may
on the diskstream as it sets its own state want to operate on the diskstream as it sets its own state
*/ */
for (niter = nlist.begin(); niter != nlist.end(); ++niter){ for (niter = nlist.begin(); niter != nlist.end(); ++niter){
child = *niter; child = *niter;
if (child->name() == Controllable::xml_node_name && (prop = child->property ("name")) != 0) { if (child->name() == Controllable::xml_node_name && (prop = child->property ("name")) != 0) {
if (prop->value() == X_("recenable")) { if (prop->value() == X_("recenable")) {
_rec_enable_control->set_state (*child, version); _rec_enable_control->set_state (*child, version);
} }
} }
} }
pending_state = const_cast<XMLNode*> (&node); pending_state = const_cast<XMLNode*> (&node);
if (_session.state_of_the_state() & Session::Loading) { 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 { } else {
set_state_part_two (); set_state_part_two ();
} }
@ -380,7 +384,7 @@ MidiTrack::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame
process_output_buffers (bufs, start_frame, end_frame, nframes, process_output_buffers (bufs, start_frame, end_frame, nframes,
(!_session.get_record_enabled() || !Config->get_do_not_record_plugins()), declick, (!_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); _main_outs->flush_buffers (nframes, end_frame - start_frame - 1);
@ -429,14 +433,14 @@ MidiTrack::push_midi_input_to_step_edit_ringbuffer (framecnt_t nframes)
const Evoral::MIDIEvent<framepos_t> ev(*e, false); const Evoral::MIDIEvent<framepos_t> ev(*e, false);
/* note on, since for step edit, note length is determined /* note on, since for step edit, note length is determined
elsewhere elsewhere
*/ */
if (ev.is_note_on()) { if (ev.is_note_on()) {
/* we don't care about the time for this purpose */ /* we don't care about the time for this purpose */
_step_edit_ring_buffer.write (0, ev.type(), ev.size(), ev.buffer()); _step_edit_ring_buffer.write (0, ev.type(), ev.size(), ev.buffer());
} }
} }
} }
} }
@ -446,12 +450,12 @@ MidiTrack::write_out_of_band_data (BufferSet& bufs, framepos_t /*start*/, framep
{ {
// Append immediate events // Append immediate events
MidiBuffer& buf (bufs.get_midi (0)); MidiBuffer& buf (bufs.get_midi (0));
if (_immediate_events.read_space()) { if (_immediate_events.read_space()) {
DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of immediate events to deliver\n", DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of immediate events to deliver\n",
name(), _immediate_events.read_space())); name(), _immediate_events.read_space()));
} }
_immediate_events.read (buf, 0, 1, nframes-1); // all stamps = 0 _immediate_events.read (buf, 0, 1, nframes-1); // all stamps = 0
// MIDI thru: send incoming data "through" output // MIDI thru: send incoming data "through" output
if (_midi_thru && _session.transport_speed() != 0.0f && _input->n_ports().n_midi()) { if (_midi_thru && _session.transport_speed() != 0.0f && _input->n_ports().n_midi()) {
buf.merge_in_place (_input->midi(0)->get_midi_buffer(nframes)); buf.merge_in_place (_input->midi(0)->get_midi_buffer(nframes));
@ -505,7 +509,7 @@ MidiTrack::set_note_mode (NoteMode m)
void void
MidiTrack::midi_panic() 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++) { for (uint8_t channel = 0; channel <= 0xF; channel++) {
uint8_t ev[3] = { MIDI_CMD_CONTROL | channel, MIDI_CTL_SUSTAIN, 0 }; uint8_t ev[3] = { MIDI_CMD_CONTROL | channel, MIDI_CTL_SUSTAIN, 0 };
write_immediate_event(3, ev); write_immediate_event(3, ev);
@ -590,14 +594,14 @@ MidiTrack::MidiControl::set_value(double val)
void void
MidiTrack::set_step_editing (bool yn) MidiTrack::set_step_editing (bool yn)
{ {
if (_session.record_status() != Session::Disabled) { if (_session.record_status() != Session::Disabled) {
return; return;
} }
if (yn != _step_editing) { if (yn != _step_editing) {
_step_editing = yn; _step_editing = yn;
StepEditStatusChange (yn); StepEditStatusChange (yn);
} }
} }
void void
@ -651,11 +655,11 @@ MidiTrack::diskstream_data_recorded (boost::shared_ptr<MidiBuffer> buf, boost::w
bool bool
MidiTrack::should_monitor () const MidiTrack::should_monitor () const
{ {
return true; return true;
} }
bool bool
MidiTrack::send_silence () const MidiTrack::send_silence () const
{ {
return false; return false;
} }

View File

@ -840,34 +840,34 @@ TempoMap::bbt_time_with_metric (framepos_t frame, BBT_Time& bbt, const TempoMetr
frame_diff = frame - metric.frame(); frame_diff = frame - metric.frame();
bbt.ticks = metric.start().ticks + (uint32_t)round((double)frame_diff / ticks_per_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; uint32_t xtra_beats = bbt.ticks / (uint32_t)BBT_Time::ticks_per_beat;
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.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.bars = metric.start().bars + (uint32_t)floor((double)bbt.beats / beats_per_bar);
bbt.beats = (uint32_t)fmod((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 /* 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 we're in the last beat (the fractional one). if so, we
round ticks appropriately and bump to the next bar. */ round ticks appropriately and bump to the next bar. */
double beat_fraction = beats_per_bar - floor(beats_per_bar); double beat_fraction = beats_per_bar - floor(beats_per_bar);
/* XXX one problem here is that I'm not sure how to handle /* XXX one problem here is that I'm not sure how to handle
fractional beats that don't evenly divide ticks_per_beat. fractional beats that don't evenly divide ticks_per_beat.
If they aren't handled consistently, I would guess we'll If they aren't handled consistently, I would guess we'll
continue to have strange discrepancies occuring. Perhaps continue to have strange discrepancies occuring. Perhaps
this will also behave badly in the case of meters like this will also behave badly in the case of meters like
0.1/4, but I can't be bothered to test that. 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); 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) { if (bbt.beats > (uint32_t)floor(beats_per_bar) && bbt.ticks >= ticks_on_last_beat) {
bbt.ticks -= ticks_on_last_beat; bbt.ticks -= ticks_on_last_beat;
bbt.beats = 0; bbt.beats = 0;
bbt.bars++; 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; // cerr << "-----\t RETURN " << bbt << endl;
} }
@ -875,8 +875,9 @@ TempoMap::bbt_time_with_metric (framepos_t frame, BBT_Time& bbt, const TempoMetr
framecnt_t framecnt_t
TempoMap::count_frames_between (const BBT_Time& start, const BBT_Time& end) const 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, /* for this to work with fractional measure types, start and end have to be
that means that the beats and ticks should be inside a bar "legal" BBT types, that means that the beats and ticks should be inside
a bar
*/ */
framecnt_t frames = 0; framecnt_t frames = 0;
@ -911,7 +912,7 @@ TempoMap::count_frames_between (const BBT_Time& start, const BBT_Time& end) cons
framecnt_t framecnt_t
TempoMap::count_frames_between_metrics (const Meter& meter, const Tempo& tempo, const BBT_Time& start, const BBT_Time& end) const 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; framecnt_t frames = 0;
uint32_t bar = start.bars; uint32_t bar = start.bars;
@ -997,15 +998,12 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
TempoMetric metric = metric_at(result); TempoMetric metric = metric_at(result);
beats_per_bar = metric.meter().beats_per_bar(); 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
/*reduce things to legal bbt values as a duration in a 4.5/4 measure the musical decision is that the
we have to handle possible fractional=shorter beats at the end of measures fractional beat is also a beat , although a shorter one
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) { if (dir >= 0) {
result.beats = when.beats + bbt.beats; result.beats = when.beats + bbt.beats;
result.ticks = when.ticks + bbt.ticks; result.ticks = when.ticks + bbt.ticks;
@ -1017,9 +1015,12 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
beats_per_bar = metric.meter().beats_per_bar(); 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 /* We now counted the beats and landed in the target measure, now deal
and with request like bbt = 3|2|9000 ,so we repeat the same loop but add ticks 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 ..... /* of course gtk_ardour only allows bar with at least 1.0 beats .....
@ -1048,7 +1049,7 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
} else { } else {
uint32_t b = bbt.beats; uint32_t b = bbt.beats;
/* count beats */ /* count beats */
while( b > when.beats ) { while( b > when.beats ) {
result.bars = max(1U,result.bars-- ) ; result.bars = max(1U,result.bars-- ) ;
@ -1063,7 +1064,7 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
} }
result.beats = when.beats - b; result.beats = when.beats - b;
/*count ticks */ /* count ticks */
if (bbt.ticks <= when.ticks) { if (bbt.ticks <= when.ticks) {
result.ticks = when.ticks - bbt.ticks; result.ticks = when.ticks - bbt.ticks;
@ -1111,8 +1112,8 @@ TempoMap::bbt_duration_at_unlocked (const BBT_Time& when, const BBT_Time& bbt, i
framepos_t framepos_t
TempoMap::round_to_bar (framepos_t fr, int dir) 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); return round_to_type (fr, dir, Bar);
} }
} }
@ -1121,8 +1122,8 @@ TempoMap::round_to_bar (framepos_t fr, int dir)
framepos_t framepos_t
TempoMap::round_to_beat (framepos_t fr, int dir) 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); return round_to_type (fr, dir, Beat);
} }
} }
@ -1175,13 +1176,12 @@ TempoMap::round_to_beat_subdivision (framepos_t fr, int sub_num, int dir)
difference = mod; difference = mod;
} }
try { try {
the_beat = bbt_subtract (the_beat, BBT_Time (0, 0, difference)); the_beat = bbt_subtract (the_beat, BBT_Time (0, 0, difference));
} catch (...) { } catch (...) {
/* can't go backwards from wherever pos is, so just return it */ /* can't go backwards from wherever pos is, so just return it */
return fr; return fr;
} }
} else { } else {
/* round to nearest */ /* round to nearest */
@ -1556,9 +1556,9 @@ TempoMap::get_state ()
XMLNode *root = new XMLNode ("TempoMap"); XMLNode *root = new XMLNode ("TempoMap");
{ {
Glib::RWLock::ReaderLock lm (lock); Glib::RWLock::ReaderLock lm (lock);
for (i = metrics->begin(); i != metrics->end(); ++i) { for (i = metrics->begin(); i != metrics->end(); ++i) {
root->add_child_nocopy ((*i)->get_state()); root->add_child_nocopy ((*i)->get_state());
} }
} }
@ -1917,22 +1917,22 @@ TempoMap::framepos_plus_bbt (framepos_t pos, BBT_Time op) const
const MeterSection* m; const MeterSection* m;
const TempoSection* tempo; const TempoSection* tempo;
const TempoSection* t; const TempoSection* t;
framecnt_t frames_per_beat; framecnt_t frames_per_beat;
meter = &first_meter (); meter = &first_meter ();
tempo = &first_tempo (); tempo = &first_tempo ();
assert (meter); assert (meter);
assert (tempo); assert (tempo);
/* find the starting metrics for tempo & meter */ /* find the starting metrics for tempo & meter */
for (i = metrics->begin(); i != metrics->end(); ++i) { for (i = metrics->begin(); i != metrics->end(); ++i) {
if ((*i)->frame() > pos) { if ((*i)->frame() > pos) {
break; break;
} }
if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) { if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
tempo = t; tempo = t;
} else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) { } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
@ -1951,66 +1951,66 @@ TempoMap::framepos_plus_bbt (framepos_t pos, BBT_Time op) const
checking for a new metric on every beat. 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--; op.bars--;
/* check if we need to use a new metric section: has adding frames moved us /* 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. 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) { if (i != metrics->end()) {
tempo = t; if ((*i)->frame() <= pos) {
} else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
meter = m;
}
++i;
frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
} 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) { while (op.beats) {
/* given the current meter, have we gone past the end of the bar ? */ /* given the current meter, have we gone past the end of the bar ? */
pos += frames_per_beat; pos += frames_per_beat;
op.beats--; op.beats--;
/* check if we need to use a new metric section: has adding frames moved us /* 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. 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) { if (i != metrics->end()) {
tempo = t; if ((*i)->frame() <= pos) {
} else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
meter = m; if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
} tempo = t;
++i; } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter); meter = m;
} }
++i;
frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
}
} }
} }
if (op.ticks) { if (op.ticks) {
if (op.ticks >= BBT_Time::ticks_per_beat) { if (op.ticks >= BBT_Time::ticks_per_beat) {
pos += frames_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)); pos += llrint (frames_per_beat * ((op.ticks % (uint32_t) BBT_Time::ticks_per_beat) / (double) BBT_Time::ticks_per_beat));
} else { } else {
pos += llrint (frames_per_beat * (op.ticks / (double) BBT_Time::ticks_per_beat)); pos += llrint (frames_per_beat * (op.ticks / (double) BBT_Time::ticks_per_beat));
} }
} }
return pos; return pos;
} }
@ -2020,30 +2020,30 @@ double
TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const
{ {
Metrics::const_iterator i; Metrics::const_iterator i;
double beats = 0; double beats = 0;
const MeterSection* meter; const MeterSection* meter;
const MeterSection* m; const MeterSection* m;
const TempoSection* tempo; const TempoSection* tempo;
const TempoSection* t; const TempoSection* t;
double frames_per_beat; double frames_per_beat;
double ddist = distance; double ddist = distance;
double dpos = pos; double dpos = pos;
meter = &first_meter (); meter = &first_meter ();
tempo = &first_tempo (); tempo = &first_tempo ();
assert (meter); assert (meter);
assert (tempo); assert (tempo);
/* find the starting metrics for tempo & meter */ /* find the starting metrics for tempo & meter */
for (i = metrics->begin(); i != metrics->end(); ++i) { for (i = metrics->begin(); i != metrics->end(); ++i) {
if ((*i)->frame() > pos) { if ((*i)->frame() > pos) {
break; break;
} }
if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) { if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
tempo = t; tempo = t;
} else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) { } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
@ -2062,43 +2062,43 @@ TempoMap::framewalk_to_beats (framepos_t pos, framecnt_t distance) const
checking for a new metric on every beat. 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 (ddist > 0) {
/* if we're nearly at the end, but have a fractional beat left, while (ddist > 0) {
compute the fraction and then its all over
*/
if (ddist < frames_per_beat) { /* if we're nearly at the end, but have a fractional beat left,
beats += ddist / frames_per_beat; compute the fraction and then its all over
break; */
}
/* walk one beat */ if (ddist < frames_per_beat) {
beats += ddist / frames_per_beat;
break;
}
ddist -= frames_per_beat; /* walk one 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 /* 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. 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) { if (i != metrics->end()) {
tempo = t; if ((*i)->frame() <= (framepos_t) dpos) {
} else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
meter = m; if ((t = dynamic_cast<const TempoSection*>(*i)) != 0) {
} tempo = t;
++i; } else if ((m = dynamic_cast<const MeterSection*>(*i)) != 0) {
frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter); meter = m;
} }
++i;
frames_per_beat = tempo->frames_per_beat (_frame_rate, *meter);
}
} }
} }
return beats; return beats;
} }