From 9091ba932d9f440c73b35f02b3f0a89c12f92185 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 7 Jun 2007 02:07:49 +0000 Subject: Fixed MIDI crash bug. Added some asserts to gtkmm2ext that hopefully may catch a bug I might have possibly seen once or twice, probably. Fixed uninitialized value in time_axis_view.cc. git-svn-id: svn://localhost/ardour2/trunk@1958 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/midi_source.h | 4 ++-- libs/ardour/ardour/types.h | 7 +++++-- libs/ardour/midi_source.cc | 3 +++ libs/ardour/smf_source.cc | 23 ++++++++++++++++------- libs/gtkmm2ext/gtk_ui.cc | 4 ++++ 5 files changed, 30 insertions(+), 11 deletions(-) (limited to 'libs') diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h index fd5aa15376..bc2cc90b19 100644 --- a/libs/ardour/ardour/midi_source.h +++ b/libs/ardour/ardour/midi_source.h @@ -72,7 +72,7 @@ class MidiSource : public Source virtual void load_model(bool lock=true) = 0; virtual void destroy_model() = 0; - MidiModel& model() { return _model; } + MidiModel* model() { return _model; } protected: virtual nframes_t read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset) const = 0; @@ -83,7 +83,7 @@ class MidiSource : public Source mutable uint32_t _read_data_count; ///< modified in read() mutable uint32_t _write_data_count; ///< modified in write() - MidiModel _model; + MidiModel* _model; private: bool file_changed (string path); diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index ce52252fc4..3dc4ae2693 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -59,8 +59,11 @@ namespace ARDOUR { typedef uint64_t microseconds_t; typedef uint32_t nframes_t; - typedef jack_midi_event_t MidiEvent; - typedef unsigned char Byte; + typedef unsigned char Byte; + + struct MidiEvent : public jack_midi_event_t { + MidiEvent() { time = 0; size = 0; buffer = NULL; } + }; enum IOChange { NoChange = 0, diff --git a/libs/ardour/midi_source.cc b/libs/ardour/midi_source.cc index d73520134a..2b4f8a8255 100644 --- a/libs/ardour/midi_source.cc +++ b/libs/ardour/midi_source.cc @@ -44,6 +44,7 @@ sigc::signal MidiSource::MidiSourceCreated; MidiSource::MidiSource (Session& s, string name) : Source (s, name, DataType::MIDI) + , _model(new MidiModel()) { _read_data_count = 0; _write_data_count = 0; @@ -51,6 +52,7 @@ MidiSource::MidiSource (Session& s, string name) MidiSource::MidiSource (Session& s, const XMLNode& node) : Source (s, node) + , _model(new MidiModel()) { _read_data_count = 0; _write_data_count = 0; @@ -62,6 +64,7 @@ MidiSource::MidiSource (Session& s, const XMLNode& node) MidiSource::~MidiSource () { + delete _model; } XMLNode& diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 730ba053bd..9ecb961f19 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -259,6 +259,7 @@ SMFSource::read_event(MidiEvent& ev) const } uint32_t delta_time = read_var_len(); + assert(!feof(_fd)); int status = fgetc(_fd); assert(status != EOF); // FIXME die gracefully if (status == 0xFF) { @@ -273,11 +274,15 @@ SMFSource::read_event(MidiEvent& ev) const return 0; } } + + ev.time = delta_time; + ev.size = midi_event_size((unsigned char)status) + 1; + + if (ev.buffer == NULL) + ev.buffer = (Byte*)malloc(sizeof(Byte) * ev.size); ev.buffer[0] = (unsigned char)status; - ev.size = midi_event_size(ev.buffer[0]) + 1; fread(ev.buffer+1, 1, ev.size - 1, _fd); - ev.time = delta_time; /*printf("SMF - read event, delta = %u, size = %zu, data = ", delta_time, ev.size); @@ -393,7 +398,7 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt) const nframes_t oldlen = _length; update_length(oldlen, cnt); - _model.append(buf); + _model->append(buf); ViewDataRangeReady (buf_ptr, oldlen, cnt); /* EMIT SIGNAL */ @@ -777,8 +782,9 @@ SMFSource::load_model(bool lock) if (lock) Glib::Mutex::Lock lm (_lock); - _model.clear(); - + destroy_model(); + _model = new MidiModel(); + fseek(_fd, _header_size, 0); nframes_t time = 0; @@ -789,14 +795,17 @@ SMFSource::load_model(bool lock) time += ev.time; ev.time = time; if (ret > 0) { // didn't skip (meta) event - _model.append(ev); + cerr << "ADDING EVENT TO MODEL: " << ev.time << endl; + _model->append(ev); } } } + void SMFSource::destroy_model() { - _model.clear(); + delete _model; + _model = NULL; } diff --git a/libs/gtkmm2ext/gtk_ui.cc b/libs/gtkmm2ext/gtk_ui.cc index ee9d39c918..174d645d17 100644 --- a/libs/gtkmm2ext/gtk_ui.cc +++ b/libs/gtkmm2ext/gtk_ui.cc @@ -19,6 +19,7 @@ */ #include +#include #include #include #include @@ -429,6 +430,9 @@ UI::toggle_errors () void UI::display_message (const char *prefix, gint prefix_len, RefPtr ptag, RefPtr mtag, const char *msg) { + assert(ptag); + assert(mtag); + RefPtr buffer (errors->text().get_buffer()); buffer->insert_with_tag(buffer->end(), prefix, ptag); -- cgit v1.2.3