summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/SConscript19
-rw-r--r--libs/ardour/ardour/automatable.h11
-rw-r--r--libs/ardour/ardour/event_type_map.h43
-rw-r--r--libs/ardour/ardour/midi_buffer.h14
-rw-r--r--libs/ardour/ardour/midi_ring_buffer.h347
-rw-r--r--libs/ardour/ardour/parameter.h14
-rw-r--r--libs/ardour/event_type_map.cc61
-rw-r--r--libs/ardour/import.cc2
-rw-r--r--libs/ardour/meter.cc2
-rw-r--r--libs/ardour/midi_buffer.cc8
-rw-r--r--libs/ardour/midi_diskstream.cc4
-rw-r--r--libs/ardour/midi_model.cc14
-rw-r--r--libs/ardour/midi_track.cc3
-rw-r--r--libs/ardour/quantize.cc4
-rw-r--r--libs/ardour/smf_source.cc18
15 files changed, 200 insertions, 364 deletions
diff --git a/libs/ardour/SConscript b/libs/ardour/SConscript
index c351510d19..352d1b26f6 100644
--- a/libs/ardour/SConscript
+++ b/libs/ardour/SConscript
@@ -32,18 +32,18 @@ ardour.Append(CPPPATH = '#libs/surfaces/control_protocol')
ardour_files=Split("""
amp.cc
analyser.cc
-audioanalyser.cc
audio_buffer.cc
audio_diskstream.cc
-audioengine.cc
-audiofilesource.cc
-audiofile_tagger.cc
audio_library.cc
audio_playlist.cc
audio_port.cc
+audio_track.cc
+audioanalyser.cc
+audioengine.cc
+audiofile_tagger.cc
+audiofilesource.cc
audioregion.cc
audiosource.cc
-audio_track.cc
auditioner.cc
auto_bundle.cc
automatable.cc
@@ -65,13 +65,14 @@ default_click.cc
directory_names.cc
diskstream.cc
enums.cc
+event_type_map.cc
export_channel_configuration.cc
export_file_io.cc
export_filename.cc
export_format_base.cc
export_format_manager.cc
-export_formats.cc
export_format_specification.cc
+export_formats.cc
export_handler.cc
export_preset.cc
export_processor.cc
@@ -97,6 +98,7 @@ ladspa_plugin.cc
location.cc
meter.cc
midi_buffer.cc
+midi_clock_slave.cc
midi_diskstream.cc
midi_model.cc
midi_playlist.cc
@@ -107,7 +109,6 @@ midi_stretch.cc
midi_track.cc
mix.cc
mtc_slave.cc
-midi_clock_slave.cc
named_selection.cc
onset_detector.cc
panner.cc
@@ -131,8 +132,8 @@ reverse.cc
route.cc
route_group.cc
send.cc
-session_butler.cc
session.cc
+session_butler.cc
session_click.cc
session_command.cc
session_directory.cc
@@ -150,8 +151,8 @@ silentfilesource.cc
smf_reader.cc
smf_source.cc
sndfile_helpers.cc
-sndfilesource.cc
sndfileimportable.cc
+sndfilesource.cc
source.cc
source_factory.cc
svn_revision.cc
diff --git a/libs/ardour/ardour/automatable.h b/libs/ardour/ardour/automatable.h
index 837bbbc617..dbce7de0bf 100644
--- a/libs/ardour/ardour/automatable.h
+++ b/libs/ardour/ardour/automatable.h
@@ -27,6 +27,7 @@
#include <ardour/automation_list.h>
#include <ardour/automation_control.h>
#include <ardour/parameter.h>
+#include <ardour/event_type_map.h>
#include <evoral/ControlSet.hpp>
#include <evoral/Sequence.hpp>
@@ -53,9 +54,6 @@ public:
virtual void add_control(boost::shared_ptr<Evoral::Control>);
virtual void automation_snapshot(nframes_t now, bool force);
- bool should_snapshot (nframes_t now) {
- return (_last_automation_snapshot > now || (now - _last_automation_snapshot) > _automation_interval);
- }
virtual void transport_stopped(nframes_t now);
virtual string describe_parameter(Parameter param);
@@ -73,6 +71,11 @@ public:
void mark_automation_visible(Parameter, bool);
+ inline bool should_snapshot (nframes_t now) {
+ return (_last_automation_snapshot > now
+ || (now - _last_automation_snapshot) > _automation_interval);
+ }
+
static void set_automation_interval (jack_nframes_t frames) {
_automation_interval = frames;
}
@@ -113,7 +116,7 @@ public:
AutomatableSequence(Session& s, size_t size)
: Evoral::ControlSet()
, Automatable(s)
- , Evoral::Sequence(size)
+ , Evoral::Sequence(EventTypeMap::instance())
{}
};
diff --git a/libs/ardour/ardour/event_type_map.h b/libs/ardour/ardour/event_type_map.h
new file mode 100644
index 0000000000..6736feeb86
--- /dev/null
+++ b/libs/ardour/ardour/event_type_map.h
@@ -0,0 +1,43 @@
+/*
+ Copyright (C) 2000-2007 Paul Davis
+ Author: Dave 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __ardour_event_type_map_h__
+#define __ardour_event_type_map_h__
+
+#include <evoral/TypeMap.hpp>
+
+namespace ARDOUR {
+
+class EventTypeMap : public Evoral::TypeMap {
+public:
+ bool type_is_midi(uint32_t type) const;
+ uint8_t parameter_midi_type(const Evoral::Parameter& param) const;
+ uint32_t midi_event_type(uint8_t status) const;
+
+ static EventTypeMap& instance() { return event_type_map; }
+
+private:
+ static EventTypeMap event_type_map;
+};
+
+} // namespace ARDOUR
+
+#endif /* __ardour_event_type_map_h__ */
+
diff --git a/libs/ardour/ardour/midi_buffer.h b/libs/ardour/ardour/midi_buffer.h
index 0c13199825..606cbd0ec8 100644
--- a/libs/ardour/ardour/midi_buffer.h
+++ b/libs/ardour/ardour/midi_buffer.h
@@ -39,7 +39,7 @@ public:
void copy(const MidiBuffer& copy);
- bool push_back(const Evoral::Event& event);
+ bool push_back(const Evoral::MIDIEvent& event);
bool push_back(const jack_midi_event_t& event);
uint8_t* reserve(double time, size_t size);
@@ -50,7 +50,7 @@ public:
struct iterator {
iterator(MidiBuffer& b, size_t i) : buffer(b), index(i) {}
- inline Evoral::Event& operator*() const { return buffer[index]; }
+ inline Evoral::MIDIEvent& operator*() const { return buffer[index]; }
inline iterator& operator++() { ++index; return *this; } // prefix
inline bool operator!=(const iterator& other) const { return index != other.index; }
@@ -61,7 +61,7 @@ public:
struct const_iterator {
const_iterator(const MidiBuffer& b, size_t i) : buffer(b), index(i) {}
- inline const Evoral::Event& operator*() const { return buffer[index]; }
+ inline const Evoral::MIDIEvent& operator*() const { return buffer[index]; }
inline const_iterator& operator++() { ++index; return *this; } // prefix
inline bool operator!=(const const_iterator& other) const { return index != other.index; }
@@ -80,8 +80,8 @@ private:
friend class iterator;
friend class const_iterator;
- const Evoral::Event& operator[](size_t i) const { assert(i < _size); return _events[i]; }
- Evoral::Event& operator[](size_t i) { assert(i < _size); return _events[i]; }
+ const Evoral::MIDIEvent& operator[](size_t i) const { assert(i < _size); return _events[i]; }
+ Evoral::MIDIEvent& operator[](size_t i) { assert(i < _size); return _events[i]; }
// FIXME: Eliminate this
static const size_t MAX_EVENT_SIZE = 4; // bytes
@@ -92,8 +92,8 @@ private:
/* FIXME: this is utter crap. rewrite as a flat/packed buffer like MidiRingBuffer */
- Evoral::Event* _events; ///< Event structs that point to offsets in _data
- uint8_t* _data; ///< MIDI, straight up. No time stamps.
+ Evoral::MIDIEvent* _events; ///< Event structs that point to offsets in _data
+ uint8_t* _data; ///< MIDI, straight up. No time stamps.
};
diff --git a/libs/ardour/ardour/midi_ring_buffer.h b/libs/ardour/ardour/midi_ring_buffer.h
index db0c3029a8..ae82dc14ab 100644
--- a/libs/ardour/ardour/midi_ring_buffer.h
+++ b/libs/ardour/ardour/midi_ring_buffer.h
@@ -24,239 +24,30 @@
#include <ardour/types.h>
#include <ardour/buffer.h>
#include <evoral/EventSink.hpp>
+#include <evoral/EventRingBuffer.hpp>
namespace ARDOUR {
-/* FIXME: this is probably too much inlined code */
-
-
-/** A RingBuffer.
- * Read/Write realtime safe.
- * Single-reader Single-writer thread safe.
- *
- * This is Raul::RingBuffer, lifted for MIDIRingBuffer to inherit from as it works
- * a bit differently than PBD::Ringbuffer. This could/should be replaced with
- * the PBD ringbuffer to decrease code size, but this code is tested and known to
- * work, so here it sits for now...
- *
- * Ignore this class, use MidiRingBuffer.
- */
-template <typename T>
-class MidiRingBufferBase {
-public:
-
- /** @param size Size in bytes.
- */
- MidiRingBufferBase(size_t size)
- : _size(size)
- , _buf(new T[size])
- {
- reset();
- assert(read_space() == 0);
- assert(write_space() == size - 1);
- }
-
- virtual ~MidiRingBufferBase() {
- delete[] _buf;
- }
-
- /** Reset(empty) the ringbuffer.
- * NOT thread safe.
- */
- void reset() {
- g_atomic_int_set(&_write_ptr, 0);
- g_atomic_int_set(&_read_ptr, 0);
- }
-
- size_t write_space() const {
-
- const size_t w = g_atomic_int_get(&_write_ptr);
- const size_t r = g_atomic_int_get(&_read_ptr);
-
- if (w > r) {
- return ((r - w + _size) % _size) - 1;
- } else if (w < r) {
- return (r - w) - 1;
- } else {
- return _size - 1;
- }
- }
-
- size_t read_space() const {
-
- const size_t w = g_atomic_int_get(&_write_ptr);
- const size_t r = g_atomic_int_get(&_read_ptr);
-
- if (w > r) {
- return w - r;
- } else {
- return (w - r + _size) % _size;
- }
- }
-
- size_t capacity() const { return _size; }
-
- size_t peek(size_t size, T* dst);
- bool full_peek(size_t size, T* dst);
-
- size_t read(size_t size, T* dst);
- bool full_read(size_t size, T* dst);
-
- bool skip(size_t size);
-
- void write(size_t size, const T* src);
-
-protected:
- mutable int _write_ptr;
- mutable int _read_ptr;
-
- size_t _size; ///< Size (capacity) in bytes
- T* _buf; ///< size, event, size, event...
-};
-
-
-/** Peek at the ringbuffer (read w/o advancing read pointer).
- *
- * Note that a full read may not be done if the data wraps around.
- * Caller must check return value and call again if necessary, or use the
- * full_peek method which does this automatically.
- */
-template<typename T>
-size_t
-MidiRingBufferBase<T>::peek(size_t size, T* dst)
-{
- const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr);
-
- const size_t read_size = (priv_read_ptr + size < _size)
- ? size
- : _size - priv_read_ptr;
-
- memcpy(dst, &_buf[priv_read_ptr], read_size);
-
- return read_size;
-}
-
-
-template<typename T>
-bool
-MidiRingBufferBase<T>::full_peek(size_t size, T* dst)
-{
- if (read_space() < size) {
- return false;
- }
-
- const size_t read_size = peek(size, dst);
-
- if (read_size < size) {
- peek(size - read_size, dst + read_size);
- }
-
- return true;
-}
-
-
-/** Read from the ringbuffer.
- *
- * Note that a full read may not be done if the data wraps around.
- * Caller must check return value and call again if necessary, or use the
- * full_read method which does this automatically.
- */
-template<typename T>
-size_t
-MidiRingBufferBase<T>::read(size_t size, T* dst)
-{
- const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr);
-
- const size_t read_size = (priv_read_ptr + size < _size)
- ? size
- : _size - priv_read_ptr;
-
- memcpy(dst, &_buf[priv_read_ptr], read_size);
-
- g_atomic_int_set(&_read_ptr, (priv_read_ptr + read_size) % _size);
-
- return read_size;
-}
-
-
-template<typename T>
-bool
-MidiRingBufferBase<T>::full_read(size_t size, T* dst)
-{
- if (read_space() < size) {
- return false;
- }
-
- const size_t read_size = read(size, dst);
-
- if (read_size < size) {
- read(size - read_size, dst + read_size);
- }
-
- return true;
-}
-
-
-template<typename T>
-bool
-MidiRingBufferBase<T>::skip(size_t size)
-{
- if (read_space() < size) {
- std::cerr << "WARNING: Attempt to skip past end of MIDI ring buffer" << std::endl;
- return false;
- }
-
- const size_t priv_read_ptr = g_atomic_int_get(&_read_ptr);
- g_atomic_int_set(&_read_ptr, (priv_read_ptr + size) % _size);
-
- return true;
-}
-
-
-template<typename T>
-inline void
-MidiRingBufferBase<T>::write(size_t size, const T* src)
-{
- const size_t priv_write_ptr = g_atomic_int_get(&_write_ptr);
-
- if (priv_write_ptr + size <= _size) {
- memcpy(&_buf[priv_write_ptr], src, size);
- g_atomic_int_set(&_write_ptr, (priv_write_ptr + size) % _size);
- } else {
- const size_t this_size = _size - priv_write_ptr;
- assert(this_size < size);
- assert(priv_write_ptr + this_size <= _size);
- memcpy(&_buf[priv_write_ptr], src, this_size);
- memcpy(&_buf[0], src+this_size, size - this_size);
- g_atomic_int_set(&_write_ptr, size - this_size);
- }
-}
-
-
-/* ******************************************************************** */
-
-
-/** A MIDI RingBuffer.
+/** A RingBuffer for (MIDI) events.
*
- * This is timestamps and MIDI packed sequentially into a single buffer, similarly
- * to LV2 MIDI. The buffer looks like this:
+ * This is simply a wrapper around a raw ringbuffer which writes/reads events
+ * as flat placked blobs.
+ * The buffer looks like this:
*
- * [timestamp][size][size bytes of raw MIDI][timestamp][size][etc..]
+ * [timestamp][type][size][size bytes of raw MIDI][timestamp][type][size](etc...)
*/
-class MidiRingBuffer : public MidiRingBufferBase<uint8_t>, public Evoral::EventSink {
+class MidiRingBuffer : public Evoral::EventRingBuffer {
public:
/** @param size Size in bytes.
*/
MidiRingBuffer(size_t size)
- : MidiRingBufferBase<uint8_t>(size), _channel_mask(0x0000FFFF)
+ : Evoral::EventRingBuffer(size)
+ , _channel_mask(0x0000FFFF)
{}
- size_t write(double time, uint32_t size, const uint8_t* buf);
- bool read(double* time, uint32_t* size, uint8_t* buf);
-
- bool read_prefix(double* time, size_t* size);
- bool read_contents(size_t size, uint8_t* buf);
+ inline bool read_prefix(EventTime* time, EventType* type, uint32_t* size);
+ inline bool read_contents(uint32_t size, uint8_t* buf);
size_t read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t offset=0);
@@ -292,32 +83,17 @@ private:
};
-inline bool
-MidiRingBuffer::read(double* time, uint32_t* size, uint8_t* buf)
-{
- bool success = MidiRingBufferBase<uint8_t>::full_read(sizeof(double), (uint8_t*)time);
-
- if (success) {
- success = MidiRingBufferBase<uint8_t>::full_read(sizeof(size_t), (uint8_t*)size);
- }
- if (success) {
- success = MidiRingBufferBase<uint8_t>::full_read(*size, buf);
- }
-
- return success;
-}
-
-
/** Read the time and size of an event. This call MUST be immediately proceeded
* by a call to read_contents (or the read pointer will be garabage).
*/
inline bool
-MidiRingBuffer::read_prefix(double* time, size_t* size)
+MidiRingBuffer::read_prefix(EventTime* time, EventType* type, uint32_t* size)
{
- bool success = MidiRingBufferBase<uint8_t>::full_read(sizeof(double), (uint8_t*)time);
- if (success) {
- success = MidiRingBufferBase<uint8_t>::full_read(sizeof(size_t), (uint8_t*)size);
- }
+ bool success = Evoral::EventRingBuffer::full_read(sizeof(EventTime), (uint8_t*)time);
+ if (success)
+ success = Evoral::EventRingBuffer::full_read(sizeof(EventType), (uint8_t*)type);
+ if (success)
+ success = Evoral::EventRingBuffer::full_read(sizeof(uint32_t), (uint8_t*)size);
return success;
}
@@ -327,51 +103,9 @@ MidiRingBuffer::read_prefix(double* time, size_t* size)
* by a call to read_prefix (or the returned even will be garabage).
*/
inline bool
-MidiRingBuffer::read_contents(size_t size, uint8_t* buf)
-{
- return MidiRingBufferBase<uint8_t>::full_read(size, buf);
-}
-
-
-inline size_t
-MidiRingBuffer::write(double time, uint32_t size, const uint8_t* buf)
+MidiRingBuffer::read_contents(uint32_t size, uint8_t* buf)
{
- /*fprintf(stderr, "MRB %p write (t = %f) ", this, time);
- for (size_t i = 0; i < size; ++i)
- fprintf(stderr, "%X", (char)buf[i]);
- fprintf(stderr, "\n");*/
-
- assert(size > 0);
-
- // Don't write event if it doesn't match channel filter
- if (is_channel_event(buf[0]) && get_channel_mode() == FilterChannels) {
- uint8_t channel = buf[0] & 0x0F;
- if ( !(get_channel_mask() & (1L << channel)) ) {
- return 0;
- }
- }
-
- if (write_space() < (sizeof(double) + sizeof(size_t) + size)) {
- return 0;
- } else {
- MidiRingBufferBase<uint8_t>::write(sizeof(double), (uint8_t*)&time);
- MidiRingBufferBase<uint8_t>::write(sizeof(size_t), (uint8_t*)&size);
- if (is_channel_event(buf[0]) && get_channel_mode() == ForceChannel) {
- assert(size == 2 || size == 3);
- uint8_t tmp_buf[3];
- // Force event to channel
- tmp_buf[0] = (buf[0] & 0xF0) | (get_channel_mask() & 0x0F);
- tmp_buf[1] = buf[1];
- if (size == 3) {
- tmp_buf[2] = buf[2];
- }
- MidiRingBufferBase<uint8_t>::write(size, tmp_buf);
- } else {
- MidiRingBufferBase<uint8_t>::write(size, buf);
- }
- return size;
- }
-
+ return Evoral::EventRingBuffer::full_read(size, buf);
}
@@ -383,31 +117,31 @@ MidiRingBuffer::write(double time, uint32_t size, const uint8_t* buf)
inline size_t
MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t offset)
{
- if (read_space() == 0)
+ if (read_space() == 0) {
+ //std::cerr << "MRB: NO READ SPACE" << std::endl;
return 0;
+ }
- double ev_time;
- uint32_t ev_size;
+ EventTime ev_time;
+ EventType ev_type;
+ uint32_t ev_size;
size_t count = 0;
- //printf("---- MRB read %u .. %u + %u\n", start, end, offset);
+ //std::cerr << "MRB read " << start << " .. " << end << " + " << offset << std::endl;
- while (read_space() > sizeof(double) + sizeof(size_t)) {
+ while (read_space() > sizeof(EventTime) + sizeof(EventType) + sizeof(uint32_t)) {
- full_peek(sizeof(double), (uint8_t*)&ev_time);
+ full_peek(sizeof(EventTime), (uint8_t*)&ev_time);
if (ev_time > end) {
+ //std::cerr << "MRB: PAST END (" << ev_time << " : " << end << ")" << std::endl;
break;
}
- bool success = MidiRingBufferBase<uint8_t>::full_read(sizeof(double), (uint8_t*)&ev_time);
- if (success) {
- success = MidiRingBufferBase<uint8_t>::full_read(sizeof(size_t), (uint8_t*)&ev_size);
- }
-
+ bool success = read_prefix(&ev_time, &ev_type, &ev_size);
if (!success) {
- std::cerr << "MRB: READ ERROR (time/size)" << std::endl;
+ //std::cerr << "MRB: READ ERROR (time/type/size)" << std::endl;
continue;
}
@@ -419,6 +153,7 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t
if (is_channel_event(status) && get_channel_mode() == FilterChannels) {
const uint8_t channel = status & 0x0F;
if ( !(get_channel_mask() & (1L << channel)) ) {
+ //std::cerr << "MRB skipping event due to channel mask" << std::endl;
skip(ev_size); // Advance read pointer to next event
continue;
}
@@ -426,36 +161,36 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t
if (ev_time >= start) {
- /*std::cerr << "MRB " << this << " - Reading event, time = "
- << ev_time << " - " << start << " => " << ev_time - start
- << ", size = " << ev_size << std::endl;*/
+ //std::cerr << "MRB " << this << " - Reading event, time = "
+ // << ev_time << " - " << start << " => " << ev_time - start
+ // << ", size = " << ev_size << std::endl;
ev_time -= start;
uint8_t* write_loc = dst.reserve(ev_time, ev_size);
if (write_loc == NULL) {
- std::cerr << "MRB: Unable to reserve space in buffer, event skipped";
+ //std::cerr << "MRB: Unable to reserve space in buffer, event skipped";
continue;
}
- success = MidiRingBufferBase<uint8_t>::full_read(ev_size, write_loc);
+ success = Evoral::EventRingBuffer::full_read(ev_size, write_loc);
if (success) {
if (is_channel_event(status) && get_channel_mode() == ForceChannel) {
write_loc[0] = (write_loc[0] & 0xF0) | (get_channel_mask() & 0x0F);
}
++count;
- //printf("MRB - read event at time %lf\n", ev_time);
+ //std::cerr << "MRB - read event at time " << ev_time << std::endl;
} else {
- std::cerr << "MRB: READ ERROR (data)" << std::endl;
+ //std::cerr << "MRB: READ ERROR (data)" << std::endl;
}
} else {
- printf("MRB (start %u) - Skipping event at (too early) time %f\n", start, ev_time);
+ //std::cerr << "MRB (start " << start << ") - Skipping event at (too early) time " << ev_time << std::endl;
}
}
- //printf("(R) read space: %zu\n", read_space());
+ //std::cerr << "MTB read space: " << read_space() << std::endl;
return count;
}
diff --git a/libs/ardour/ardour/parameter.h b/libs/ardour/ardour/parameter.h
index 5c390c1039..5ccbd4a6e3 100644
--- a/libs/ardour/ardour/parameter.h
+++ b/libs/ardour/ardour/parameter.h
@@ -50,20 +50,6 @@ public:
init_metadata(type);
}
-#if 0
- Parameter(AutomationType type, double min, double max, double normal)
- : Evoral::Parameter((uint32_t)type, 0, 0, min, max, normal)
- {}
-
- Parameter(const Parameter& copy)
- : Evoral::Parameter(copy)
- {
- _min = copy._min;
- _max = copy._max;
- _normal = copy._max;
- }
-#endif
-
Parameter(const Evoral::Parameter& copy)
: Evoral::Parameter(copy)
{
diff --git a/libs/ardour/event_type_map.cc b/libs/ardour/event_type_map.cc
new file mode 100644
index 0000000000..cd78fd02f7
--- /dev/null
+++ b/libs/ardour/event_type_map.cc
@@ -0,0 +1,61 @@
+/*
+ Copyright (C) 2008 Paul Davis
+ Author: Dave 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <ardour/types.h>
+#include <ardour/event_type_map.h>
+#include <evoral/Parameter.hpp>
+#include <evoral/midi_events.h>
+
+namespace ARDOUR {
+
+EventTypeMap EventTypeMap::event_type_map;
+
+bool
+EventTypeMap::type_is_midi(uint32_t type) const
+{
+ return (type >= MidiCCAutomation) && (type <= MidiChannelPressureAutomation);
+}
+
+uint8_t
+EventTypeMap::parameter_midi_type(const Evoral::Parameter& param) const
+{
+ switch (param.type()) {
+ case MidiCCAutomation: return MIDI_CMD_CONTROL; break;
+ case MidiPgmChangeAutomation: return MIDI_CMD_PGM_CHANGE; break;
+ case MidiChannelPressureAutomation: return MIDI_CMD_CHANNEL_PRESSURE; break;
+ case MidiPitchBenderAutomation: return MIDI_CMD_BENDER; break;
+ default: return 0;
+ }
+}
+
+uint32_t
+EventTypeMap::midi_event_type(uint8_t status) const
+{
+ switch (status & 0xF0) {
+ case MIDI_CMD_CONTROL: return MidiCCAutomation; break;
+ case MIDI_CMD_PGM_CHANGE: return MidiPgmChangeAutomation; break;
+ case MIDI_CMD_CHANNEL_PRESSURE: return MidiChannelPressureAutomation; break;
+ case MIDI_CMD_BENDER: return MidiPitchBenderAutomation; break;
+ default: return 0;
+ }
+}
+
+} // namespace ARDOUR
+
diff --git a/libs/ardour/import.cc b/libs/ardour/import.cc
index 199a2fd1a4..370991be5f 100644
--- a/libs/ardour/import.cc
+++ b/libs/ardour/import.cc
@@ -305,7 +305,7 @@ static void
write_midi_data_to_new_files (SMFReader* source, Session::import_status& status,
vector<boost::shared_ptr<Source> >& newfiles)
{
- Evoral::Event ev(0.0, 4, NULL, true);
+ Evoral::Event ev(0, 0.0, 4, NULL, true);
status.progress = 0.0f;
diff --git a/libs/ardour/meter.cc b/libs/ardour/meter.cc
index 363cbe242f..5dee1d9845 100644
--- a/libs/ardour/meter.cc
+++ b/libs/ardour/meter.cc
@@ -47,7 +47,7 @@ PeakMeter::run_in_place (BufferSet& bufs, nframes_t start_frame, nframes_t end_f
// GUI needs a better MIDI meter, not much information can be
// expressed through peaks alone
for (MidiBuffer::iterator i = bufs.get_midi(n).begin(); i != bufs.get_midi(n).end(); ++i) {
- const Evoral::Event& ev = *i;
+ const Evoral::MIDIEvent& ev = *i;
if (ev.is_note_on()) {
const float this_vel = log(ev.buffer()[2] / 127.0 * (M_E*M_E-M_E) + M_E) - 1.0;
//printf("V %d -> %f\n", (int)((Byte)ev.buffer[2]), this_vel);
diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc
index afd8481795..f1f6b9b633 100644
--- a/libs/ardour/midi_buffer.cc
+++ b/libs/ardour/midi_buffer.cc
@@ -115,7 +115,7 @@ MidiBuffer::read_from(const Buffer& src, nframes_t nframes, nframes_t offset)
// FIXME: slow
for (size_t i=0; i < msrc.size(); ++i) {
- const Evoral::Event& ev = msrc[i];
+ const Evoral::MIDIEvent& ev = msrc[i];
if (ev.time() >= offset && ev.time() < offset+nframes) {
//cout << "MidiBuffer::read_from got event, " << int(ev.type()) << " time: " << ev.time() << " buffer size: " << _size << endl;
push_back(ev);
@@ -136,7 +136,7 @@ MidiBuffer::read_from(const Buffer& src, nframes_t nframes, nframes_t offset)
* @return false if operation failed (not enough room)
*/
bool
-MidiBuffer::push_back(const Evoral::Event& ev)
+MidiBuffer::push_back(const Evoral::MIDIEvent& ev)
{
if (_size == _capacity)
return false;
@@ -262,8 +262,8 @@ MidiBuffer::merge(const MidiBuffer& a, const MidiBuffer& b)
push_back(b[b_index]);
++b_index;
} else {
- const Evoral::Event& a_ev = a[a_index];
- const Evoral::Event& b_ev = b[b_index];
+ const Evoral::MIDIEvent& a_ev = a[a_index];
+ const Evoral::MIDIEvent& b_ev = b[b_index];
if (a_ev.time() <= b_ev.time()) {
push_back(a_ev);
diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc
index b2991c1a7f..bb7f2931f4 100644
--- a/libs/ardour/midi_diskstream.cc
+++ b/libs/ardour/midi_diskstream.cc
@@ -520,9 +520,9 @@ MidiDiskstream::process (nframes_t transport_frame, nframes_t nframes, nframes_t
MidiBuffer::iterator port_iter = _source_port->get_midi_buffer().begin();
for (size_t i=0; i < to_write; ++i) {
- const Evoral::Event& ev = *port_iter;
+ const Evoral::MIDIEvent& ev = *port_iter;
assert(ev.buffer());
- _capture_buf->write(ev.time() + transport_frame, ev.size(), ev.buffer());
+ _capture_buf->write(ev.time() + transport_frame, ev.type(), ev.size(), ev.buffer());
++port_iter;
}
diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc
index c22820c83c..18b37689bd 100644
--- a/libs/ardour/midi_model.cc
+++ b/libs/ardour/midi_model.cc
@@ -170,9 +170,9 @@ MidiModel::DeltaCommand::marshal_note(const boost::shared_ptr<Evoral::Note> note
time_str << int(note->time());
xml_note->add_property("time", time_str.str());
- ostringstream duration_str(ios::ate);
- duration_str <<(unsigned int) note->duration();
- xml_note->add_property("duration", duration_str.str());
+ ostringstream length_str(ios::ate);
+ length_str <<(unsigned int) note->length();
+ xml_note->add_property("length", length_str.str());
ostringstream velocity_str(ios::ate);
velocity_str << (unsigned int) note->velocity();
@@ -195,15 +195,15 @@ boost::shared_ptr<Evoral::Note> MidiModel::DeltaCommand::unmarshal_note(XMLNode
istringstream time_str(xml_note->property("time")->value());
time_str >> time;
- unsigned int duration;
- istringstream duration_str(xml_note->property("duration")->value());
- duration_str >> duration;
+ unsigned int length;
+ istringstream length_str(xml_note->property("length")->value());
+ length_str >> length;
unsigned int velocity;
istringstream velocity_str(xml_note->property("velocity")->value());
velocity_str >> velocity;
- boost::shared_ptr<Evoral::Note> note_ptr(new Evoral::Note(channel, time, duration, note, velocity));
+ boost::shared_ptr<Evoral::Note> note_ptr(new Evoral::Note(channel, time, length, note, velocity));
return note_ptr;
}
diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc
index 745e5bf1b7..d60aba8bbc 100644
--- a/libs/ardour/midi_track.cc
+++ b/libs/ardour/midi_track.cc
@@ -723,7 +723,8 @@ MidiTrack::write_immediate_event(size_t size, const uint8_t* buf)
printf("%X ", buf[i]);
}
printf("\n");*/
- return (_immediate_events.write(0, size, buf) == size);
+ const uint32_t type = EventTypeMap::instance().midi_event_type(buf[0]);
+ return (_immediate_events.write(0, type, size, buf) == size);
}
void
diff --git a/libs/ardour/quantize.cc b/libs/ardour/quantize.cc
index ff8925edd9..3b5a264a7b 100644
--- a/libs/ardour/quantize.cc
+++ b/libs/ardour/quantize.cc
@@ -72,12 +72,12 @@ Quantize::run (boost::shared_ptr<Region> r)
for (Evoral::Sequence::Notes::iterator i = model->notes().begin();
i != model->notes().end(); ++i) {
const double new_time = lrint((*i)->time() / q_frames) * q_frames;
- double new_dur = lrint((*i)->duration() / q_frames) * q_frames;
+ double new_dur = lrint((*i)->length() / q_frames) * q_frames;
if (new_dur == 0.0)
new_dur = q_frames;
(*i)->set_time(new_time);
- (*i)->set_duration(new_dur);
+ (*i)->set_length(new_dur);
}
model->set_edited(true);
diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc
index 2d5c0af0d5..03a8b98199 100644
--- a/libs/ardour/smf_source.cc
+++ b/libs/ardour/smf_source.cc
@@ -39,6 +39,7 @@
#include <ardour/tempo.h>
#include <ardour/audioengine.h>
#include <ardour/smf_reader.h>
+#include <ardour/event_type_map.h>
#include "i18n.h"
@@ -385,6 +386,7 @@ SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, n
// Output parameters for read_event (which will allocate scratch in buffer as needed)
uint32_t ev_delta_t = 0;
+ uint32_t ev_type = 0;
uint32_t ev_size = 0;
uint8_t* ev_buffer = 0;
@@ -407,6 +409,8 @@ SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, n
break;
}
+ ev_type = EventTypeMap::instance().midi_event_type(ev_buffer[0]);
+
time += ev_delta_t; // accumulate delta time
if (ret == 0) { // meta-event (skipped, just accumulate time)
@@ -419,7 +423,7 @@ SMFSource::read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, n
((time / (double)_ppqn) * frames_per_beat)) + stamp_offset;
if (ev_frame_time <= start + cnt)
- dst.write(ev_frame_time - negative_stamp_offset, ev_size, ev_buffer);
+ dst.write(ev_frame_time - negative_stamp_offset, ev_type, ev_size, ev_buffer);
else
break;
}
@@ -441,8 +445,9 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt)
{
_write_data_count = 0;
- double time;
- size_t size;
+ EventTime time;
+ EventType type;
+ uint32_t size;
size_t buf_capacity = 4;
uint8_t* buf = (uint8_t*)malloc(buf_capacity);
@@ -450,14 +455,14 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt)
if (_model && ! _model->writing())
_model->start_write();
- Evoral::Event ev(0.0, 4, NULL, true);
+ Evoral::MIDIEvent ev(0, 0.0, 4, NULL, true);
while (true) {
- bool ret = src.full_peek(sizeof(double), (uint8_t*)&time);
+ bool ret = src.peek_time(&time);
if (!ret || time - _timeline_position > _length + cnt)
break;
- ret = src.read_prefix(&time, &size);
+ ret = src.read_prefix(&time, &type, &size);
if (!ret)
break;
@@ -476,6 +481,7 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt)
time -= _timeline_position;
ev.set(buf, size, time);
+ ev.set_event_type(EventTypeMap::instance().midi_event_type(ev.buffer()[0]));
if (! (ev.is_channel_event() || ev.is_smf_meta_event() || ev.is_sysex()) ) {
//cerr << "SMFSource: WARNING: caller tried to write non SMF-Event of type " << std::hex << int(ev.buffer()[0]) << endl;
continue;