* formatting/style guide
authorHans Baier <hansfbaier@googlemail.com>
Fri, 9 May 2008 16:10:36 +0000 (16:10 +0000)
committerHans Baier <hansfbaier@googlemail.com>
Fri, 9 May 2008 16:10:36 +0000 (16:10 +0000)
* bugfix: midi_util.h only considered channel events up to E0, but had to be EF
* bugfix: parameter.h operator == should also compare channel (drobilla, correct me if I am wrong)
* added some assert() guards

git-svn-id: svn://localhost/ardour2/branches/3.0@3330 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/canvas-program-change.cc
gtk2_ardour/midi_region_view.cc
libs/ardour/ardour/midi_util.h
libs/ardour/ardour/parameter.h
libs/ardour/midi_model.cc

index 103bd7bb8def95aeec5773aa6efd26bdd2362fbb..ccaf333ef5e39762171e96e546dde23616421d9c 100644 (file)
@@ -21,6 +21,7 @@ CanvasProgramChange::CanvasProgramChange(
          _widget(0)
 {
        _text = new Text(*this);
+       assert(_text);
        ostringstream pgm(ios::ate);
        pgm << int(event->pgm_number());
        _text->property_text() = pgm.str();
index 69f756f3ca6c7156fdc56b07a5d8150655377ebf..bc492b0e71bd902a0e611788d839580a7d71938f 100644 (file)
@@ -672,8 +672,9 @@ MidiRegionView::begin_write()
 {
        assert(!_active_notes);
        _active_notes = new CanvasNote*[128];
-       for (unsigned i=0; i < 128; ++i)
+       for (unsigned i=0; i < 128; ++i) {
                _active_notes[i] = NULL;
+       }
 }
 
 
@@ -765,6 +766,8 @@ MidiRegionView::add_note(const boost::shared_ptr<Note> note)
                ev_rect->property_y2() = y1 + floor(midi_stream_view()->note_height());
 
                if (note->duration() == 0) {
+                       assert(_active_notes);
+                       assert(note->note() < 128);
                        _active_notes[note->note()] = ev_rect;
                        /* outline all but right edge */
                        ev_rect->property_outline_what() = (guint32) (0x1 & 0x4 & 0x8);
index efcb6a7cd519802cfd17ea04b6f5afa150009852..6bcc6278e1a353acb5d2c2d5df1abcdc31f6ee31 100644 (file)
@@ -31,7 +31,8 @@ namespace ARDOUR {
 static inline int
 midi_event_size(unsigned char status)
 {
-       if (status >= 0x80 && status <= 0xE0) {
+       // if we have a channel event
+       if (status >= 0x80 && status < 0xF0) {
                status &= 0xF0; // mask off the channel
        }
 
index a602419e14d959d5e95d40dd94d4a0f8535c2da9..a795ee0eaae9a01ddb226bff272792cd77479ba7 100644 (file)
@@ -59,7 +59,7 @@ public:
        inline uint8_t        channel() const { return _channel; }
 
        inline bool operator==(const Parameter& id) const {
-               return (_type == id._type && _id == id._id);
+               return (_type == id._type && _id == id._id && _channel == id._channel);
        }
        
        /** Arbitrary but fixed ordering (for use in e.g. std::map) */
index 8c6f569c5cebf88826e0298b705290c16629c1c4..3cef80deb6f0af6fa0e00f4a00f2351db2e202e3 100644 (file)
@@ -171,7 +171,7 @@ const MidiModel::const_iterator& MidiModel::const_iterator::operator++()
                //cerr << "control_iter x:" << _control_iter->x << " y:" << _control_iter->y << endl;
 
                if (ret) {
-                       cerr << "Incremented " << _control_iter->automation_list->parameter().id() << " to " << x << endl;
+                       //cerr << "Incremented " << _control_iter->automation_list->parameter().id() << " to " << x << endl;
                        _control_iter->x = x;
                        _control_iter->y = y;
                } else {
@@ -243,10 +243,11 @@ const MidiModel::const_iterator& MidiModel::const_iterator::operator++()
 
 bool MidiModel::const_iterator::operator==(const const_iterator& other) const
 {
-       if (_is_end || other._is_end)
+       if (_is_end || other._is_end) {
                return (_is_end == other._is_end);
-       else
+       } else {
                return (_event == other._event);
+       }
 }
 
 MidiModel::const_iterator& MidiModel::const_iterator::operator=(const const_iterator& other)
@@ -352,17 +353,16 @@ bool MidiModel::control_to_midi_event(MIDI::Event& ev,
                return true;
 
        case MidiPgmChangeAutomation:
-               if (ev.size() < 3) {
-                       ev.set_buffer((Byte*)malloc(3), true);
+               if (ev.size() < 2) {
+                       ev.set_buffer((Byte*)malloc(2), true);
                }
 
                assert(iter.automation_list);
                assert(iter.automation_list->parameter().channel() < 16);
-               assert(iter.automation_list->parameter().id() <= INT8_MAX);
+               assert(iter.automation_list->parameter().id() == 0);
                assert(iter.y <= INT8_MAX);
                ev.buffer()[0] = MIDI_CMD_PGM_CHANGE + iter.automation_list->parameter().channel();
                ev.buffer()[1] = (Byte)iter.y;
-               ev.buffer()[2] = 0;
                ev.time() = iter.x;
                ev.size() = 3;
                return true;
@@ -374,7 +374,7 @@ bool MidiModel::control_to_midi_event(MIDI::Event& ev,
 
                assert(iter.automation_list);
                assert(iter.automation_list->parameter().channel() < 16);
-               assert(iter.automation_list->parameter().id() <= INT8_MAX);
+               assert(iter.automation_list->parameter().id() == 0);
                assert(iter.y < (1<<14));
                ev.buffer()[0] = MIDI_CMD_BENDER + iter.automation_list->parameter().channel();
                ev.buffer()[1] = ((Byte)iter.y) & 0x7F; // LSB
@@ -384,18 +384,17 @@ bool MidiModel::control_to_midi_event(MIDI::Event& ev,
                return true;
 
        case MidiChannelAftertouchAutomation:
-               if (ev.size() < 3) {
-                       ev.set_buffer((Byte*)malloc(3), true);
+               if (ev.size() < 2) {
+                       ev.set_buffer((Byte*)malloc(2), true);
                }
 
                assert(iter.automation_list);
                assert(iter.automation_list->parameter().channel() < 16);
-               assert(iter.automation_list->parameter().id() <= INT8_MAX);
+               assert(iter.automation_list->parameter().id() == 0);
                assert(iter.y <= INT8_MAX);
                ev.buffer()[0]
                                = MIDI_CMD_CHANNEL_PRESSURE + iter.automation_list->parameter().channel();
                ev.buffer()[1] = (Byte)iter.y;
-               ev.buffer()[2] = 0;
                ev.time() = iter.x;
                ev.size() = 3;
                return true;
@@ -580,9 +579,10 @@ void MidiModel::append_note_off_unlocked(uint8_t chan, double time,
                }
        }
 
-       if (!resolved)
+       if (!resolved) {
                cerr << "MidiModel " << this << " spurious note off chan " << (int)chan
                                << ", note " << (int)note_num << " @ " << time << endl;
+       }
 }
 
 void MidiModel::append_automation_event_unlocked(AutomationType type,
@@ -618,7 +618,7 @@ void MidiModel::append_automation_event_unlocked(AutomationType type,
 
        Parameter param(type, id, chan);
        boost::shared_ptr<AutomationControl> control = Automatable::control(param, true);
-       control->list()->fast_simple_add(time, value);
+       control->list()->rt_add(time, value);
        /*cerr << "control list size after fast simple add: " << control->list()->size() << endl;*/
 }