summaryrefslogtreecommitdiff
path: root/libs/ardour
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-06-09 13:00:54 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-06-09 13:00:54 +0000
commit1e728e728a79d9b272cc18bc1c46f0c3c8831bf8 (patch)
tree6ecd938ef19be41d6489540bca740f7a67d88de1 /libs/ardour
parent8f263c239a2090d43221d817442c8141dd439079 (diff)
basically, fix all kinds of odds and ends with MIDI playback, including missed notes and applying gain
git-svn-id: svn://localhost/ardour2/branches/3.0@7247 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour')
-rw-r--r--libs/ardour/amp.cc5
-rw-r--r--libs/ardour/audio_port.cc4
-rw-r--r--libs/ardour/audioengine.cc40
-rw-r--r--libs/ardour/delivery.cc2
-rw-r--r--libs/ardour/graph.cc14
-rw-r--r--libs/ardour/midi_buffer.cc35
-rw-r--r--libs/ardour/midi_playlist.cc4
-rw-r--r--libs/ardour/midi_port.cc10
-rw-r--r--libs/ardour/midi_ring_buffer.cc15
-rw-r--r--libs/ardour/midi_track.cc10
-rw-r--r--libs/ardour/port.cc1
11 files changed, 106 insertions, 34 deletions
diff --git a/libs/ardour/amp.cc b/libs/ardour/amp.cc
index ceb593f4c3..a739b59088 100644
--- a/libs/ardour/amp.cc
+++ b/libs/ardour/amp.cc
@@ -167,9 +167,8 @@ Amp::apply_gain (BufferSet& bufs, nframes_t nframes, gain_t initial, gain_t targ
Evoral::MIDIEvent<MidiBuffer::TimeType> ev = *m;
if (ev.is_note_on()) {
- gain_t scale = delta * (ev.time()/nframes);
- std::cerr << "scale by " << scale << " for " << ev.time() << " of " << nframes << std::endl;
- ev.scale_velocity (scale);
+ gain_t scale = delta * (ev.time()/(double) nframes);
+ ev.scale_velocity (initial+scale);
}
}
}
diff --git a/libs/ardour/audio_port.cc b/libs/ardour/audio_port.cc
index a75f7d7a09..71ec7c6289 100644
--- a/libs/ardour/audio_port.cc
+++ b/libs/ardour/audio_port.cc
@@ -98,8 +98,8 @@ AudioPort::get_audio_buffer (nframes_t nframes, nframes_t offset)
}
size_t
-AudioPort::raw_buffer_size(nframes_t nframes) const
+AudioPort::raw_buffer_size (nframes_t nframes) const
{
- return nframes * sizeof(float);
+ return nframes * sizeof (Sample);
}
diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc
index a16f268edd..d2cf8d12a4 100644
--- a/libs/ardour/audioengine.cc
+++ b/libs/ardour/audioengine.cc
@@ -232,6 +232,15 @@ AudioEngine::start ()
}
_raw_buffer_sizes[DataType::AUDIO] = blocksize * sizeof(float);
+
+ jack_port_t* midi_port = jack_port_register (_priv_jack, "m", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
+ if (!midi_port) {
+ error << _("Cannot create temporary MIDI port to determine MIDI buffer size") << endmsg;
+ } else {
+ _raw_buffer_sizes[DataType::MIDI] = jack_midi_max_event_size (jack_port_get_buffer(midi_port, blocksize));
+ cerr << "MIDI port buffers = " << _raw_buffer_sizes[DataType::MIDI] << endl;
+ jack_port_unregister (_priv_jack, midi_port);
+ }
}
return _running ? 0 : -1;
@@ -420,6 +429,7 @@ AudioEngine::process_thread ()
jack_nframes_t nframes = jack_cycle_wait (_jack);
if (process_callback (nframes)) {
+ cerr << "--- process\n";
return 0;
}
@@ -583,16 +593,40 @@ AudioEngine::_bufsize_callback (nframes_t nframes, void *arg)
int
AudioEngine::jack_bufsize_callback (nframes_t nframes)
{
+ bool need_midi_size = true;
+ bool need_audio_size = true;
+
_buffer_size = nframes;
- _raw_buffer_sizes[DataType::AUDIO] = nframes * sizeof(float);
- cout << "FIXME: Assuming maximum MIDI buffer size " << nframes * 4 << "bytes" << endl;
- _raw_buffer_sizes[DataType::MIDI] = nframes * 4;
_usecs_per_cycle = (int) floor ((((double) nframes / frame_rate())) * 1000000.0);
last_monitor_check = 0;
boost::shared_ptr<Ports> p = ports.reader();
+ /* crude guesses, see below where we try to get the right answers.
+
+ Note that our guess for MIDI deliberatey tries to overestimate
+ by a little. It would be nicer if we could get the actual
+ size from a port, but we have to use this estimate in the
+ event that there are no MIDI ports currently. If there are
+ the value will be adjusted below.
+ */
+
+ _raw_buffer_sizes[DataType::AUDIO] = nframes * sizeof (Sample);
+ _raw_buffer_sizes[DataType::MIDI] = nframes * 4 - (nframes/2);
+
for (Ports::iterator i = p->begin(); i != p->end(); ++i) {
+
+ if (need_audio_size && (*i)->type() == DataType::AUDIO) {
+ _raw_buffer_sizes[DataType::AUDIO] = (*i)->raw_buffer_size (nframes);
+ need_audio_size = false;
+ }
+
+
+ if (need_midi_size && (*i)->type() == DataType::MIDI) {
+ _raw_buffer_sizes[DataType::MIDI] = (*i)->raw_buffer_size (nframes);
+ need_midi_size = false;
+ }
+
(*i)->reset();
}
diff --git a/libs/ardour/delivery.cc b/libs/ardour/delivery.cc
index d815a06b4f..cb8dc539a2 100644
--- a/libs/ardour/delivery.cc
+++ b/libs/ardour/delivery.cc
@@ -446,7 +446,7 @@ Delivery::flush (nframes_t nframes, nframes64_t time)
/* io_lock, not taken: function must be called from Session::process() calltree */
PortSet& ports (_output->ports());
-
+
for (PortSet::iterator i = ports.begin(); i != ports.end(); ++i) {
(*i).flush_buffers (nframes, time, _output_offset);
}
diff --git a/libs/ardour/graph.cc b/libs/ardour/graph.cc
index 4cb8d56da4..5e62ba0d6f 100644
--- a/libs/ardour/graph.cc
+++ b/libs/ardour/graph.cc
@@ -220,7 +220,7 @@ Graph::rechain (boost::shared_ptr<RouteList> routelist)
pthread_mutex_lock (&_swap_mutex);
int chain = _setup_chain;
- printf ("============== setup %d\n", chain);
+ DEBUG_TRACE (DEBUG::Graph, string_compose ("============== setup %1\n", chain));
// set all refcounts to 0;
_init_finished_refcount[chain] = 0;
@@ -393,21 +393,21 @@ Graph::dump (int chain)
chain = _pending_chain;
- printf ("--------------------------------------------Graph dump:\n" );
+ DEBUG_TRACE (DEBUG::Graph, "--------------------------------------------Graph dump:\n");
for (ni=_nodes_rt[chain].begin(); ni!=_nodes_rt[chain].end(); ni++) {
boost::shared_ptr<Route> rp = boost::dynamic_pointer_cast<Route>( *ni);
- printf ("GraphNode: %s refcount: %d\n", rp->name().c_str(), (*ni)->_init_refcount[chain] );
+ DEBUG_TRACE (DEBUG::Graph, string_compose ("GraphNode: %1 refcount: %2\n", rp->name().c_str(), (*ni)->_init_refcount[chain]));
for (ai=(*ni)->_activation_set[chain].begin(); ai!=(*ni)->_activation_set[chain].end(); ai++) {
- printf (" triggers: %s\n", boost::dynamic_pointer_cast<Route>(*ai)->name().c_str() );
+ DEBUG_TRACE (DEBUG::Graph, string_compose (" triggers: %1\n", boost::dynamic_pointer_cast<Route>(*ai)->name().c_str()));
}
}
- printf ("------------- trigger list:\n" );
+ DEBUG_TRACE (DEBUG::Graph, "------------- trigger list:\n");
for (ni=_init_trigger_list[chain].begin(); ni!=_init_trigger_list[chain].end(); ni++) {
- printf ("GraphNode: %s refcount: %d\n", boost::dynamic_pointer_cast<Route>(*ni)->name().c_str(), (*ni)->_init_refcount[chain] );
+ DEBUG_TRACE (DEBUG::Graph, string_compose ("GraphNode: %1 refcount: %2\n", boost::dynamic_pointer_cast<Route>(*ni)->name().c_str(), (*ni)->_init_refcount[chain]));
}
- printf ("final activation refcount: %d\n", _init_finished_refcount[chain] );
+ DEBUG_TRACE (DEBUG::Graph, string_compose ("final activation refcount: %1\n", _init_finished_refcount[chain]));
#endif
}
diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc
index cbf7603c96..8299d811f6 100644
--- a/libs/ardour/midi_buffer.cc
+++ b/libs/ardour/midi_buffer.cc
@@ -18,11 +18,17 @@
*/
#include <iostream>
+
#include "pbd/malign.h"
+#include "pbd/compose.h"
+#include "pbd/debug.h"
+
+#include "ardour/debug.h"
#include "ardour/midi_buffer.h"
using namespace std;
using namespace ARDOUR;
+using namespace PBD;
// FIXME: mirroring for MIDI buffers?
MidiBuffer::MidiBuffer(size_t capacity)
@@ -93,7 +99,10 @@ MidiBuffer::read_from (const Buffer& src, nframes_t nframes, nframes_t dst_offse
const Evoral::MIDIEvent<TimeType> ev(*i, false);
if (ev.time() >= src_offset && ev.time() < (nframes+src_offset)) {
push_back (ev);
- }
+ } else {
+ cerr << "MIDI event @ " << ev.time() << " skipped, not within range " << src_offset << " .. "
+ << (nframes + src_offset) << endl;
+ }
}
_silent = src.silent();
@@ -128,7 +137,7 @@ MidiBuffer::push_back(const Evoral::MIDIEvent<TimeType>& ev)
cerr << "MidiBuffer::push_back failed (buffer is full)" << endl;
return false;
}
-
+
if (!Evoral::midi_event_is_valid(ev.buffer(), ev.size())) {
cerr << "WARNING: MidiBuffer ignoring illegal MIDI event" << endl;
return false;
@@ -147,8 +156,22 @@ bool
MidiBuffer::push_back(TimeType time, size_t size, const uint8_t* data)
{
const size_t stamp_size = sizeof(TimeType);
- /*cerr << "MidiBuffer: pushing event @ " << ev.time()
- << " size = " << ev.size() << endl;*/
+
+#ifndef NDEBUG
+ DEBUG_STR_DECL(a);
+ DEBUG_STR_APPEND(a, string_compose ("midibuffer %1 push event @ %2 sz %3 ", this, time, size));
+ for (size_t i=0; i < size; ++i) {
+ DEBUG_STR_APPEND(a,hex);
+ DEBUG_STR_APPEND(a,"0x");
+ DEBUG_STR_APPEND(a,(int)data[i]);
+ DEBUG_STR_APPEND(a,' ');
+ }
+ DEBUG_STR_APPEND(a,'\n');
+ DEBUG_TRACE (DEBUG::MidiIO, DEBUG_STR(a).str());
+#endif
+
+ // cerr << "MidiBuffer: pushing event @ " << time
+ // << " size = " << size << endl;
if (_size + stamp_size + size >= _capacity) {
cerr << "MidiBuffer::push_back failed (buffer is full)" << endl;
@@ -302,10 +325,12 @@ MidiBuffer::merge_in_place(const MidiBuffer &other)
++them;
}
+#if 0
if (us != end())
cerr << "us @ " << (*us).time() << endl;
if (them != other.end())
cerr << "them @ " << (*them).time() << endl;
+#endif
if (sz) {
assert(src >= 0);
@@ -342,7 +367,7 @@ MidiBuffer::merge_in_place(const MidiBuffer &other)
size_t test_final_count = 0;
test_time = 0;
for (iterator i = begin(); i != end(); ++i) {
- cerr << "CHECK " << test_final_count << " / " << test_us_count + test_them_count << endl;
+ // cerr << "CHECK " << test_final_count << " / " << test_us_count + test_them_count << endl;
assert(Evoral::midi_event_is_valid((*i).buffer(), (*i).size()));
assert((*i).time() >= test_time);
test_time = (*i).time();
diff --git a/libs/ardour/midi_playlist.cc b/libs/ardour/midi_playlist.cc
index eec0cde0db..89b5914753 100644
--- a/libs/ardour/midi_playlist.cc
+++ b/libs/ardour/midi_playlist.cc
@@ -163,11 +163,11 @@ MidiPlaylist::read (MidiRingBuffer<nframes_t>& dst, nframes_t start, nframes_t d
DEBUG_TRACE (DEBUG::MidiPlaylistIO, "\tBEFORE: new tracker\n");
} else {
tracker = t->second;
- DEBUG_TRACE (DEBUG::MidiPlaylistIO, string_compose ("\tBEFORE: tracker says there are %1 on notes", tracker->on()));
+ DEBUG_TRACE (DEBUG::MidiPlaylistIO, string_compose ("\tBEFORE: tracker says there are %1 on notes\n", tracker->on()));
}
mr->read_at (dst, start, dur, chan_n, _note_mode, tracker);
- DEBUG_TRACE (DEBUG::MidiPlaylistIO, string_compose ("\tAFTER: tracker says there are %1 on notes", tracker->on()));
+ DEBUG_TRACE (DEBUG::MidiPlaylistIO, string_compose ("\tAFTER: tracker says there are %1 on notes\n", tracker->on()));
if (new_tracker) {
pair<Region*,MidiStateTracker*> newpair;
diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc
index 8dddc39fe3..40cb48f54f 100644
--- a/libs/ardour/midi_port.cc
+++ b/libs/ardour/midi_port.cc
@@ -137,8 +137,14 @@ MidiPort::flush_buffers (nframes_t nframes, nframes64_t time, nframes_t offset)
assert(ev.time() < (nframes+offset+_port_offset));
if (ev.time() >= offset + _port_offset) {
- jack_midi_event_write (jack_buffer, (jack_nframes_t) ev.time(), ev.buffer(), ev.size());
- }
+ 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 " << ev.time() << " > " << offset << " + " << _port_offset
+ << endl;
+ }
+ } else {
+ cerr << "drop flushed note off on the floor, time " << ev.time() << " > " << offset << " + " << _port_offset
+ << endl;
+ }
}
}
}
diff --git a/libs/ardour/midi_ring_buffer.cc b/libs/ardour/midi_ring_buffer.cc
index e8ae9bb5d3..2999621b70 100644
--- a/libs/ardour/midi_ring_buffer.cc
+++ b/libs/ardour/midi_ring_buffer.cc
@@ -50,7 +50,7 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
this->full_peek(sizeof(T), (uint8_t*)&ev_time);
- if (ev_time > end) {
+ if (ev_time >= end) {
DEBUG_TRACE (DEBUG::MidiDiskstreamIO, string_compose ("MRB event @ %1 past end @ %2\n", ev_time, end));
break;
} else if (ev_time < start) {
@@ -70,7 +70,7 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
if (ev_type == LoopEventType) {
/*ev_time -= start;
ev_time += offset;*/
- // cerr << "MRB loop boundary @ " << ev_time << endl;
+ cerr << "MRB loop boundary @ " << ev_time << endl;
// Return without reading data or writing to buffer (loop events have no data)
// FIXME: This is not correct, loses events after the loop this cycle
@@ -98,7 +98,7 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
// write the timestamp to address (write_loc - 1)
uint8_t* write_loc = dst.reserve(ev_time, ev_size);
if (write_loc == NULL) {
- // cerr << "MRB: Unable to reserve space in buffer, event skipped";
+ cerr << "MRB: Unable to reserve space in buffer, event skipped";
this->skip (ev_size); // Advance read pointer to next event
continue;
}
@@ -107,15 +107,16 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes
success = read_contents (ev_size, write_loc);
#ifndef NDEBUG
- DEBUG_TRACE (DEBUG::MidiDiskstreamIO, "wrote MidiEvent to Buffer: ");
+ DEBUG_STR_DECL(a);
+ DEBUG_STR_APPEND(a, string_compose ("wrote MidiEvent to Buffer (time=%1, start=%2 offset=%3)", ev_time, start, offset));
for (size_t i=0; i < ev_size; ++i) {
- DEBUG_STR_DECL(a);
DEBUG_STR_APPEND(a,hex);
DEBUG_STR_APPEND(a,"0x");
DEBUG_STR_APPEND(a,(int)write_loc[i]);
- DEBUG_TRACE (DEBUG::MidiDiskstreamIO, DEBUG_STR(a).str());
+ DEBUG_STR_APPEND(a,' ');
}
- DEBUG_TRACE (DEBUG::MidiDiskstreamIO, "\n");
+ DEBUG_STR_APPEND(a,'\n');
+ DEBUG_TRACE (DEBUG::MidiDiskstreamIO, DEBUG_STR(a).str());
#endif
if (success) {
diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc
index fbd1f54213..d25a70d819 100644
--- a/libs/ardour/midi_track.cc
+++ b/libs/ardour/midi_track.cc
@@ -25,6 +25,7 @@
#include "ardour/amp.h"
#include "ardour/buffer_set.h"
+#include "ardour/debug.h"
#include "ardour/delivery.h"
#include "ardour/io_processor.h"
#include "ardour/meter.h"
@@ -412,8 +413,12 @@ MidiTrack::write_out_of_band_data (BufferSet& bufs, sframes_t /*start*/, sframes
{
// Append immediate events
MidiBuffer& buf (bufs.get_midi (0));
- _immediate_events.read (buf, 0, 0, nframes - 1); // all stamps = 0
-
+ if (_immediate_events.read_space()) {
+ DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of immediate events to deliver\n",
+ name(), _immediate_events.read_space()));
+ }
+ _immediate_events.read (buf, 0, 1, nframes-1); // all stamps = 0
+
// MIDI thru: send incoming data "through" output
if (_midi_thru && _session.transport_speed() != 0.0f && _input->n_ports().n_midi()) {
buf.merge_in_place (_input->midi(0)->get_midi_buffer(nframes));
@@ -474,6 +479,7 @@ MidiTrack::set_note_mode (NoteMode m)
void
MidiTrack::midi_panic()
{
+ DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 delivers panic data\n", name()));
for (uint8_t channel = 0; channel <= 0xF; channel++) {
uint8_t ev[3] = { MIDI_CMD_CONTROL | channel, MIDI_CTL_SUSTAIN, 0 };
write_immediate_event(3, ev);
diff --git a/libs/ardour/port.cc b/libs/ardour/port.cc
index 6ae0c5d92b..5f29503fb6 100644
--- a/libs/ardour/port.cc
+++ b/libs/ardour/port.cc
@@ -316,3 +316,4 @@ Port::physically_connected () const
return false;
}
+