2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "evoral/midi_util.h"
21 #include "ardour/midi_region.h"
22 #include "ardour/session.h"
23 #include "ardour/tempo.h"
25 #include "midi_list_editor.h"
32 using namespace ARDOUR;
34 MidiListEditor::MidiListEditor (Session& s, boost::shared_ptr<MidiRegion> r)
35 : ArdourDialog (r->name(), false, false)
39 model = ListStore::create (columns);
40 view.set_model (model);
42 view.append_column (_("Start"), columns.start);
43 view.append_column (_("Channel"), columns.channel);
44 view.append_column (_("Num"), columns.note);
45 view.append_column (_("Name"), columns.note_name);
46 view.append_column (_("Vel"), columns.velocity);
47 view.append_column (_("Length"), columns.length);
48 view.append_column (_("End"), columns.end);
49 view.set_headers_visible (true);
50 view.set_name (X_("MidiListView"));
51 view.set_rules_hint (true);
53 for (int i = 0; i < 6; ++i) {
54 CellRendererText* renderer = dynamic_cast<CellRendererText*>(view.get_column_cell_renderer (i));
55 renderer->property_editable() = true;
56 renderer->signal_edited().connect (mem_fun (*this, &MidiListEditor::edited));
60 scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
67 get_vbox()->pack_start (scroller);
68 set_size_request (400, 400);
71 MidiListEditor::~MidiListEditor ()
76 MidiListEditor::edited (const Glib::ustring& path, const Glib::ustring& /* text */)
78 TreeModel::iterator iter = model->get_iter (path);
80 cerr << "Edit at " << path << endl;
86 boost::shared_ptr<NoteType> note = (*iter)[columns._note];
88 cerr << "Edited " << *note << endl;
94 MidiListEditor::redisplay_model ()
96 view.set_model (Glib::RefPtr<Gtk::ListStore>(0));
99 MidiModel::Notes notes = region->midi_source(0)->model()->notes();
102 for (MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) {
103 row = *(model->append());
104 row[columns.channel] = (*i)->channel();
105 row[columns.note_name] = _("Note");
106 row[columns.note] = (*i)->note();
107 row[columns.velocity] = (*i)->velocity();
113 session.tempo_map().bbt_time (region->position(), bbt);
116 dur.beats = floor ((*i)->time());
119 session.tempo_map().bbt_duration_at (region->position(), dur, 0);
122 row[columns.start] = ss.str();
124 row[columns.length] = ss.str();
126 session.tempo_map().bbt_time (region->position(), bbt);
127 /* XXX get end point */
130 row[columns.end] = ss.str();
132 row[columns._note] = (*i);
135 view.set_model (model);