From 8d44391f4ba571c4dbcec0a87033c83414f515e8 Mon Sep 17 00:00:00 2001 From: Hans Baier Date: Fri, 9 May 2008 11:28:14 +0000 Subject: * adjusted formatting a bit to style guide * fixed: velocity value left on canvas * fixed: end-of-track problem still showed up sometimes * enabled heaps of debugging output in order to debug MidiModel corruption git-svn-id: svn://localhost/ardour2/branches/3.0@3329 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/canvas-note-event.cc | 22 +++++++++++----- gtk2_ardour/canvas-note.h | 4 +-- gtk2_ardour/midi_channel_selector.cc | 1 + gtk2_ardour/midi_channel_selector.h | 4 +-- gtk2_ardour/midi_region_view.cc | 49 ++++++++++++++++++++--------------- libs/ardour/ardour/midi_ring_buffer.h | 6 +++-- libs/ardour/ardour/note.h | 1 + libs/ardour/midi_model.cc | 34 ++++++++++++++---------- libs/ardour/note.cc | 14 +++++++++- libs/ardour/smf_source.cc | 14 +++++++--- libs/midi++2/midi++/event.h | 16 +++++++----- 11 files changed, 109 insertions(+), 56 deletions(-) diff --git a/gtk2_ardour/canvas-note-event.cc b/gtk2_ardour/canvas-note-event.cc index 149ad755ac..bd402f8c08 100644 --- a/gtk2_ardour/canvas-note-event.cc +++ b/gtk2_ardour/canvas-note-event.cc @@ -45,8 +45,11 @@ CanvasNoteEvent::CanvasNoteEvent(MidiRegionView& region, Item* item, CanvasNoteEvent::~CanvasNoteEvent() { - if (_text) + cerr << "CanvasNoteEvent::~CanvasNoteEvent() " << int(_note->note()) << " velo " << int(_note->velocity()) << endl; + if (_text) { + _text->hide(); delete _text; + } if (_channel_selector_widget) delete _channel_selector_widget; @@ -56,13 +59,17 @@ void CanvasNoteEvent::move_event(double dx, double dy) { _item->move(dx, dy); - if (_text) + if (_text) { + _text->hide(); _text->move(dx, dy); + _text->show(); + } } void CanvasNoteEvent::show_velocity(void) { + hide_velocity(); _text = new Text(*(_item->property_parent())); _text->property_x() = (x1() + x2()) /2; _text->property_y() = (y1() + y2()) /2; @@ -79,8 +86,11 @@ CanvasNoteEvent::show_velocity(void) void CanvasNoteEvent::hide_velocity(void) { - delete _text; - _text = NULL; + if(_text) { + _text->hide(); + delete _text; + } + _text = 0; } void @@ -91,8 +101,8 @@ CanvasNoteEvent::on_channel_selection_change(uint16_t selection) set_fill_color(ARDOUR_UI::config()->canvasvar_MidiNoteFillInactiveChannel.get()); set_outline_color(ARDOUR_UI::config()->canvasvar_MidiNoteOutlineInactiveChannel.get()); } else { - set_fill_color(note_fill_color(_note->velocity())); - set_outline_color(note_outline_color(_note->velocity())); + // set the color according to the notes selection state + selected(_selected); } // this forces the item to update..... maybe slow... _item->hide(); diff --git a/gtk2_ardour/canvas-note.h b/gtk2_ardour/canvas-note.h index 84791c89ca..97739b4207 100644 --- a/gtk2_ardour/canvas-note.h +++ b/gtk2_ardour/canvas-note.h @@ -36,8 +36,8 @@ public: double x2() { return property_x2(); } double y2() { return property_y2(); } - void set_outline_color(uint32_t c) { property_outline_color_rgba() = c; } - void set_fill_color(uint32_t c) { property_fill_color_rgba() = c; } + void set_outline_color(uint32_t c) { property_outline_color_rgba() = c; hide(); show(); } + void set_fill_color(uint32_t c) { property_fill_color_rgba() = c; hide(); show(); } bool on_event(GdkEvent* ev); diff --git a/gtk2_ardour/midi_channel_selector.cc b/gtk2_ardour/midi_channel_selector.cc index 1b0e9ecfbb..0018c169ab 100644 --- a/gtk2_ardour/midi_channel_selector.cc +++ b/gtk2_ardour/midi_channel_selector.cc @@ -65,6 +65,7 @@ SingleMidiChannelSelector::button_toggled(ToggleButton *button, uint8_t channel) _last_active_button->set_active(false); _active_channel = channel; _last_active_button = button; + channel_selected.emit(channel); } } else { // if not, the user pressed the already active button diff --git a/gtk2_ardour/midi_channel_selector.h b/gtk2_ardour/midi_channel_selector.h index 3562f5febe..9ac95036d6 100644 --- a/gtk2_ardour/midi_channel_selector.h +++ b/gtk2_ardour/midi_channel_selector.h @@ -34,8 +34,8 @@ public: protected: virtual void button_toggled(Gtk::ToggleButton *button, uint8_t button_nr); - Gtk::ToggleButton *_last_active_button; - uint8_t _active_channel; + Gtk::ToggleButton* _last_active_button; + uint8_t _active_channel; }; class MidiMultipleChannelSelector : public MidiChannelSelector diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 5b0f3070d4..69f756f3ca 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -456,24 +456,22 @@ MidiRegionView::redisplay_model() if (_model) { clear_events(); - begin_write(); - _model->read_lock(); - MidiModel::Notes notes = _model->notes(); cerr << endl << "Model contains " << notes.size() << " Notes:" << endl; for(MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) { - Note note = *(*i).get(); - cerr << "MODEL: Note time: " << note.time() << " duration: " << note.duration() - << " end-time: " << note.end_time() - << " velocity: " << int(note.velocity()) + cerr << "MODEL: Note time: " << (*i)->time() + << " pitch: " << int((*i)->note()) + << " duration: " << (*i)->duration() + << " end-time: " << (*i)->end_time() + << " velocity: " << int((*i)->velocity()) //<< " Note-on: " << note.on_event(). //<< " Note-off: " << note.off_event() << endl; } - for (size_t i=0; i < _model->n_notes(); ++i) { + for (size_t i = 0; i < _model->n_notes(); ++i) { add_note(_model->note_at(i)); } @@ -495,8 +493,6 @@ MidiRegionView::redisplay_model() } } - end_write(); - // Is this necessary ?????????? /*for (Automatable::Controls::const_iterator i = _model->controls().begin(); i != _model->controls().end(); ++i) { @@ -841,9 +837,11 @@ MidiRegionView::delete_selection() { assert(_delta_command); - for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) - if ((*i)->selected()) + for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) { + if ((*i)->selected()) { _delta_command->remove((*i)->note()); + } + } _selection.clear(); } @@ -851,9 +849,11 @@ MidiRegionView::delete_selection() void MidiRegionView::clear_selection_except(ArdourCanvas::CanvasNoteEvent* ev) { - for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) - if ((*i)->selected() && (*i) != ev) + for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) { + if ((*i)->selected() && (*i) != ev) { (*i)->selected(false); + } + } _selection.clear(); } @@ -861,40 +861,47 @@ MidiRegionView::clear_selection_except(ArdourCanvas::CanvasNoteEvent* ev) void MidiRegionView::unique_select(ArdourCanvas::CanvasNoteEvent* ev) { - for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) - if ((*i) != ev) + for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) { + if ((*i) != ev) { (*i)->selected(false); + } + } _selection.clear(); _selection.insert(ev); - if ( ! ev->selected()) + if ( ! ev->selected()) { ev->selected(true); + } } void MidiRegionView::note_selected(ArdourCanvas::CanvasNoteEvent* ev, bool add) { - if ( ! add) + if ( ! add) { clear_selection_except(ev); + } _selection.insert(ev); - if ( ! ev->selected()) + if ( ! ev->selected()) { ev->selected(true); + } } void MidiRegionView::note_deselected(ArdourCanvas::CanvasNoteEvent* ev, bool add) { - if ( ! add) + if ( ! add) { clear_selection_except(ev); + } _selection.erase(ev); - if (ev->selected()) + if (ev->selected()) { ev->selected(false); + } } diff --git a/libs/ardour/ardour/midi_ring_buffer.h b/libs/ardour/ardour/midi_ring_buffer.h index b514ea2bc2..c817866600 100644 --- a/libs/ardour/ardour/midi_ring_buffer.h +++ b/libs/ardour/ardour/midi_ring_buffer.h @@ -368,8 +368,9 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t break; bool success = MidiRingBufferBase::full_read(sizeof(double), (Byte*)&ev.time()); - if (success) + if (success) { success = MidiRingBufferBase::full_read(sizeof(size_t), (Byte*)&ev.size()); + } if (!success) { std::cerr << "MRB: READ ERROR (time/size)" << std::endl; @@ -377,8 +378,9 @@ MidiRingBuffer::read(MidiBuffer& dst, nframes_t start, nframes_t end, nframes_t } Byte first_event_byte; - if(success) + if(success) { success = full_peek(sizeof(Byte), &first_event_byte); + } // could this ever happen??? if (!success) { diff --git a/libs/ardour/ardour/note.h b/libs/ardour/ardour/note.h index 713d732113..f32a2e75f9 100644 --- a/libs/ardour/ardour/note.h +++ b/libs/ardour/ardour/note.h @@ -36,6 +36,7 @@ class Note { public: Note(uint8_t chan=0, double time=0, double dur=0, uint8_t note=0, uint8_t vel=0x40); Note(const Note& copy); + ~Note(); const Note& operator=(const Note& copy); diff --git a/libs/ardour/midi_model.cc b/libs/ardour/midi_model.cc index e544a64afb..8c6f569c5c 100644 --- a/libs/ardour/midi_model.cc +++ b/libs/ardour/midi_model.cc @@ -143,14 +143,16 @@ MidiModel::const_iterator::const_iterator(const MidiModel& model, double t) MidiModel::const_iterator::~const_iterator() { - if (_locked) + if (_locked) { _model->read_unlock(); + } } const MidiModel::const_iterator& MidiModel::const_iterator::operator++() { - if (_is_end) + if (_is_end) { throw std::logic_error("Attempt to iterate past end of MidiModel"); + } /*cerr << "const_iterator::operator++: _event type:" << hex << "0x" << int(_event.type()) << " buffer: 0x" << int(_event.buffer()[0]) << " 0x" << int(_event.buffer()[1]) @@ -264,7 +266,7 @@ MidiModel::const_iterator& MidiModel::const_iterator::operator=(const const_iter size_t index = other._control_iter - other._control_iters.begin(); _control_iter = _control_iters.begin() + index; - assert( ! _event.owns_buffer()); + assert( !_event.owns_buffer() ); return *this; } @@ -312,13 +314,13 @@ size_t MidiModel::read(MidiRingBuffer& dst, nframes_t start, nframes_t nframes, dst.write(_read_iter->time() + stamp_offset - negative_stamp_offset, _read_iter->size(), _read_iter->buffer()); - /* + cerr << this << " MidiModel::read event @ " << _read_iter->time() << " type: " << hex << int(_read_iter->type()) << dec - << " note: " << int(_read_iter->note()) - << " velocity: " << int(_read_iter->velocity()) + //<< " note: " << int(_read_iter->note()) + //<< " velocity: " << int(_read_iter->velocity()) << endl; - */ + ++_read_iter; ++read_events; @@ -334,8 +336,9 @@ bool MidiModel::control_to_midi_event(MIDI::Event& ev, switch (iter.automation_list->parameter().type()) { case MidiCCAutomation: - if (ev.size() < 3) + if (ev.size() < 3) { ev.set_buffer((Byte*)malloc(3), true); + } assert(iter.automation_list); assert(iter.automation_list->parameter().channel() < 16); @@ -349,8 +352,9 @@ bool MidiModel::control_to_midi_event(MIDI::Event& ev, return true; case MidiPgmChangeAutomation: - if (ev.size() < 3) + if (ev.size() < 3) { ev.set_buffer((Byte*)malloc(3), true); + } assert(iter.automation_list); assert(iter.automation_list->parameter().channel() < 16); @@ -364,8 +368,9 @@ bool MidiModel::control_to_midi_event(MIDI::Event& ev, return true; case MidiPitchBenderAutomation: - if (ev.size() < 3) + if (ev.size() < 3) { ev.set_buffer((Byte*)malloc(3), true); + } assert(iter.automation_list); assert(iter.automation_list->parameter().channel() < 16); @@ -379,8 +384,9 @@ bool MidiModel::control_to_midi_event(MIDI::Event& ev, return true; case MidiChannelAftertouchAutomation: - if (ev.size() < 3) + if (ev.size() < 3) { ev.set_buffer((Byte*)malloc(3), true); + } assert(iter.automation_list); assert(iter.automation_list->parameter().channel() < 16); @@ -528,7 +534,8 @@ void MidiModel::append_note_on_unlocked(uint8_t chan, double time, assert(_writing); _edited = true; - _notes.push_back(boost::shared_ptr(new Note(chan, time, 0, note_num, velocity))); + boost::shared_ptr new_note(new Note(chan, time, 0, note_num, velocity)); + _notes.push_back(new_note); if (_note_mode == Sustained) { //cerr << "MM Sustained: Appending active note on " << (unsigned)(uint8_t)note_num << endl; _write_notes[chan].push_back(_notes.size() - 1); @@ -896,8 +903,9 @@ bool MidiModel::write_to(boost::shared_ptr source) const NoteMode old_note_mode = _note_mode; _note_mode = Sustained; - for (const_iterator i = begin(); i != end(); ++i) + for (const_iterator i = begin(); i != end(); ++i) { source->append_event_unlocked(Frames, *i); + } _note_mode = old_note_mode; diff --git a/libs/ardour/note.cc b/libs/ardour/note.cc index 0ddd745242..ea1e7133af 100644 --- a/libs/ardour/note.cc +++ b/libs/ardour/note.cc @@ -19,6 +19,7 @@ */ #include +#include namespace ARDOUR { @@ -40,7 +41,8 @@ Note::Note(uint8_t chan, double t, double d, uint8_t n, uint8_t v) assert(duration() == d); assert(note() == n); assert(velocity() == v); - assert(_on_event.channel() == _off_event.channel()); + assert(_on_event.channel() == _off_event.channel()); + assert(channel() == chan); } @@ -69,6 +71,16 @@ Note::Note(const Note& copy) assert(channel() == copy.channel()); } +Note::~Note() +{ + std::cerr << "Note::~Note() Note time: " << time() + << " pitch: " << int(note()) + << " duration: " << duration() + << " end-time: " << end_time() + << " velocity: " << int(velocity()) + << std::endl; +} + const Note& Note::operator=(const Note& copy) diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 8c2ee6031f..4ab7a9b973 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -194,8 +194,15 @@ SMFSource::seek_to_footer_position() // lets check if there is a track end marker at the end of the data fseek(_fd, -4, SEEK_END); + //cerr << "SMFSource::seek_to_footer_position: At position: " << ftell(_fd); size_t read_bytes = fread(buffer, sizeof(uint8_t), 4, _fd); - //cerr << "SMFSource::seek_to_footer_position: read size: " << read_bytes << endl; + /*cerr << " read size: " << read_bytes << " buffer: "; + for (size_t i=0; i < read_bytes; ++i) { + printf("%x ", buffer[i]); + } + printf("\n"); + */ + if( (read_bytes == 4) && buffer[0] == 0x00 && buffer[1] == 0xFF && @@ -244,6 +251,7 @@ SMFSource::flush_footer() //cerr << path() << " SMF Flushing footer\n"; seek_to_footer_position(); write_footer(); + seek_to_footer_position(); return 0; } @@ -491,8 +499,8 @@ SMFSource::write_unlocked (MidiRingBuffer& src, nframes_t cnt) void SMFSource::append_event_unlocked(EventTimeUnit unit, const MIDI::Event& ev) { - /*printf("SMFSource: %s - append_event_unlocked chan = %u, time = %lf, size = %u, data = ", - name().c_str(), (unsigned)ev.channel(), ev.time(), ev.size()); */ + printf("SMFSource: %s - append_event_unlocked chan = %u, time = %lf, size = %u, data = ", + name().c_str(), (unsigned)ev.channel(), ev.time(), ev.size()); for (size_t i=0; i < ev.size(); ++i) { printf("%X ", ev.buffer()[i]); } diff --git a/libs/midi++2/midi++/event.h b/libs/midi++2/midi++/event.h index 7f792af1e9..4a0210095f 100644 --- a/libs/midi++2/midi++/event.h +++ b/libs/midi++2/midi++/event.h @@ -53,10 +53,11 @@ struct Event { { if (owns_buffer) { _buffer = (uint8_t*)malloc(_size); - if (b) + if (b) { memcpy(_buffer, b, _size); - else + } else { memset(_buffer, 0, _size); + } } } @@ -74,24 +75,27 @@ struct Event { { if (owns_buffer) { _buffer = (uint8_t*)malloc(_size); - if (copy._buffer) + if (copy._buffer) { memcpy(_buffer, copy._buffer, _size); - else + } else { memset(_buffer, 0, _size); + } } } ~Event() { - if (_owns_buffer) + if (_owns_buffer) { free(_buffer); + } } inline const Event& operator=(const Event& copy) { _time = copy._time; if (_owns_buffer) { if (copy._buffer) { - if (!_buffer || _size < copy._size) + if (!_buffer || _size < copy._size) { _buffer = (uint8_t*)::realloc(_buffer, copy._size); + } memcpy(_buffer, copy._buffer, copy._size); } else { free(_buffer); -- cgit v1.2.3