ardour
midi_list_editor.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Paul Davis
3 
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.
8 
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.
13 
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.
17 */
18 
19 #include <cmath>
20 #include <map>
21 
22 #include <gtkmm/cellrenderercombo.h>
23 
24 #include "evoral/midi_util.h"
25 #include "evoral/Note.hpp"
26 
28 #include "ardour/midi_model.h"
29 #include "ardour/midi_region.h"
30 #include "ardour/midi_source.h"
31 #include "ardour/session.h"
32 #include "ardour/tempo.h"
33 
34 #include "gtkmm2ext/gui_thread.h"
35 #include "gtkmm2ext/keyboard.h"
36 #include "gtkmm2ext/actions.h"
37 
38 #include "ardour_ui.h"
39 #include "midi_list_editor.h"
40 #include "note_player.h"
41 
42 #include "i18n.h"
43 
44 using namespace std;
45 using namespace Gtk;
46 using namespace Gtkmm2ext;
47 using namespace Glib;
48 using namespace ARDOUR;
49 using Timecode::BBT_Time;
50 
51 static map<int,std::string> note_length_map;
52 
53 static void
55 {
56  note_length_map.insert (make_pair<int,string> (BBT_Time::ticks_per_beat, _("Whole")));
57  note_length_map.insert (make_pair<int,string> (BBT_Time::ticks_per_beat/2, _("Half")));
58  note_length_map.insert (make_pair<int,string> (BBT_Time::ticks_per_beat/3, _("Triplet")));
59  note_length_map.insert (make_pair<int,string> (BBT_Time::ticks_per_beat/4, _("Quarter")));
60  note_length_map.insert (make_pair<int,string> (BBT_Time::ticks_per_beat/8, _("Eighth")));
61  note_length_map.insert (make_pair<int,string> (BBT_Time::ticks_per_beat/16, _("Sixteenth")));
62  note_length_map.insert (make_pair<int,string> (BBT_Time::ticks_per_beat/32, _("Thirty-second")));
63  note_length_map.insert (make_pair<int,string> (BBT_Time::ticks_per_beat/64, _("Sixty-fourth")));
64 }
65 
67  : ArdourWindow (r->name())
68  , buttons (1, 1)
69  , region (r)
70  , track (tr)
71 {
72  if (note_length_map.empty()) {
74  }
75 
76  /* We do not handle nested sources/regions. Caller should have tackled this */
77 
78  if (r->max_source_level() > 0) {
79  throw failed_constructor();
80  }
81 
82  set_session (s);
83 
84  edit_column = -1;
85  editing_renderer = 0;
86  editing_editable = 0;
87 
88  model = ListStore::create (columns);
89  view.set_model (model);
90 
91  note_length_model = ListStore::create (note_length_columns);
92  TreeModel::Row row;
93 
94  for (std::map<int,string>::iterator i = note_length_map.begin(); i != note_length_map.end(); ++i) {
95  row = *(note_length_model->append());
96  row[note_length_columns.ticks] = i->first;
97  row[note_length_columns.name] = i->second;
98  }
99 
100  view.signal_key_press_event().connect (sigc::mem_fun (*this, &MidiListEditor::key_press), false);
101  view.signal_key_release_event().connect (sigc::mem_fun (*this, &MidiListEditor::key_release), false);
102  view.signal_scroll_event().connect (sigc::mem_fun (*this, &MidiListEditor::scroll_event), false);
103 
104  view.append_column (_("Start"), columns.start);
105  view.append_column (_("Channel"), columns.channel);
106  view.append_column (_("Num"), columns.note);
107  view.append_column (_("Name"), columns.note_name);
108  view.append_column (_("Vel"), columns.velocity);
109 
110  /* use a combo renderer for length, so that we can offer a selection
111  of pre-defined note lengths. we still allow edited values with
112  arbitrary length (in ticks).
113  */
114 
115  Gtk::TreeViewColumn* lenCol = Gtk::manage (new Gtk::TreeViewColumn (_("Length")));
116  Gtk::CellRendererCombo* comboCell = Gtk::manage(new Gtk::CellRendererCombo);
117  lenCol->pack_start(*comboCell);
118  lenCol->add_attribute (comboCell->property_text(), columns.length);
119 
120  comboCell->property_model() = note_length_model;
121  comboCell->property_text_column() = 1;
122  comboCell->property_has_entry() = false;
123 
124  view.append_column (*lenCol);
125 
126  view.set_headers_visible (true);
127  view.set_rules_hint (true);
128  view.get_selection()->set_mode (SELECTION_MULTIPLE);
129  view.get_selection()->signal_changed().connect (sigc::mem_fun (*this, &MidiListEditor::selection_changed));
130 
131  for (int i = 0; i < 6; ++i) {
132  CellRendererText* renderer = dynamic_cast<CellRendererText*>(view.get_column_cell_renderer (i));
133 
134  TreeViewColumn* col = view.get_column (i);
135  col->set_data (X_("colnum"), GUINT_TO_POINTER(i));
136 
137  renderer->property_editable() = true;
138 
139  renderer->signal_editing_started().connect (sigc::bind (sigc::mem_fun (*this, &MidiListEditor::editing_started), i));
140  renderer->signal_editing_canceled().connect (sigc::mem_fun (*this, &MidiListEditor::editing_canceled));
141  renderer->signal_edited().connect (sigc::mem_fun (*this, &MidiListEditor::edited));
142  }
143 
144  scroller.add (view);
145  scroller.set_policy (POLICY_NEVER, POLICY_AUTOMATIC);
146 
147  redisplay_model ();
148 
149  region->midi_source(0)->model()->ContentsChanged.connect (content_connection, invalidator (*this),
150  boost::bind (&MidiListEditor::redisplay_model, this), gui_context());
151 
152  buttons.attach (sound_notes_button, 0, 1, 0, 1);
153  Glib::RefPtr<Gtk::Action> act = ActionManager::get_action ("Editor", "sound-midi-notes");
154  if (act) {
155  gtk_activatable_set_related_action (GTK_ACTIVATABLE (sound_notes_button.gobj()), act->gobj());
156  }
157 
158  view.show ();
159  scroller.show ();
160  buttons.show ();
161  vbox.show ();
162  sound_notes_button.show ();
163 
164  vbox.set_spacing (6);
165  vbox.set_border_width (6);
166  vbox.pack_start (buttons, false, false);
167  vbox.pack_start (scroller, true, true);
168 
169  add (vbox);
170  set_size_request (-1, 400);
171 }
172 
174 {
175 }
176 
177 bool
178 MidiListEditor::scroll_event (GdkEventScroll* ev)
179 {
180  TreeModel::Path path;
181  TreeViewColumn* col;
182  int cellx;
183  int celly;
184  int idelta = 0;
185  double fdelta = 0;
186  MidiModel::NoteDiffCommand::Property prop (MidiModel::NoteDiffCommand::NoteNumber);
187  bool apply = false;
188  bool was_selected = false;
189  char const * opname;
190 
191  if (!view.get_path_at_pos (ev->x, ev->y, path, col, cellx, celly)) {
192  return false;
193  }
194 
195  if (view.get_selection()->count_selected_rows() == 0) {
196  was_selected = false;
197  } else if (view.get_selection()->is_selected (path)) {
198  was_selected = true;
199  } else {
200  was_selected = false;
201  }
202 
203  int colnum = GPOINTER_TO_UINT (col->get_data (X_("colnum")));
204 
205  switch (colnum) {
206  case 0:
207  if (Keyboard::modifier_state_equals (ev->state, Keyboard::SecondaryModifier)) {
208  fdelta = 1/64.0;
209  } else {
210  fdelta = 1/4.0;
211  }
212  if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
213  fdelta = -fdelta;
214  }
215  prop = MidiModel::NoteDiffCommand::StartTime;
216  opname = _("edit note start");
217  apply = true;
218  break;
219  case 1:
220  idelta = 1;
221  if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
222  idelta = -idelta;
223  }
224  prop = MidiModel::NoteDiffCommand::Channel;
225  opname = _("edit note channel");
226  apply = true;
227  break;
228  case 2:
229  case 3:
230  idelta = 1;
231  if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
232  idelta = -idelta;
233  }
234  prop = MidiModel::NoteDiffCommand::NoteNumber;
235  opname = _("edit note number");
236  apply = true;
237  break;
238 
239  case 4:
240  idelta = 1;
241  if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
242  idelta = -idelta;
243  }
244  prop = MidiModel::NoteDiffCommand::Velocity;
245  opname = _("edit note velocity");
246  apply = true;
247  break;
248 
249  case 5:
250  if (Keyboard::modifier_state_equals (ev->state, Keyboard::SecondaryModifier)) {
251  fdelta = 1/64.0;
252  } else {
253  fdelta = 1/4.0;
254  }
255  if (ev->direction == GDK_SCROLL_DOWN || ev->direction == GDK_SCROLL_LEFT) {
256  fdelta = -fdelta;
257  }
258  prop = MidiModel::NoteDiffCommand::Length;
259  opname = _("edit note length");
260  apply = true;
261  break;
262 
263  default:
264  break;
265  }
266 
267 
268  if (apply) {
269 
271  MidiModel::NoteDiffCommand* cmd = m->new_note_diff_command (opname);
272  vector<TreeModel::Path> previous_selection;
273 
274  if (was_selected) {
275 
276  /* use selection */
277 
278  TreeView::Selection::ListHandle_Path rows = view.get_selection()->get_selected_rows ();
279  TreeModel::iterator iter;
281 
282  for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) {
283 
284  previous_selection.push_back (*i);
285 
286  if ((iter = model->get_iter (*i))) {
287 
288  note = (*iter)[columns._note];
289 
290  switch (prop) {
291  case MidiModel::NoteDiffCommand::StartTime:
292  if (note->time() + fdelta >= 0) {
293  cmd->change (note, prop, note->time() + fdelta);
294  } else {
295  cmd->change (note, prop, Evoral::Beats());
296  }
297  break;
298  case MidiModel::NoteDiffCommand::Velocity:
299  cmd->change (note, prop, (uint8_t) (note->velocity() + idelta));
300  break;
301  case MidiModel::NoteDiffCommand::Length:
302  if (note->length().to_double() + fdelta >=
304  cmd->change (note, prop, note->length() + fdelta);
305  } else {
306  cmd->change (note, prop, Evoral::Beats::tick());
307  }
308  break;
309  case MidiModel::NoteDiffCommand::Channel:
310  cmd->change (note, prop, (uint8_t) (note->channel() + idelta));
311  break;
312  case MidiModel::NoteDiffCommand::NoteNumber:
313  cmd->change (note, prop, (uint8_t) (note->note() + idelta));
314  break;
315  default:
316  continue;
317  }
318  }
319  }
320 
321  } else {
322 
323  /* just this row */
324 
325  TreeModel::iterator iter;
326  iter = model->get_iter (path);
327 
328  previous_selection.push_back (path);
329 
330  if (iter) {
331  boost::shared_ptr<NoteType> note = (*iter)[columns._note];
332 
333  switch (prop) {
334  case MidiModel::NoteDiffCommand::StartTime:
335  if (note->time() + fdelta >= 0) {
336  cmd->change (note, prop, note->time() + fdelta);
337  } else {
338  cmd->change (note, prop, Evoral::Beats());
339  }
340  break;
341  case MidiModel::NoteDiffCommand::Velocity:
342  cmd->change (note, prop, (uint8_t) (note->velocity() + idelta));
343  break;
344  case MidiModel::NoteDiffCommand::Length:
345  if (note->length() + fdelta >=
347  cmd->change (note, prop, note->length() + fdelta);
348  } else {
349  cmd->change (note, prop, Evoral::Beats::tick());
350  }
351  break;
352  case MidiModel::NoteDiffCommand::Channel:
353  cmd->change (note, prop, (uint8_t) (note->channel() + idelta));
354  break;
355  case MidiModel::NoteDiffCommand::NoteNumber:
356  cmd->change (note, prop, (uint8_t) (note->note() + idelta));
357  break;
358  default:
359  break;
360  }
361  }
362  }
363 
364  m->apply_command (*_session, cmd);
365 
366  /* reset selection to be as it was before we rebuilt */
367 
368  for (vector<TreeModel::Path>::iterator i = previous_selection.begin(); i != previous_selection.end(); ++i) {
369  view.get_selection()->select (*i);
370  }
371  }
372 
373  return true;
374 }
375 
376 bool
377 MidiListEditor::key_press (GdkEventKey* ev)
378 {
379  bool ret = false;
380  TreeModel::Path path;
381  TreeViewColumn* col;
382  int colnum;
383 
384  switch (ev->keyval) {
385  case GDK_Tab:
386  if (edit_column > 0) {
387  colnum = edit_column;
388  path = edit_path;
389  if (editing_editable) {
390  editing_editable->editing_done ();
391  }
392  if (colnum >= 5) {
393  /* wrap to next line */
394  colnum = 0;
395  path.next();
396  } else {
397  colnum++;
398  }
399  col = view.get_column (colnum);
400  view.set_cursor (path, *col, true);
401  ret = true;
402  }
403  break;
404 
405  case GDK_Up:
406  case GDK_uparrow:
407  if (edit_column > 0) {
408  colnum = edit_column;
409  path = edit_path;
410  if (editing_editable) {
411  editing_editable->editing_done ();
412  }
413  path.prev ();
414  col = view.get_column (colnum);
415  view.set_cursor (path, *col, true);
416  ret = true;
417  }
418  break;
419 
420  case GDK_Down:
421  case GDK_downarrow:
422  if (edit_column > 0) {
423  colnum = edit_column;
424  path = edit_path;
425  if (editing_editable) {
426  editing_editable->editing_done ();
427  }
428  path.next ();
429  col = view.get_column (colnum);
430  view.set_cursor (path, *col, true);
431  ret = true;
432  }
433  break;
434 
435  case GDK_Escape:
436  stop_editing (true);
437  break;
438 
439  }
440 
441  return ret;
442 }
443 
444 bool
446 {
447  bool ret = false;
448  TreeModel::Path path;
449  TreeViewColumn* col;
450  TreeModel::iterator iter;
455 
456  switch (ev->keyval) {
457  case GDK_Insert:
458  /* add a new note to the model, based on the note at the cursor
459  * pos
460  */
461  view.get_cursor (path, col);
462  iter = model->get_iter (path);
463  cmd = m->new_note_diff_command (_("insert new note"));
464  note = (*iter)[columns._note];
465  copy.reset (new NoteType (*note.get()));
466  cmd->add (copy);
467  m->apply_command (*_session, cmd);
468  /* model has been redisplayed by now */
469  path.next ();
470  /* select, start editing column 2 (note) */
471  col = view.get_column (2);
472  view.set_cursor (path, *col, true);
473  break;
474 
475  case GDK_Delete:
476  case GDK_BackSpace:
477  if (edit_column < 0) {
479  }
480  ret = true;
481  break;
482 
483  case GDK_z:
485  _session->undo (1);
486  ret = true;
487  }
488  break;
489 
490  case GDK_r:
492  _session->redo (1);
493  ret = true;
494  }
495  break;
496 
497  default:
498  break;
499  }
500 
501  return ret;
502 }
503 
504 void
506 {
507  Glib::RefPtr<TreeSelection> selection = view.get_selection();
508  TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
509 
510  if (rows.empty()) {
511  return;
512  }
513 
514  typedef vector<boost::shared_ptr<NoteType> > Notes;
515  Notes to_delete;
516 
517  for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) {
518  TreeIter iter;
519 
520  if ((iter = model->get_iter (*i))) {
521  boost::shared_ptr<NoteType> note = (*iter)[columns._note];
522  to_delete.push_back (note);
523  }
524  }
525 
527  MidiModel::NoteDiffCommand* cmd = m->new_note_diff_command (_("delete notes (from list)"));
528 
529  for (Notes::iterator i = to_delete.begin(); i != to_delete.end(); ++i) {
530  cmd->remove (*i);
531  }
532 
533  m->apply_command (*_session, cmd);
534 }
535 
536 void
538 {
539  if (!cancelled) {
540  if (editing_editable) {
541  editing_editable->editing_done ();
542  }
543  } else {
544  if (editing_renderer) {
545  editing_renderer->stop_editing (cancelled);
546  }
547  }
548 }
549 
550 void
551 MidiListEditor::editing_started (CellEditable* ed, const string& path, int colno)
552 {
553  edit_path = TreePath (path);
554  edit_column = colno;
555  editing_renderer = dynamic_cast<CellRendererText*>(view.get_column_cell_renderer (colno));
556  editing_editable = ed;
557 
558  if (ed) {
559  Gtk::Entry *e = dynamic_cast<Gtk::Entry*> (ed);
560  if (e) {
561  e->signal_key_press_event().connect (sigc::mem_fun (*this, &MidiListEditor::key_press), false);
562  e->signal_key_release_event().connect (sigc::mem_fun (*this, &MidiListEditor::key_release), false);
563  }
564  }
565 }
566 
567 void
569 {
570  edit_path.clear ();
571  edit_column = -1;
572  editing_renderer = 0;
573  editing_editable = 0;
574 }
575 
576 void
577 MidiListEditor::edited (const std::string& path, const std::string& text)
578 {
579  TreeModel::iterator iter = model->get_iter (path);
580 
581  if (!iter || text.empty()) {
582  return;
583  }
584 
585  boost::shared_ptr<NoteType> note = (*iter)[columns._note];
586  MidiModel::NoteDiffCommand::Property prop (MidiModel::NoteDiffCommand::NoteNumber);
587 
588  double fval;
589  int ival;
590  bool apply = false;
591  int idelta = 0;
592  double fdelta = 0;
593  char const * opname;
594  switch (edit_column) {
595  case 0: // start
596  break;
597  case 1: // channel
598  // correct ival for zero-based counting after scan
599  if (sscanf (text.c_str(), "%d", &ival) == 1 && --ival != note->channel()) {
600  idelta = ival - note->channel();
601  prop = MidiModel::NoteDiffCommand::Channel;
602  opname = _("change note channel");
603  apply = true;
604  }
605  break;
606  case 2: // note
607  if (sscanf (text.c_str(), "%d", &ival) == 1 && ival != note->note()) {
608  idelta = ival - note->note();
609  prop = MidiModel::NoteDiffCommand::NoteNumber;
610  opname = _("change note number");
611  apply = true;
612  }
613  break;
614  case 3: // name
615  break;
616  case 4: // velocity
617  if (sscanf (text.c_str(), "%d", &ival) == 1 && ival != note->velocity()) {
618  idelta = ival - note->velocity();
619  prop = MidiModel::NoteDiffCommand::Velocity;
620  opname = _("change note velocity");
621  apply = true;
622  }
623  break;
624  case 5: // length
625 
626  if (sscanf (text.c_str(), "%lf", &fval) == 1) {
627 
628  /* numeric value entered */
629 
630  if (text.find ('.') == string::npos && text.find (',') == string::npos) {
631  /* integral => units are ticks */
632  fval = fval / BBT_Time::ticks_per_beat;
633  } else {
634  /* non-integral => beats, so use as-is */
635  }
636 
637  } else {
638 
639  /* assume its text from the combo. look for the map
640  * entry for the actual note ticks
641  */
642 
643  uint64_t len_ticks = note->length().to_ticks();
644  std::map<int,string>::iterator x = note_length_map.find (len_ticks);
645 
646  if (x == note_length_map.end()) {
647 
648  /* tick length not in map - was
649  * displaying numeric value ... use new value
650  * from note length map, and convert to beats.
651  */
652 
653  for (x = note_length_map.begin(); x != note_length_map.end(); ++x) {
654  if (x->second == text) {
655  break;
656  }
657  }
658 
659  if (x != note_length_map.end()) {
660  fval = x->first / BBT_Time::ticks_per_beat;
661  }
662 
663  } else {
664 
665  fval = -1.0;
666 
667  if (text != x->second) {
668 
669  /* get ticks for the newly selected
670  * note length
671  */
672 
673  for (x = note_length_map.begin(); x != note_length_map.end(); ++x) {
674  if (x->second == text) {
675  break;
676  }
677  }
678 
679  if (x != note_length_map.end()) {
680  /* convert to beats */
681  fval = (double) x->first / BBT_Time::ticks_per_beat;
682  }
683  }
684  }
685  }
686 
687  if (fval > 0.0) {
688  fdelta = fval - note->length().to_double();
689  prop = MidiModel::NoteDiffCommand::Length;
690  opname = _("change note length");
691  apply = true;
692  }
693  break;
694 
695  default:
696  break;
697  }
698 
699  if (apply) {
700 
702  MidiModel::NoteDiffCommand* cmd = m->new_note_diff_command (opname);
703 
704  TreeView::Selection::ListHandle_Path rows = view.get_selection()->get_selected_rows ();
705 
706  for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) {
707  if ((iter = model->get_iter (*i))) {
708 
709  note = (*iter)[columns._note];
710 
711  switch (prop) {
712  case MidiModel::NoteDiffCommand::Velocity:
713  cmd->change (note, prop, (uint8_t) (note->velocity() + idelta));
714  break;
715  case MidiModel::NoteDiffCommand::Length:
716  cmd->change (note, prop, note->length() + fdelta);
717  break;
718  case MidiModel::NoteDiffCommand::Channel:
719  cmd->change (note, prop, (uint8_t) (note->channel() + idelta));
720  break;
721  case MidiModel::NoteDiffCommand::NoteNumber:
722  cmd->change (note, prop, (uint8_t) (note->note() + idelta));
723  break;
724  default:
725  continue;
726  }
727  }
728  }
729 
730  m->apply_command (*_session, cmd);
731 
732  /* model has been redisplayed by now */
733  /* keep selected row(s), move cursor there, don't continue editing */
734 
735  TreeViewColumn* col = view.get_column (edit_column);
736  view.set_cursor (edit_path, *col, 0);
737 
738  /* reset edit info, since we're done */
739 
740  edit_path.clear ();
741  edit_column = -1;
742  editing_renderer = 0;
743  editing_editable = 0;
744  }
745 }
746 
747 void
749 {
750  view.set_model (Glib::RefPtr<Gtk::ListStore>(0));
751  model->clear ();
752 
753  if (_session) {
754 
756  MidiModel::Notes notes = region->midi_source(0)->model()->notes();
757  TreeModel::Row row;
758  stringstream ss;
759 
760  for (MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) {
761  row = *(model->append());
762  row[columns.channel] = (*i)->channel() + 1;
763  row[columns.note_name] = Evoral::midi_note_name ((*i)->note());
764  row[columns.note] = (*i)->note();
765  row[columns.velocity] = (*i)->velocity();
766 
767  Timecode::BBT_Time bbt;
768 
769  _session->tempo_map().bbt_time (conv.to ((*i)->time()), bbt);
770 
771  ss.str ("");
772  ss << bbt;
773  row[columns.start] = ss.str();
774 
775  bbt.bars = 0;
776  const Evoral::Beats dur = (*i)->end_time() - (*i)->time();
777  bbt.beats = dur.get_beats ();
778  bbt.ticks = dur.get_ticks ();
779 
780  int len_ticks = (*i)->length().to_ticks();
781  std::map<int,string>::iterator x = note_length_map.find (len_ticks);
782 
783  if (x != note_length_map.end()) {
784  row[columns.length] = x->second;
785  } else {
786  ss.str ("");
787  ss << len_ticks;
788  row[columns.length] = ss.str();
789  }
790 
791  row[columns._note] = (*i);
792  }
793  }
794 
795  view.set_model (model);
796 }
797 
798 void
800 {
801  if (!ARDOUR_UI::config()->get_sound_midi_notes()) {
802  return;
803  }
804 
805  TreeModel::Path path;
806  TreeModel::iterator iter;
808  TreeView::Selection::ListHandle_Path rows = view.get_selection()->get_selected_rows ();
809 
810  NotePlayer* player = new NotePlayer (track);
811 
812  for (TreeView::Selection::ListHandle_Path::iterator i = rows.begin(); i != rows.end(); ++i) {
813  if ((iter = model->get_iter (*i))) {
814  note = (*iter)[columns._note];
815  player->add (note);
816  }
817  }
818 
819  player->play ();
820 }
LIBEVORAL_API std::string midi_note_name(uint8_t noteval)
Definition: midi_util.cpp:25
void apply_command(Session &session, Command *cmd)
Definition: midi_model.cc:97
uint8_t velocity() const
Definition: Note.hpp:63
uint32_t get_ticks() const
Definition: Beats.hpp:190
void bbt_time(framepos_t when, Timecode::BBT_Time &)
Definition: tempo.cc:1168
Gtk::TreeModelColumn< std::string > start
void undo(uint32_t n)
Definition: session.h:767
Time time() const
Definition: Note.hpp:60
void edited(const std::string &, const std::string &)
Definition: ardour_ui.h:130
Gtk::TreeModelColumn< uint8_t > channel
Gtk::TreeModelColumn< uint8_t > velocity
TempoMap & tempo_map()
Definition: session.h:596
LIBGTKMM2EXT_API Glib::RefPtr< Gtk::Action > get_action(const char *group, const char *name)
Definition: actions.cc:406
uint8_t note() const
Definition: Note.hpp:62
Gtk::TreeModel::Path edit_path
Definition: Beats.hpp:239
MidiListModelColumns columns
bool key_release(GdkEventKey *ev)
void add(boost::shared_ptr< NoteType >)
Definition: note_player.cc:40
#define invalidator(x)
Definition: gui_thread.h:40
Gtk::TreeModelColumn< boost::shared_ptr< NoteType > > _note
#define _(Text)
Definition: i18n.h:11
static bool modifier_state_contains(guint state, ModifierMask)
Definition: keyboard.cc:520
#define X_(Text)
Definition: i18n.h:13
static Beats beats(int32_t beats)
Definition: Beats.hpp:44
static uint32_t PrimaryModifier
Definition: keyboard.h:55
uint8_t channel() const
Definition: Note.hpp:66
static Beats tick()
Definition: Beats.hpp:196
Gtk::TreeModelColumn< uint8_t > note
Definition: amp.h:29
Gtk::TreeView view
uint32_t get_beats() const
Definition: Beats.hpp:189
#define gui_context()
Definition: gui_thread.h:36
PBD::ScopedConnection content_connection
MidiListEditor(ARDOUR::Session *, boost::shared_ptr< ARDOUR::MidiRegion >, boost::shared_ptr< ARDOUR::MidiTrack >)
Gtk::CellEditable * editing_editable
static void fill_note_length_map()
T * get() const
Definition: shared_ptr.hpp:268
framepos_t position() const
Definition: region.h:112
Gtk::TreeModelColumn< std::string > note_name
const char * name
static map< int, std::string > note_length_map
Gtk::TreeModelColumn< std::string > length
static UIConfiguration * config()
Definition: ardour_ui.h:188
void stop_editing(bool cancelled=false)
double to_double() const
Definition: Beats.hpp:185
Gtk::TreeModelColumn< int > ticks
Gtk::ToggleButton sound_notes_button
bool key_press(GdkEventKey *ev)
Gtk::Table buttons
boost::shared_ptr< ARDOUR::MidiTrack > track
Time length() const
Definition: Note.hpp:65
Gtk::ScrolledWindow scroller
virtual void set_session(ARDOUR::Session *)
boost::shared_ptr< MidiSource > midi_source(uint32_t n=0) const
Definition: midi_region.cc:390
Glib::RefPtr< Gtk::ListStore > model
boost::shared_ptr< ARDOUR::MidiRegion > region
uint32_t max_source_level() const
Definition: region.cc:1682
Glib::RefPtr< Gtk::ListStore > note_length_model
void editing_started(Gtk::CellEditable *, const std::string &path, int)
ARDOUR::Session * _session
Gtk::TreeModelColumn< std::string > name
void play()
Definition: note_player.cc:61
void add(const NotePtr note)
Definition: midi_model.cc:148
NoteLengthColumns note_length_columns
void redo(uint32_t n)
Definition: session.h:771
Gtk::CellRendererText * editing_renderer
bool scroll_event(GdkEventScroll *)