2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2006 Paul Davis
|
|
|
|
Written by Dave Robillard, 2006
|
|
|
|
|
|
|
|
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 <vector>
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/mountpoint.h"
|
|
|
|
#include "pbd/pathscanner.h"
|
|
|
|
#include "pbd/stl_delete.h"
|
|
|
|
#include "pbd/strsplit.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "evoral/SMFReader.hpp"
|
|
|
|
#include "evoral/Control.hpp"
|
2008-09-29 20:45:26 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/audioengine.h"
|
|
|
|
#include "ardour/event_type_map.h"
|
|
|
|
#include "ardour/midi_model.h"
|
|
|
|
#include "ardour/midi_ring_buffer.h"
|
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/smf_source.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2009-02-16 21:11:49 -05:00
|
|
|
using namespace Glib;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-15 12:30:42 -05:00
|
|
|
/** Constructor used for new internal-to-session files. File cannot exist. */
|
2009-02-16 21:11:49 -05:00
|
|
|
SMFSource::SMFSource (Session& s, const ustring& path, bool embedded, Source::Flag flags)
|
|
|
|
: Source(s, DataType::MIDI, path, flags)
|
|
|
|
, MidiSource(s, path)
|
|
|
|
, FileSource(s, DataType::MIDI, path, embedded, flags)
|
2009-02-14 20:53:06 -05:00
|
|
|
, Evoral::SMF()
|
2009-02-15 12:30:42 -05:00
|
|
|
, _last_ev_time_beats(0.0)
|
|
|
|
, _last_ev_time_frames(0)
|
2009-09-15 21:08:51 -04:00
|
|
|
, _smf_last_read_end (0)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-02-16 21:11:49 -05:00
|
|
|
if (init(_name, false)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
throw failed_constructor ();
|
|
|
|
}
|
|
|
|
|
2009-02-14 15:52:15 -05:00
|
|
|
if (create(path)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
throw failed_constructor ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-16 21:11:49 -05:00
|
|
|
/** Constructor used for existing internal-to-session files. */
|
|
|
|
SMFSource::SMFSource (Session& s, const XMLNode& node, bool must_exist)
|
|
|
|
: Source(s, node)
|
|
|
|
, MidiSource(s, node)
|
|
|
|
, FileSource(s, node, must_exist)
|
2009-02-15 12:30:42 -05:00
|
|
|
, _last_ev_time_beats(0.0)
|
|
|
|
, _last_ev_time_frames(0)
|
2009-09-15 21:08:51 -04:00
|
|
|
, _smf_last_read_end (0)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-02-14 20:53:06 -05:00
|
|
|
if (set_state(node)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
throw failed_constructor ();
|
|
|
|
}
|
|
|
|
|
2009-02-14 20:53:06 -05:00
|
|
|
if (init(_name, true)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
throw failed_constructor ();
|
|
|
|
}
|
|
|
|
|
2008-09-29 20:45:26 -04:00
|
|
|
if (open(_path)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
throw failed_constructor ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SMFSource::~SMFSource ()
|
|
|
|
{
|
|
|
|
if (removable()) {
|
|
|
|
unlink (_path.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** All stamps in audio frames */
|
|
|
|
nframes_t
|
2009-04-30 17:56:40 -04:00
|
|
|
SMFSource::read_unlocked (MidiRingBuffer<nframes_t>& destination, sframes_t source_start,
|
2009-04-14 06:13:06 -04:00
|
|
|
sframes_t start, nframes_t duration,
|
2009-02-19 00:45:11 -05:00
|
|
|
sframes_t stamp_offset, sframes_t negative_stamp_offset) const
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-02-16 21:11:49 -05:00
|
|
|
int ret = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
uint64_t time = 0; // in SMF ticks, 1 tick per _ppqn
|
|
|
|
|
|
|
|
_read_data_count = 0;
|
|
|
|
|
|
|
|
// Output parameters for read_event (which will allocate scratch in buffer as needed)
|
|
|
|
uint32_t ev_delta_t = 0;
|
2009-02-14 20:53:06 -05:00
|
|
|
uint32_t ev_type = 0;
|
|
|
|
uint32_t ev_size = 0;
|
|
|
|
uint8_t* ev_buffer = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
size_t scratch_size = 0; // keep track of scratch to minimize reallocs
|
2009-02-18 23:12:54 -05:00
|
|
|
|
2009-04-30 17:56:40 -04:00
|
|
|
BeatsFramesConverter converter(_session, source_start);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-18 23:12:54 -05:00
|
|
|
const uint64_t start_ticks = (uint64_t)(converter.from(start) * ppqn());
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-09-21 11:43:11 -04:00
|
|
|
if (_smf_last_read_end == 0 || start != _smf_last_read_end) {
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
//cerr << "SMFSource::read_unlocked seeking to " << start << endl;
|
2009-02-14 21:09:58 -05:00
|
|
|
Evoral::SMF::seek_to_start();
|
|
|
|
while (time < start_ticks) {
|
|
|
|
ret = read_event(&ev_delta_t, &ev_size, &ev_buffer);
|
|
|
|
if (ret == -1) { // EOF
|
2009-09-15 21:08:51 -04:00
|
|
|
_smf_last_read_end = start + duration;
|
2009-04-14 06:13:06 -04:00
|
|
|
return duration;
|
2009-02-14 21:09:58 -05:00
|
|
|
}
|
|
|
|
time += ev_delta_t; // accumulate delta time
|
|
|
|
}
|
2009-09-21 11:43:11 -04:00
|
|
|
}
|
2009-02-14 21:09:58 -05:00
|
|
|
|
2009-09-15 21:08:51 -04:00
|
|
|
_smf_last_read_end = start + duration;
|
2009-02-14 21:09:58 -05:00
|
|
|
|
2009-02-15 14:44:27 -05:00
|
|
|
while (true) {
|
2009-02-14 21:09:58 -05:00
|
|
|
ret = read_event(&ev_delta_t, &ev_size, &ev_buffer);
|
2008-06-02 17:41:35 -04:00
|
|
|
if (ret == -1) { // EOF
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
time += ev_delta_t; // accumulate delta time
|
|
|
|
|
|
|
|
if (ret == 0) { // meta-event (skipped, just accumulate time)
|
|
|
|
continue;
|
|
|
|
}
|
2009-02-15 15:50:20 -05:00
|
|
|
|
|
|
|
ev_type = EventTypeMap::instance().midi_event_type(ev_buffer[0]);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-09-21 11:43:11 -04:00
|
|
|
#if 0
|
|
|
|
cerr << "+++ SMF source read "
|
|
|
|
<< " delta = " << ev_delta_t
|
|
|
|
<< " time = " << time
|
|
|
|
<< " buf[0] " << hex << (int) ev_buffer[0] << dec
|
|
|
|
<< " type = " << ev_type;
|
|
|
|
#endif
|
|
|
|
|
2009-02-14 21:09:58 -05:00
|
|
|
assert(time >= start_ticks);
|
2009-02-19 00:45:11 -05:00
|
|
|
const sframes_t ev_frame_time = converter.to(time / (double)ppqn()) + stamp_offset;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-09-21 11:43:11 -04:00
|
|
|
#if 0
|
|
|
|
cerr << " frames = " << ev_frame_time
|
|
|
|
<< " w/offset = " << ev_frame_time - negative_stamp_offset
|
|
|
|
<< endl;
|
|
|
|
#endif
|
|
|
|
|
2009-04-14 06:13:06 -04:00
|
|
|
if (ev_frame_time < start + duration) {
|
|
|
|
destination.write(ev_frame_time - negative_stamp_offset, ev_type, ev_size, ev_buffer);
|
2009-02-14 21:09:58 -05:00
|
|
|
} else {
|
|
|
|
break;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-09-21 11:43:11 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
_read_data_count += ev_size;
|
|
|
|
|
2009-02-14 20:53:06 -05:00
|
|
|
if (ev_size > scratch_size) {
|
2008-06-02 17:41:35 -04:00
|
|
|
scratch_size = ev_size;
|
2009-02-14 20:53:06 -05:00
|
|
|
}
|
2009-02-14 22:51:49 -05:00
|
|
|
ev_size = scratch_size; // ensure read_event only allocates if necessary
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-04-14 06:13:06 -04:00
|
|
|
return duration;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/** All stamps in audio frames */
|
|
|
|
nframes_t
|
2009-04-14 06:13:06 -04:00
|
|
|
SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& source, sframes_t position, nframes_t duration)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
_write_data_count = 0;
|
|
|
|
|
2009-04-16 10:34:56 -04:00
|
|
|
nframes_t time;
|
|
|
|
Evoral::EventType type;
|
|
|
|
uint32_t size;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-14 20:53:06 -05:00
|
|
|
size_t buf_capacity = 4;
|
|
|
|
uint8_t* buf = (uint8_t*)malloc(buf_capacity);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-14 20:53:06 -05:00
|
|
|
if (_model && ! _model->writing()) {
|
2008-06-02 17:41:35 -04:00
|
|
|
_model->start_write();
|
2009-02-14 20:53:06 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-19 19:30:42 -05:00
|
|
|
Evoral::MIDIEvent<nframes_t> ev;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
while (true) {
|
2009-04-16 10:34:56 -04:00
|
|
|
bool ret = source.peek_time(&time);
|
|
|
|
if (!ret || time > _last_write_end + duration) {
|
2008-06-02 17:41:35 -04:00
|
|
|
break;
|
2009-02-14 20:53:06 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-04-16 10:34:56 -04:00
|
|
|
ret = source.read_prefix(&time, &type, &size);
|
2009-02-14 20:53:06 -05:00
|
|
|
if (!ret) {
|
2009-02-19 19:30:42 -05:00
|
|
|
cerr << "ERROR: Unable to read event prefix, corrupt MIDI ring buffer" << endl;
|
2008-06-02 17:41:35 -04:00
|
|
|
break;
|
2009-02-14 20:53:06 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-04-16 10:34:56 -04:00
|
|
|
if (size > buf_capacity) {
|
|
|
|
buf_capacity = size;
|
|
|
|
buf = (uint8_t*)realloc(buf, size);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-04-16 10:34:56 -04:00
|
|
|
ret = source.read_contents(size, buf);
|
2008-06-02 17:41:35 -04:00
|
|
|
if (!ret) {
|
2009-04-16 10:34:56 -04:00
|
|
|
cerr << "ERROR: Read time/size but not buffer, corrupt MIDI ring buffer" << endl;
|
2008-06-02 17:41:35 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-16 10:34:56 -04:00
|
|
|
assert(time >= position);
|
|
|
|
time -= position;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-04-16 10:34:56 -04:00
|
|
|
ev.set(buf, size, time);
|
2008-09-22 12:28:02 -04:00
|
|
|
ev.set_event_type(EventTypeMap::instance().midi_event_type(ev.buffer()[0]));
|
2009-02-14 20:53:06 -05:00
|
|
|
if (!(ev.is_channel_event() || ev.is_smf_meta_event() || ev.is_sysex())) {
|
2009-02-14 20:24:26 -05:00
|
|
|
cerr << "SMFSource: WARNING: caller tried to write non SMF-Event of type "
|
|
|
|
<< std::hex << int(ev.buffer()[0]) << endl;
|
2008-06-02 17:41:35 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-02-18 23:12:54 -05:00
|
|
|
append_event_unlocked_frames(ev, position);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-01-28 19:18:26 -05:00
|
|
|
if (_model) {
|
2009-02-14 12:59:58 -05:00
|
|
|
set_default_controls_interpolation();
|
2009-01-28 19:18:26 -05:00
|
|
|
}
|
|
|
|
|
2009-02-14 20:32:41 -05:00
|
|
|
Evoral::SMF::flush();
|
2008-06-02 17:41:35 -04:00
|
|
|
free(buf);
|
|
|
|
|
2009-04-14 06:13:06 -04:00
|
|
|
ViewDataRangeReady(position + _last_write_end, duration); /* EMIT SIGNAL */
|
2009-02-15 12:30:42 -05:00
|
|
|
|
2009-04-14 06:13:06 -04:00
|
|
|
return duration;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-15 12:30:42 -05:00
|
|
|
/** Append an event with a timestamp in beats (double) */
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
2009-02-16 21:11:49 -05:00
|
|
|
SMFSource::append_event_unlocked_beats (const Evoral::Event<double>& ev)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-02-01 16:04:12 -05:00
|
|
|
if (ev.size() == 0) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return;
|
2009-02-01 16:04:12 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-15 12:30:42 -05:00
|
|
|
/*printf("SMFSource: %s - append_event_unlocked_beats time = %lf, size = %u, data = ",
|
2009-02-01 16:04:12 -05:00
|
|
|
name().c_str(), ev.time(), ev.size());
|
2009-02-15 12:30:42 -05:00
|
|
|
for (size_t i = 0; i < ev.size(); ++i) printf("%X ", ev.buffer()[i]); printf("\n");*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
assert(ev.time() >= 0);
|
2009-02-15 12:30:42 -05:00
|
|
|
if (ev.time() < _last_ev_time_beats) {
|
|
|
|
cerr << "SMFSource: Warning: Skipping event with non-monotonic time" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-19 19:30:42 -05:00
|
|
|
_length_beats = max(_length_beats, ev.time());
|
|
|
|
|
2009-02-15 12:30:42 -05:00
|
|
|
const double delta_time_beats = ev.time() - _last_ev_time_beats;
|
|
|
|
const uint32_t delta_time_ticks = (uint32_t)lrint(delta_time_beats * (double)ppqn());
|
2009-09-14 12:01:32 -04:00
|
|
|
|
2009-02-15 12:30:42 -05:00
|
|
|
Evoral::SMF::append_event_delta(delta_time_ticks, ev.size(), ev.buffer());
|
|
|
|
_last_ev_time_beats = ev.time();
|
|
|
|
|
|
|
|
_write_data_count += ev.size();
|
|
|
|
|
|
|
|
if (_model) {
|
|
|
|
_model->append(ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Append an event with a timestamp in frames (nframes_t) */
|
|
|
|
void
|
2009-02-19 00:45:11 -05:00
|
|
|
SMFSource::append_event_unlocked_frames (const Evoral::Event<nframes_t>& ev, sframes_t position)
|
2009-02-15 12:30:42 -05:00
|
|
|
{
|
|
|
|
if (ev.size() == 0) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return;
|
|
|
|
}
|
2009-02-15 12:30:42 -05:00
|
|
|
|
|
|
|
/*printf("SMFSource: %s - append_event_unlocked_frames time = %u, size = %u, data = ",
|
|
|
|
name().c_str(), ev.time(), ev.size());
|
|
|
|
for (size_t i=0; i < ev.size(); ++i) printf("%X ", ev.buffer()[i]); printf("\n");*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-15 12:30:42 -05:00
|
|
|
if (ev.time() < _last_ev_time_frames) {
|
|
|
|
cerr << "SMFSource: Warning: Skipping event with non-monotonic time" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-18 23:12:54 -05:00
|
|
|
BeatsFramesConverter converter(_session, position);
|
|
|
|
|
2009-02-19 19:30:42 -05:00
|
|
|
_length_beats = max(_length_beats, converter.from(ev.time()));
|
|
|
|
|
2009-02-19 00:45:11 -05:00
|
|
|
const sframes_t delta_time_frames = ev.time() - _last_ev_time_frames;
|
2009-02-18 23:12:54 -05:00
|
|
|
const double delta_time_beats = converter.from(delta_time_frames);
|
2009-02-15 21:51:16 -05:00
|
|
|
const uint32_t delta_time_ticks = (uint32_t)(lrint(delta_time_beats * (double)ppqn()));
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-15 21:51:16 -05:00
|
|
|
Evoral::SMF::append_event_delta(delta_time_ticks, ev.size(), ev.buffer());
|
2009-02-15 12:30:42 -05:00
|
|
|
_last_ev_time_frames = ev.time();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
_write_data_count += ev.size();
|
2009-02-15 12:30:42 -05:00
|
|
|
|
|
|
|
if (_model) {
|
2009-02-18 23:12:54 -05:00
|
|
|
const double ev_time_beats = converter.from(ev.time());
|
2009-02-15 12:30:42 -05:00
|
|
|
const Evoral::Event<double> beat_ev(
|
2009-02-15 21:51:16 -05:00
|
|
|
ev.event_type(), ev_time_beats, ev.size(), (uint8_t*)ev.buffer());
|
2009-02-15 12:30:42 -05:00
|
|
|
_model->append(beat_ev);
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode&
|
|
|
|
SMFSource::get_state ()
|
|
|
|
{
|
2009-02-16 21:11:49 -05:00
|
|
|
return MidiSource::get_state();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SMFSource::set_state (const XMLNode& node)
|
|
|
|
{
|
2009-02-16 21:11:49 -05:00
|
|
|
if (Source::set_state (node)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
if (MidiSource::set_state (node)) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-16 21:11:49 -05:00
|
|
|
|
|
|
|
if (FileSource::set_state (node)) {
|
|
|
|
return -1;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-19 00:45:11 -05:00
|
|
|
SMFSource::mark_streaming_midi_write_started (NoteMode mode, sframes_t start_frame)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
MidiSource::mark_streaming_midi_write_started (mode, start_frame);
|
2009-02-14 20:32:41 -05:00
|
|
|
Evoral::SMF::begin_write ();
|
2009-02-15 12:30:42 -05:00
|
|
|
_last_ev_time_beats = 0.0;
|
|
|
|
_last_ev_time_frames = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SMFSource::mark_streaming_write_completed ()
|
|
|
|
{
|
|
|
|
MidiSource::mark_streaming_write_completed();
|
|
|
|
|
|
|
|
if (!writable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_model->set_edited(false);
|
2009-02-14 20:32:41 -05:00
|
|
|
Evoral::SMF::end_write ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-02-16 21:11:49 -05:00
|
|
|
SMFSource::safe_midi_file_extension (const Glib::ustring& file)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
return (file.rfind(".mid") != Glib::ustring::npos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-16 21:11:49 -05:00
|
|
|
SMFSource::load_model (bool lock, bool force_reload)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-01-27 23:55:31 -05:00
|
|
|
if (_writing) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return;
|
2009-01-27 23:55:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lock) {
|
2008-06-02 17:41:35 -04:00
|
|
|
Glib::Mutex::Lock lm (_lock);
|
2009-01-27 23:55:31 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-02-15 14:44:27 -05:00
|
|
|
if (_model && !force_reload) {
|
2008-06-02 17:41:35 -04:00
|
|
|
return;
|
2009-01-27 23:55:31 -05:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
if (! _model) {
|
|
|
|
_model = boost::shared_ptr<MidiModel>(new MidiModel(this));
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
//cerr << _name << " loaded new model " << _model.get() << endl;
|
2008-06-02 17:41:35 -04:00
|
|
|
} else {
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
/*cerr << _name << " reloading model " << _model.get()
|
|
|
|
<< " (" << _model->n_notes() << " notes)" << endl;*/
|
2008-06-02 17:41:35 -04:00
|
|
|
_model->clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
_model->start_write();
|
2009-02-14 20:32:41 -05:00
|
|
|
Evoral::SMF::seek_to_start();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
uint64_t time = 0; /* in SMF ticks */
|
2009-02-01 21:36:05 -05:00
|
|
|
Evoral::Event<double> ev;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
size_t scratch_size = 0; // keep track of scratch and minimize reallocs
|
|
|
|
|
|
|
|
uint32_t delta_t = 0;
|
|
|
|
uint32_t size = 0;
|
|
|
|
uint8_t* buf = NULL;
|
|
|
|
int ret;
|
|
|
|
while ((ret = read_event(&delta_t, &size, &buf)) >= 0) {
|
|
|
|
time += delta_t;
|
2009-02-15 12:30:42 -05:00
|
|
|
ev.set(buf, size, time / (double)ppqn());
|
2009-09-14 12:01:32 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (ret > 0) { // didn't skip (meta) event
|
2008-09-22 12:59:32 -04:00
|
|
|
ev.set_event_type(EventTypeMap::instance().midi_event_type(buf[0]));
|
2008-06-02 17:41:35 -04:00
|
|
|
_model->append(ev);
|
|
|
|
}
|
|
|
|
|
2009-01-27 23:55:31 -05:00
|
|
|
if (ev.size() > scratch_size) {
|
2008-06-02 17:41:35 -04:00
|
|
|
scratch_size = ev.size();
|
2009-01-27 23:55:31 -05:00
|
|
|
}
|
2009-02-14 22:51:49 -05:00
|
|
|
ev.size() = scratch_size; // ensure read_event only allocates if necessary
|
2009-02-19 19:30:42 -05:00
|
|
|
|
|
|
|
_length_beats = max(_length_beats, ev.time());
|
2009-01-27 23:55:31 -05:00
|
|
|
}
|
|
|
|
|
2009-02-14 12:59:58 -05:00
|
|
|
set_default_controls_interpolation();
|
2009-01-28 19:18:26 -05:00
|
|
|
|
|
|
|
_model->end_write(false);
|
|
|
|
_model->set_edited(false);
|
|
|
|
|
2009-02-15 17:10:32 -05:00
|
|
|
_model_iter = _model->begin();
|
|
|
|
|
2009-01-28 19:18:26 -05:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LINEAR_INTERPOLATION_MODE_WORKS_PROPERLY 0
|
|
|
|
|
|
|
|
void
|
2009-02-16 21:11:49 -05:00
|
|
|
SMFSource::set_default_controls_interpolation ()
|
2009-01-28 19:18:26 -05:00
|
|
|
{
|
2009-01-27 23:55:31 -05:00
|
|
|
// set interpolation style to defaults, can be changed by the GUI later
|
|
|
|
Evoral::ControlSet::Controls controls = _model->controls();
|
|
|
|
for (Evoral::ControlSet::Controls::iterator c = controls.begin(); c != controls.end(); ++c) {
|
|
|
|
(*c).second->list()->set_interpolation(
|
2009-01-28 04:49:42 -05:00
|
|
|
// to be enabled when ControlList::rt_safe_earliest_event_linear_unlocked works properly
|
2009-01-28 19:18:26 -05:00
|
|
|
#if LINEAR_INTERPOLATION_MODE_WORKS_PROPERLY
|
2009-01-27 23:55:31 -05:00
|
|
|
EventTypeMap::instance().interpolation_of((*c).first));
|
2009-01-28 04:49:42 -05:00
|
|
|
#else
|
|
|
|
Evoral::ControlList::Discrete);
|
|
|
|
#endif
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-02-16 21:11:49 -05:00
|
|
|
SMFSource::destroy_model ()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
//cerr << _name << " destroying model " << _model.get() << endl;
|
|
|
|
_model.reset();
|
|
|
|
}
|
|
|
|
|
2008-09-29 20:45:26 -04:00
|
|
|
void
|
2009-02-16 21:11:49 -05:00
|
|
|
SMFSource::flush_midi ()
|
2008-09-29 20:45:26 -04:00
|
|
|
{
|
2009-02-14 20:32:41 -05:00
|
|
|
Evoral::SMF::end_write();
|
2008-09-29 20:45:26 -04:00
|
|
|
}
|
|
|
|
|