projects
/
ardour.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Ongoing work on latency compensation
[ardour.git]
/
libs
/
ardour
/
midi_region.cc
diff --git
a/libs/ardour/midi_region.cc
b/libs/ardour/midi_region.cc
index a419e83ae3f7a1bbf233d0c7294cb2f4405df102..ebadc9cd5e18c91ad955c02eafc4dbc455bebcc9 100644
(file)
--- a/
libs/ardour/midi_region.cc
+++ b/
libs/ardour/midi_region.cc
@@
-28,7
+28,7
@@
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
-#include "
evoral/Beats.hpp
"
+#include "
temporal/beats.h
"
#include "pbd/xml++.h"
#include "pbd/basename.h"
#include "pbd/xml++.h"
#include "pbd/basename.h"
@@
-44,6
+44,7
@@
#include "ardour/source_factory.h"
#include "ardour/tempo.h"
#include "ardour/types.h"
#include "ardour/source_factory.h"
#include "ardour/tempo.h"
#include "ardour/types.h"
+#include "ardour/evoral_types_convert.h"
#include "pbd/i18n.h"
#include <locale.h>
#include "pbd/i18n.h"
#include <locale.h>
@@
-104,7
+105,7
@@
MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other)
}
/** Create a new MidiRegion that is part of an existing one */
}
/** Create a new MidiRegion that is part of an existing one */
-MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other, Music
Fram
e offset)
+MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other, Music
Sampl
e offset)
: Region (other, offset)
, _start_beats (Properties::start_beats, other->_start_beats)
, _length_beats (Properties::length_beats, other->_length_beats)
: Region (other, offset)
, _start_beats (Properties::start_beats, other->_start_beats)
, _length_beats (Properties::length_beats, other->_length_beats)
@@
-113,8
+114,8
@@
MidiRegion::MidiRegion (boost::shared_ptr<const MidiRegion> other, MusicFrame of
register_properties ();
register_properties ();
- const double offset_quarter_note = _session.tempo_map().exact_qn_at_
frame (other->_position + offset.fram
e, offset.division) - other->_quarter_note;
- if (offset.
fram
e != 0) {
+ const double offset_quarter_note = _session.tempo_map().exact_qn_at_
sample (other->_position + offset.sampl
e, offset.division) - other->_quarter_note;
+ if (offset.
sampl
e != 0) {
_start_beats = other->_start_beats + offset_quarter_note;
_length_beats = other->_length_beats - offset_quarter_note;
}
_start_beats = other->_start_beats + offset_quarter_note;
_length_beats = other->_length_beats - offset_quarter_note;
}
@@
-140,11
+141,11
@@
MidiRegion::do_export (string path) const
assert (!Glib::file_test (path, Glib::FILE_TEST_EXISTS));
newsrc = boost::dynamic_pointer_cast<MidiSource>(
SourceFactory::createWritable(DataType::MIDI, _session,
assert (!Glib::file_test (path, Glib::FILE_TEST_EXISTS));
newsrc = boost::dynamic_pointer_cast<MidiSource>(
SourceFactory::createWritable(DataType::MIDI, _session,
- path, false, _session.
fram
e_rate()));
+ path, false, _session.
sampl
e_rate()));
- Beats
Fram
esConverter bfc (_session.tempo_map(), _position);
-
Ev
oral::Beats const bbegin = bfc.from (_start);
-
Ev
oral::Beats const bend = bfc.from (_start + _length);
+ Beats
Sampl
esConverter bfc (_session.tempo_map(), _position);
+
Temp
oral::Beats const bbegin = bfc.from (_start);
+
Temp
oral::Beats const bend = bfc.from (_start + _length);
{
/* Lock our source since we'll be reading from it. write_to() will
{
/* Lock our source since we'll be reading from it. write_to() will
@@
-171,16
+172,16
@@
MidiRegion::clone (string path) const
assert (!Glib::file_test (path, Glib::FILE_TEST_EXISTS));
newsrc = boost::dynamic_pointer_cast<MidiSource>(
SourceFactory::createWritable(DataType::MIDI, _session,
assert (!Glib::file_test (path, Glib::FILE_TEST_EXISTS));
newsrc = boost::dynamic_pointer_cast<MidiSource>(
SourceFactory::createWritable(DataType::MIDI, _session,
- path, false, _session.
fram
e_rate()));
+ path, false, _session.
sampl
e_rate()));
return clone (newsrc);
}
boost::shared_ptr<MidiRegion>
MidiRegion::clone (boost::shared_ptr<MidiSource> newsrc) const
{
return clone (newsrc);
}
boost::shared_ptr<MidiRegion>
MidiRegion::clone (boost::shared_ptr<MidiSource> newsrc) const
{
- Beats
Fram
esConverter bfc (_session.tempo_map(), _position);
-
Ev
oral::Beats const bbegin = bfc.from (_start);
-
Ev
oral::Beats const bend = bfc.from (_start + _length);
+ Beats
Sampl
esConverter bfc (_session.tempo_map(), _position);
+
Temp
oral::Beats const bbegin = bfc.from (_start);
+
Temp
oral::Beats const bend = bfc.from (_start + _length);
{
boost::shared_ptr<MidiSource> ms = midi_source(0);
{
boost::shared_ptr<MidiSource> ms = midi_source(0);
@@
-234,20
+235,20
@@
MidiRegion::post_set (const PropertyChange& pc)
}
if (pc.contains (Properties::start) && !pc.contains (Properties::start_beats)) {
}
if (pc.contains (Properties::start) && !pc.contains (Properties::start_beats)) {
- set_start_beats_from_start_
fram
es ();
+ set_start_beats_from_start_
sampl
es ();
}
}
void
}
}
void
-MidiRegion::set_start_beats_from_start_
fram
es ()
+MidiRegion::set_start_beats_from_start_
sampl
es ()
{
if (position_lock_style() == AudioTime) {
{
if (position_lock_style() == AudioTime) {
- _start_beats = quarter_note() - _session.tempo_map().quarter_note_at_
fram
e (_position - _start);
+ _start_beats = quarter_note() - _session.tempo_map().quarter_note_at_
sampl
e (_position - _start);
}
}
void
}
}
void
-MidiRegion::set_length_internal (
fram
ecnt_t len, const int32_t sub_num)
+MidiRegion::set_length_internal (
sampl
ecnt_t len, const int32_t sub_num)
{
Region::set_length_internal (len, sub_num);
update_length_beats (sub_num);
{
Region::set_length_internal (len, sub_num);
update_length_beats (sub_num);
@@
-262,9
+263,9
@@
MidiRegion::update_after_tempo_map_change (bool /* send */)
return;
}
return;
}
- const
fram
epos_t old_pos = _position;
- const
fram
epos_t old_length = _length;
- const
fram
epos_t old_start = _start;
+ const
sampl
epos_t old_pos = _position;
+ const
sampl
epos_t old_length = _length;
+ const
sampl
epos_t old_start = _start;
PropertyChange s_and_l;
PropertyChange s_and_l;
@@
-285,10
+286,10
@@
MidiRegion::update_after_tempo_map_change (bool /* send */)
For now, the musical position at the region start is retained, but subsequent events
will maintain their beat distance according to the map.
*/
For now, the musical position at the region start is retained, but subsequent events
will maintain their beat distance according to the map.
*/
- _start = _session.tempo_map().
fram
es_between_quarter_notes (quarter_note() - start_beats(), quarter_note());
+ _start = _session.tempo_map().
sampl
es_between_quarter_notes (quarter_note() - start_beats(), quarter_note());
/* _length doesn't change for audio-locked regions. update length_beats to match. */
/* _length doesn't change for audio-locked regions. update length_beats to match. */
- _length_beats = _session.tempo_map().quarter_note_at_
fram
e (_position + _length) - quarter_note();
+ _length_beats = _session.tempo_map().quarter_note_at_
sampl
e (_position + _length) - quarter_note();
s_and_l.add (Properties::start);
s_and_l.add (Properties::length_beats);
s_and_l.add (Properties::start);
s_and_l.add (Properties::length_beats);
@@
-300,7
+301,7
@@
MidiRegion::update_after_tempo_map_change (bool /* send */)
Region::update_after_tempo_map_change (false);
/* _start has now been updated. */
Region::update_after_tempo_map_change (false);
/* _start has now been updated. */
- _length = max ((
framecnt_t) 1, _session.tempo_map().fram
es_between_quarter_notes (quarter_note(), quarter_note() + _length_beats));
+ _length = max ((
samplecnt_t) 1, _session.tempo_map().sampl
es_between_quarter_notes (quarter_note(), quarter_note() + _length_beats));
if (old_start != _start) {
s_and_l.add (Properties::start);
if (old_start != _start) {
s_and_l.add (Properties::start);
@@
-318,11
+319,11
@@
MidiRegion::update_after_tempo_map_change (bool /* send */)
void
MidiRegion::update_length_beats (const int32_t sub_num)
{
void
MidiRegion::update_length_beats (const int32_t sub_num)
{
- _length_beats = _session.tempo_map().exact_qn_at_
fram
e (_position + _length, sub_num) - quarter_note();
+ _length_beats = _session.tempo_map().exact_qn_at_
sampl
e (_position + _length, sub_num) - quarter_note();
}
void
}
void
-MidiRegion::set_position_internal (
fram
epos_t pos, bool allow_bbt_recompute, const int32_t sub_num)
+MidiRegion::set_position_internal (
sampl
epos_t pos, bool allow_bbt_recompute, const int32_t sub_num)
{
Region::set_position_internal (pos, allow_bbt_recompute, sub_num);
{
Region::set_position_internal (pos, allow_bbt_recompute, sub_num);
@@
-332,7
+333,7
@@
MidiRegion::set_position_internal (framepos_t pos, bool allow_bbt_recompute, con
}
/* set _start to new position in tempo map */
}
/* set _start to new position in tempo map */
- _start = _session.tempo_map().
fram
es_between_quarter_notes (quarter_note() - start_beats(), quarter_note());
+ _start = _session.tempo_map().
sampl
es_between_quarter_notes (quarter_note() - start_beats(), quarter_note());
/* in construction from src */
if (_length_beats == 0.0) {
/* in construction from src */
if (_length_beats == 0.0) {
@@
-340,12
+341,12
@@
MidiRegion::set_position_internal (framepos_t pos, bool allow_bbt_recompute, con
}
if (position_lock_style() == AudioTime) {
}
if (position_lock_style() == AudioTime) {
- _length_beats = _session.tempo_map().quarter_note_at_
fram
e (_position + _length) - quarter_note();
+ _length_beats = _session.tempo_map().quarter_note_at_
sampl
e (_position + _length) - quarter_note();
} else {
/* leave _length_beats alone, and change _length to reflect the state of things
} else {
/* leave _length_beats alone, and change _length to reflect the state of things
- at the new position (tempo map may dictate a different number of
fram
es).
+ at the new position (tempo map may dictate a different number of
sampl
es).
*/
*/
- Region::set_length_internal (_session.tempo_map().
fram
es_between_quarter_notes (quarter_note(), quarter_note() + length_beats()), sub_num);
+ Region::set_length_internal (_session.tempo_map().
sampl
es_between_quarter_notes (quarter_note(), quarter_note() + length_beats()), sub_num);
}
}
}
}
@@
-354,24
+355,24
@@
MidiRegion::set_position_music_internal (double qn)
{
Region::set_position_music_internal (qn);
/* set _start to new position in tempo map */
{
Region::set_position_music_internal (qn);
/* set _start to new position in tempo map */
- _start = _session.tempo_map().
fram
es_between_quarter_notes (quarter_note() - start_beats(), quarter_note());
+ _start = _session.tempo_map().
sampl
es_between_quarter_notes (quarter_note() - start_beats(), quarter_note());
if (position_lock_style() == AudioTime) {
if (position_lock_style() == AudioTime) {
- _length_beats = _session.tempo_map().quarter_note_at_
fram
e (_position + _length) - quarter_note();
+ _length_beats = _session.tempo_map().quarter_note_at_
sampl
e (_position + _length) - quarter_note();
} else {
/* leave _length_beats alone, and change _length to reflect the state of things
} else {
/* leave _length_beats alone, and change _length to reflect the state of things
- at the new position (tempo map may dictate a different number of
fram
es).
+ at the new position (tempo map may dictate a different number of
sampl
es).
*/
*/
- _length = _session.tempo_map().
fram
es_between_quarter_notes (quarter_note(), quarter_note() + length_beats());
+ _length = _session.tempo_map().
sampl
es_between_quarter_notes (quarter_note(), quarter_note() + length_beats());
}
}
}
}
-
fram
ecnt_t
-MidiRegion::read_at (Evoral::EventSink<
fram
epos_t>& out,
-
fram
epos_t position,
-
fram
ecnt_t dur,
- Evoral::Range<
fram
epos_t>* loop_range,
+
sampl
ecnt_t
+MidiRegion::read_at (Evoral::EventSink<
sampl
epos_t>& out,
+
sampl
epos_t position,
+
sampl
ecnt_t dur,
+ Evoral::Range<
sampl
epos_t>* loop_range,
MidiCursor& cursor,
uint32_t chan_n,
NoteMode mode,
MidiCursor& cursor,
uint32_t chan_n,
NoteMode mode,
@@
-381,11
+382,11
@@
MidiRegion::read_at (Evoral::EventSink<framepos_t>& out,
return _read_at (_sources, out, position, dur, loop_range, cursor, chan_n, mode, tracker, filter);
}
return _read_at (_sources, out, position, dur, loop_range, cursor, chan_n, mode, tracker, filter);
}
-
fram
ecnt_t
-MidiRegion::master_read_at (MidiRingBuffer<
fram
epos_t>& out,
-
fram
epos_t position,
-
fram
ecnt_t dur,
- Evoral::Range<
fram
epos_t>* loop_range,
+
sampl
ecnt_t
+MidiRegion::master_read_at (MidiRingBuffer<
sampl
epos_t>& out,
+
sampl
epos_t position,
+
sampl
ecnt_t dur,
+ Evoral::Range<
sampl
epos_t>* loop_range,
MidiCursor& cursor,
uint32_t chan_n,
NoteMode mode) const
MidiCursor& cursor,
uint32_t chan_n,
NoteMode mode) const
@@
-393,20
+394,20
@@
MidiRegion::master_read_at (MidiRingBuffer<framepos_t>& out,
return _read_at (_master_sources, out, position, dur, loop_range, cursor, chan_n, mode); /* no tracker */
}
return _read_at (_master_sources, out, position, dur, loop_range, cursor, chan_n, mode); /* no tracker */
}
-
fram
ecnt_t
+
sampl
ecnt_t
MidiRegion::_read_at (const SourceList& /*srcs*/,
MidiRegion::_read_at (const SourceList& /*srcs*/,
- Evoral::EventSink<
fram
epos_t>& dst,
-
fram
epos_t position,
-
fram
ecnt_t dur,
- Evoral::Range<
fram
epos_t>* loop_range,
+ Evoral::EventSink<
sampl
epos_t>& dst,
+
sampl
epos_t position,
+
sampl
ecnt_t dur,
+ Evoral::Range<
sampl
epos_t>* loop_range,
MidiCursor& cursor,
uint32_t chan_n,
NoteMode mode,
MidiStateTracker* tracker,
MidiChannelFilter* filter) const
{
MidiCursor& cursor,
uint32_t chan_n,
NoteMode mode,
MidiStateTracker* tracker,
MidiChannelFilter* filter) const
{
-
fram
eoffset_t internal_offset = 0;
-
fram
ecnt_t to_read = 0;
+
sampl
eoffset_t internal_offset = 0;
+
sampl
ecnt_t to_read = 0;
/* precondition: caller has verified that we cover the desired section */
/* precondition: caller has verified that we cover the desired section */
@@
-452,14
+453,14
@@
MidiRegion::_read_at (const SourceList& /*srcs*/,
<< endl;
#endif
<< endl;
#endif
- /* This call reads events from a source and writes them to `dst' timed in session
fram
es */
+ /* This call reads events from a source and writes them to `dst' timed in session
sampl
es */
if (src->midi_read (
lm, // source lock
dst, // destination buffer
if (src->midi_read (
lm, // source lock
dst, // destination buffer
- _position - _start, // start position of the source in session
fram
es
+ _position - _start, // start position of the source in session
sampl
es
_start + internal_offset, // where to start reading in the source
_start + internal_offset, // where to start reading in the source
- to_read, // read duration in
fram
es
+ to_read, // read duration in
sampl
es
loop_range,
cursor,
tracker,
loop_range,
cursor,
tracker,
@@
-509,7
+510,7
@@
MidiRegion::recompute_at_start ()
}
int
}
int
-MidiRegion::separate_by_channel (
ARDOUR::Session&,
vector< boost::shared_ptr<Region> >&) const
+MidiRegion::separate_by_channel (vector< boost::shared_ptr<Region> >&) const
{
// TODO
return -1;
{
// TODO
return -1;
@@
-599,10
+600,13
@@
MidiRegion::model_shifted (double qn_distance)
}
if (!_ignore_shift) {
}
if (!_ignore_shift) {
+ PropertyChange what_changed;
_start_beats += qn_distance;
_start_beats += qn_distance;
-
framepos_t const new_start = _session.tempo_map().fram
es_between_quarter_notes (_quarter_note - _start_beats, _quarter_note);
+
samplepos_t const new_start = _session.tempo_map().sampl
es_between_quarter_notes (_quarter_note - _start_beats, _quarter_note);
_start = new_start;
_start = new_start;
- send_change (Properties::start);
+ what_changed.add (Properties::start);
+ what_changed.add (Properties::start_beats);
+ send_change (what_changed);
} else {
_ignore_shift = false;
}
} else {
_ignore_shift = false;
}
@@
-639,30
+643,26
@@
MidiRegion::model_automation_state_changed (Evoral::Parameter const & p)
void
MidiRegion::fix_negative_start ()
{
void
MidiRegion::fix_negative_start ()
{
- Beats
Fram
esConverter c (_session.tempo_map(), _position);
+ Beats
Sampl
esConverter c (_session.tempo_map(), _position);
_ignore_shift = true;
_ignore_shift = true;
- model()->insert_silence_at_start (
Ev
oral::Beats (- _start_beats));
+ model()->insert_silence_at_start (
Temp
oral::Beats (- _start_beats));
_start = 0;
_start_beats = 0.0;
}
void
_start = 0;
_start_beats = 0.0;
}
void
-MidiRegion::set_start_internal (
fram
ecnt_t s, const int32_t sub_num)
+MidiRegion::set_start_internal (
sampl
ecnt_t s, const int32_t sub_num)
{
Region::set_start_internal (s, sub_num);
{
Region::set_start_internal (s, sub_num);
- if (_start_beats < 0.0) {
- fix_negative_start();
- }
-
- set_start_beats_from_start_frames ();
+ set_start_beats_from_start_samples ();
}
void
}
void
-MidiRegion::trim_to_internal (
framepos_t position, fram
ecnt_t length, const int32_t sub_num)
+MidiRegion::trim_to_internal (
samplepos_t position, sampl
ecnt_t length, const int32_t sub_num)
{
if (locked()) {
return;
{
if (locked()) {
return;
@@
-674,14
+674,14
@@
MidiRegion::trim_to_internal (framepos_t position, framecnt_t length, const int3
/* Set position before length, otherwise for MIDI regions this bad thing happens:
* 1. we call set_length_internal; length in beats is computed using the region's current
* (soon-to-be old) position
/* Set position before length, otherwise for MIDI regions this bad thing happens:
* 1. we call set_length_internal; length in beats is computed using the region's current
* (soon-to-be old) position
- * 2. we call set_position_internal; position is set and length in
fram
es re-computed using
+ * 2. we call set_position_internal; position is set and length in
sampl
es re-computed using
* length in beats from (1) but at the new position, which is wrong if the region
* straddles a tempo/meter change.
*/
if (_position != position) {
* length in beats from (1) but at the new position, which is wrong if the region
* straddles a tempo/meter change.
*/
if (_position != position) {
- const double pos_qn = _session.tempo_map().exact_qn_at_
fram
e (position, sub_num);
+ const double pos_qn = _session.tempo_map().exact_qn_at_
sampl
e (position, sub_num);
const double old_pos_qn = quarter_note();
/* sets _pulse to new position.*/
const double old_pos_qn = quarter_note();
/* sets _pulse to new position.*/
@@
-689,7
+689,7
@@
MidiRegion::trim_to_internal (framepos_t position, framecnt_t length, const int3
what_changed.add (Properties::position);
double new_start_qn = start_beats() + (pos_qn - old_pos_qn);
what_changed.add (Properties::position);
double new_start_qn = start_beats() + (pos_qn - old_pos_qn);
-
framepos_t new_start = _session.tempo_map().fram
es_between_quarter_notes (pos_qn - new_start_qn, pos_qn);
+
samplepos_t new_start = _session.tempo_map().sampl
es_between_quarter_notes (pos_qn - new_start_qn, pos_qn);
if (!verify_start_and_length (new_start, length)) {
return;
if (!verify_start_and_length (new_start, length)) {
return;