#include <glibmm.h>
#include "alsa_audiobackend.h"
-#include "rt_thread.h"
#include "pbd/compose.h"
#include "pbd/error.h"
#include "pbd/file_utils.h"
+#include "pbd/pthread_utils.h"
#include "ardour/filesystem_paths.h"
#include "ardour/port_manager.h"
#include "ardouralsautil/devicelist.h"
pthread_mutex_init (&_port_callback_mutex, 0);
_input_audio_device_info.valid = false;
_output_audio_device_info.valid = false;
+
+ _port_connection_queue.reserve (128);
}
AlsaAudioBackend::~AlsaAudioBackend ()
_run = true;
_port_change_flag = false;
- if (_realtime_pthread_create (SCHED_FIFO, -20, 100000,
+ if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, -20, 100000,
&_main_thread, pthread_process, this))
{
if (pthread_create (&_main_thread, NULL, pthread_process, this))
ThreadData* td = new ThreadData (this, func, stacksize);
- if (_realtime_pthread_create (SCHED_FIFO, -21, stacksize,
+ if (pbd_realtime_pthread_create (PBD_SCHED_FIFO, -22, stacksize,
&thread_id, alsa_process_thread, td)) {
pthread_attr_init (&attr);
pthread_attr_setstacksize (&attr, stacksize);
int
AlsaAudioBackend::midi_event_get (
pframes_t& timestamp,
- size_t& size, uint8_t** buf, void* port_buffer,
+ size_t& size, uint8_t const** buf, void* port_buffer,
uint32_t event_index)
{
assert (buf && port_buffer);
if (event_index >= source.size ()) {
return -1;
}
- AlsaMidiEvent * const event = source[event_index].get ();
+ AlsaMidiEvent const& event = source[event_index];
- timestamp = event->timestamp ();
- size = event->size ();
- *buf = event->data ();
+ timestamp = event.timestamp ();
+ size = event.size ();
+ *buf = event.data ();
return 0;
}
const uint8_t* buffer, size_t size)
{
assert (buffer && port_buffer);
+ if (size >= MaxAlsaMidiEventSize) {
+ return -1;
+ }
AlsaMidiBuffer& dst = * static_cast<AlsaMidiBuffer*>(port_buffer);
- if (dst.size () && (pframes_t)dst.back ()->timestamp () > timestamp) {
#ifndef NDEBUG
+ if (dst.size () && (pframes_t)dst.back ().timestamp () > timestamp) {
// nevermind, ::get_buffer() sorts events
fprintf (stderr, "AlsaMidiBuffer: it's too late for this event. %d > %d\n",
- (pframes_t)dst.back ()->timestamp (), timestamp);
-#endif
+ (pframes_t)dst.back ().timestamp (), timestamp);
}
- dst.push_back (boost::shared_ptr<AlsaMidiEvent>(new AlsaMidiEvent (timestamp, buffer, size)));
+#endif
+ dst.push_back (AlsaMidiEvent (timestamp, buffer, size));
return 0;
}
AlsaMidiIn *rm = _rmidi_in.at(i);
void *bptr = (*it)->get_buffer(0);
pframes_t time;
- uint8_t data[64]; // match MaxAlsaEventSize in alsa_rawmidi.cc
+ uint8_t data[MaxAlsaMidiEventSize];
size_t size = sizeof(data);
midi_clear(bptr);
while (rm->recv_event (time, data, size)) {
AlsaMidiOut *rm = _rmidi_out.at(i);
rm->sync_time (clock1);
for (AlsaMidiBuffer::const_iterator mit = src->begin (); mit != src->end (); ++mit) {
- rm->send_event ((*mit)->timestamp(), (*mit)->data(), (*mit)->size());
+ rm->send_event (mit->timestamp (), mit->data (), mit->size ());
}
}
{
_buffer[0].clear ();
_buffer[1].clear ();
+ _buffer[2].clear ();
+
+ _buffer[0].reserve(256);
+ _buffer[1].reserve(256);
+ _buffer[2].reserve(256);
}
AlsaMidiPort::~AlsaMidiPort () { }
struct MidiEventSorter {
- bool operator() (const boost::shared_ptr<AlsaMidiEvent>& a, const boost::shared_ptr<AlsaMidiEvent>& b) {
- return *a < *b;
+ bool operator() (AlsaMidiEvent const& a, AlsaMidiEvent const& b) {
+ return a < b;
}
};
++i) {
const AlsaMidiBuffer * src = static_cast<const AlsaMidiPort*>(*i)->const_buffer ();
for (AlsaMidiBuffer::const_iterator it = src->begin (); it != src->end (); ++it) {
- (_buffer[_bufperiod]).push_back (boost::shared_ptr<AlsaMidiEvent>(new AlsaMidiEvent (**it)));
+ (_buffer[_bufperiod]).push_back (*it);
}
}
std::stable_sort ((_buffer[_bufperiod]).begin (), (_buffer[_bufperiod]).end (), MidiEventSorter());
AlsaMidiEvent::AlsaMidiEvent (const pframes_t timestamp, const uint8_t* data, size_t size)
: _size (size)
, _timestamp (timestamp)
- , _data (0)
{
- if (size > 0) {
- _data = (uint8_t*) malloc (size);
+ if (size > 0 && size < MaxAlsaMidiEventSize) {
memcpy (_data, data, size);
}
}
AlsaMidiEvent::AlsaMidiEvent (const AlsaMidiEvent& other)
: _size (other.size ())
, _timestamp (other.timestamp ())
- , _data (0)
{
- if (other.size () && other.const_data ()) {
- _data = (uint8_t*) malloc (other.size ());
- memcpy (_data, other.const_data (), other.size ());
+ if (other._size > 0) {
+ assert (other._size < MaxAlsaMidiEventSize);
+ memcpy (_data, other._data, other._size);
}
};
-
-AlsaMidiEvent::~AlsaMidiEvent () {
- free (_data);
-};