Slightly hacky fix for AFL/PFL button misbehaviour
[ardour.git] / gtk2_ardour / midi_list_editor.cc
index da04c3dc9436bb30710c7d5ab29ea32a988cb615..879b1a9f2fb99257432870a9b7d014605c865b7c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2009 Paul Davis
+    Copyright (C) 2009 Paul Davis
 
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
 */
+
 #include <cmath>
 
 #include "evoral/midi_util.h"
+#include "evoral/Note.hpp"
 
 #include "ardour/beats_frames_converter.h"
+#include "ardour/midi_model.h"
 #include "ardour/midi_region.h"
+#include "ardour/midi_source.h"
 #include "ardour/session.h"
 #include "ardour/tempo.h"
 
@@ -35,9 +38,15 @@ using namespace Glib;
 using namespace ARDOUR;
 
 MidiListEditor::MidiListEditor (Session* s, boost::shared_ptr<MidiRegion> r)
-       : ArdourDialog (r->name(), false, false)
+       : ArdourWindow (r->name())
        , region (r)
 {
+       /* We do not handle nested sources/regions. Caller should have tackled this */
+
+       if (r->max_source_level() > 0) {
+               throw failed_constructor();
+       }
+
        set_session (s);
 
        model = ListStore::create (columns);
@@ -74,7 +83,7 @@ MidiListEditor::MidiListEditor (Session* s, boost::shared_ptr<MidiRegion> r)
        view.show ();
        scroller.show ();
 
-       get_vbox()->pack_start (scroller);
+       add (scroller);
        set_size_request (400, 400);
 }
 
@@ -176,7 +185,7 @@ MidiListEditor::edited (const std::string& path, const std::string& /* text */)
        cerr << "Edited " << *note << endl;
 
        redisplay_model ();
-       
+
        /* keep selected row(s), move cursor there, to allow us to continue editing */
 }
 
@@ -187,24 +196,24 @@ MidiListEditor::redisplay_model ()
        model->clear ();
 
        if (_session) {
-               
+
                BeatsFramesConverter conv (_session->tempo_map(), region->position());
                MidiModel::Notes notes = region->midi_source(0)->model()->notes();
                TreeModel::Row row;
                stringstream ss;
-               
+
                for (MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) {
                        row = *(model->append());
                        row[columns.channel] = (*i)->channel() + 1;
                        row[columns.note_name] = Evoral::midi_note_name ((*i)->note());
                        row[columns.note] = (*i)->note();
                        row[columns.velocity] = (*i)->velocity();
-                       
+
                        Timecode::BBT_Time bbt;
                        double dur;
 
                        _session->tempo_map().bbt_time (conv.to ((*i)->time()), bbt);
-                       
+
                        ss.str ("");
                        ss << bbt;
                        row[columns.start] = ss.str();
@@ -212,20 +221,20 @@ MidiListEditor::redisplay_model ()
                        bbt.bars = 0;
                        dur = (*i)->end_time() - (*i)->time();
                        bbt.beats = floor (dur);
-                       bbt.ticks = (uint32_t) lrint (fmod (dur, 1.0) * Meter::ticks_per_beat);
-                       
+                       bbt.ticks = (uint32_t) lrint (fmod (dur, 1.0) * Timecode::BBT_Time::ticks_per_beat);
+
                        _session->tempo_map().bbt_duration_at (region->position(), bbt, 0);
 
                        ss.str ("");
                        ss << bbt;
                        row[columns.length] = ss.str();
-                       
+
                        _session->tempo_map().bbt_time (conv.to ((*i)->end_time()), bbt);
-                                                                                                
+
                        ss.str ("");
                        ss << bbt;
                        row[columns.end] = ss.str();
-                       
+
                        row[columns._note] = (*i);
                }
        }