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
This commit is contained in:
David Robillard 2007-06-07 02:07:49 +00:00
parent ca40990444
commit 9091ba932d
8 changed files with 35 additions and 15 deletions

View file

@ -91,8 +91,8 @@ MidiRegionView::init (Gdk::Color& basic_color, bool wfd)
midi_region()->midi_source(0)->load_model(); midi_region()->midi_source(0)->load_model();
begin_write(); begin_write();
for (size_t i=0; i < midi_region()->midi_source(0)->model().n_events(); ++i) for (size_t i=0; i < midi_region()->midi_source(0)->model()->n_events(); ++i)
add_event(midi_region()->midi_source(0)->model().event_at(i)); add_event(midi_region()->midi_source(0)->model()->event_at(i));
end_write(); end_write();
} }
} }

View file

@ -110,8 +110,8 @@ MidiStreamView::add_region_view_internal (boost::shared_ptr<Region> r, bool wait
/* display events */ /* display events */
region_view->begin_write(); region_view->begin_write();
for (size_t i=0; i < region->midi_source(0)->model().n_events(); ++i) for (size_t i=0; i < region->midi_source(0)->model()->n_events(); ++i)
region_view->add_event(region->midi_source(0)->model().event_at(i)); region_view->add_event(region->midi_source(0)->model()->event_at(i));
region_view->end_write(); region_view->end_write();
/* catch regionview going away */ /* catch regionview going away */

View file

@ -71,6 +71,7 @@ bool TimeAxisView::need_size_info = true;
TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* rent, Canvas& canvas) TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* rent, Canvas& canvas)
: AxisView (sess), : AxisView (sess),
editor (ed), editor (ed),
height_style(Small),
y_position(0), y_position(0),
order(0), order(0),
controls_table (2, 8) controls_table (2, 8)

View file

@ -72,7 +72,7 @@ class MidiSource : public Source
virtual void load_model(bool lock=true) = 0; virtual void load_model(bool lock=true) = 0;
virtual void destroy_model() = 0; virtual void destroy_model() = 0;
MidiModel& model() { return _model; } MidiModel* model() { return _model; }
protected: protected:
virtual nframes_t read_unlocked (MidiRingBuffer& dst, nframes_t start, nframes_t cnt, nframes_t stamp_offset) const = 0; 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 _read_data_count; ///< modified in read()
mutable uint32_t _write_data_count; ///< modified in write() mutable uint32_t _write_data_count; ///< modified in write()
MidiModel _model; MidiModel* _model;
private: private:
bool file_changed (string path); bool file_changed (string path);

View file

@ -59,8 +59,11 @@ namespace ARDOUR {
typedef uint64_t microseconds_t; typedef uint64_t microseconds_t;
typedef uint32_t nframes_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 { enum IOChange {
NoChange = 0, NoChange = 0,

View file

@ -44,6 +44,7 @@ sigc::signal<void,MidiSource *> MidiSource::MidiSourceCreated;
MidiSource::MidiSource (Session& s, string name) MidiSource::MidiSource (Session& s, string name)
: Source (s, name, DataType::MIDI) : Source (s, name, DataType::MIDI)
, _model(new MidiModel())
{ {
_read_data_count = 0; _read_data_count = 0;
_write_data_count = 0; _write_data_count = 0;
@ -51,6 +52,7 @@ MidiSource::MidiSource (Session& s, string name)
MidiSource::MidiSource (Session& s, const XMLNode& node) MidiSource::MidiSource (Session& s, const XMLNode& node)
: Source (s, node) : Source (s, node)
, _model(new MidiModel())
{ {
_read_data_count = 0; _read_data_count = 0;
_write_data_count = 0; _write_data_count = 0;
@ -62,6 +64,7 @@ MidiSource::MidiSource (Session& s, const XMLNode& node)
MidiSource::~MidiSource () MidiSource::~MidiSource ()
{ {
delete _model;
} }
XMLNode& XMLNode&

View file

@ -259,6 +259,7 @@ SMFSource::read_event(MidiEvent& ev) const
} }
uint32_t delta_time = read_var_len(); uint32_t delta_time = read_var_len();
assert(!feof(_fd));
int status = fgetc(_fd); int status = fgetc(_fd);
assert(status != EOF); // FIXME die gracefully assert(status != EOF); // FIXME die gracefully
if (status == 0xFF) { if (status == 0xFF) {
@ -273,11 +274,15 @@ SMFSource::read_event(MidiEvent& ev) const
return 0; 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.buffer[0] = (unsigned char)status;
ev.size = midi_event_size(ev.buffer[0]) + 1;
fread(ev.buffer+1, 1, ev.size - 1, _fd); fread(ev.buffer+1, 1, ev.size - 1, _fd);
ev.time = delta_time;
/*printf("SMF - read event, delta = %u, size = %zu, data = ", /*printf("SMF - read event, delta = %u, size = %zu, data = ",
delta_time, ev.size); delta_time, ev.size);
@ -393,7 +398,7 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt)
const nframes_t oldlen = _length; const nframes_t oldlen = _length;
update_length(oldlen, cnt); update_length(oldlen, cnt);
_model.append(buf); _model->append(buf);
ViewDataRangeReady (buf_ptr, oldlen, cnt); /* EMIT SIGNAL */ ViewDataRangeReady (buf_ptr, oldlen, cnt); /* EMIT SIGNAL */
@ -777,8 +782,9 @@ SMFSource::load_model(bool lock)
if (lock) if (lock)
Glib::Mutex::Lock lm (_lock); Glib::Mutex::Lock lm (_lock);
_model.clear(); destroy_model();
_model = new MidiModel();
fseek(_fd, _header_size, 0); fseek(_fd, _header_size, 0);
nframes_t time = 0; nframes_t time = 0;
@ -789,14 +795,17 @@ SMFSource::load_model(bool lock)
time += ev.time; time += ev.time;
ev.time = time; ev.time = time;
if (ret > 0) { // didn't skip (meta) event if (ret > 0) { // didn't skip (meta) event
_model.append(ev); cerr << "ADDING EVENT TO MODEL: " << ev.time << endl;
_model->append(ev);
} }
} }
} }
void void
SMFSource::destroy_model() SMFSource::destroy_model()
{ {
_model.clear(); delete _model;
_model = NULL;
} }

View file

@ -19,6 +19,7 @@
*/ */
#include <cmath> #include <cmath>
#include <cassert>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
@ -429,6 +430,9 @@ UI::toggle_errors ()
void void
UI::display_message (const char *prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg) UI::display_message (const char *prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
{ {
assert(ptag);
assert(mtag);
RefPtr<TextBuffer> buffer (errors->text().get_buffer()); RefPtr<TextBuffer> buffer (errors->text().get_buffer());
buffer->insert_with_tag(buffer->end(), prefix, ptag); buffer->insert_with_tag(buffer->end(), prefix, ptag);