#include <sigc++/signal.h>
#include "pbd/memento_command.h"
+#include "pbd/stateful_diff_command.h"
#include "ardour/playlist.h"
#include "ardour/tempo.h"
#include "ardour/midi_region.h"
#include "ardour/midi_source.h"
-#include "ardour/midi_diskstream.h"
#include "ardour/midi_model.h"
#include "ardour/midi_patch_manager.h"
+#include "ardour/session.h"
#include "evoral/Parameter.hpp"
#include "evoral/Control.hpp"
#include "i18n.h"
-using namespace sigc;
using namespace ARDOUR;
using namespace PBD;
using namespace Editing;
using namespace ArdourCanvas;
+using Gtkmm2ext::Keyboard;
MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv,
boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color const & basic_color)
, _pressed_button(0)
, _sort_needed (true)
, _optimization_iterator (_events.end())
+ , _list_editor (0)
+ , no_sound_notes (false)
{
_note_group->raise_to_top();
}
, _pressed_button(0)
, _sort_needed (true)
, _optimization_iterator (_events.end())
-
+ , _list_editor (0)
+ , no_sound_notes (false)
+
{
_note_group->raise_to_top();
}
, _pressed_button(0)
, _sort_needed (true)
, _optimization_iterator (_events.end())
+ , _list_editor (0)
+ , no_sound_notes (false)
{
Gdk::Color c;
int r,g,b,a;
UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
c.set_rgb_p (r/255.0, g/255.0, b/255.0);
-
+
init (c, false);
}
, _pressed_button(0)
, _sort_needed (true)
, _optimization_iterator (_events.end())
+ , _list_editor (0)
+ , no_sound_notes (false)
{
Gdk::Color c;
int r,g,b,a;
region_muted ();
region_sync_changed ();
- region_resized (BoundsChanged);
+ region_resized (ARDOUR::bounds_change);
region_locked ();
-
+
reset_width_dependent_items (_pixel_width);
set_colors ();
}
group->raise_to_top();
- group->signal_event().connect (mem_fun (this, &MidiRegionView::canvas_event), false);
+ group->signal_event().connect (sigc::mem_fun (this, &MidiRegionView::canvas_event), false);
midi_view()->signal_channel_mode_changed().connect(
- mem_fun(this, &MidiRegionView::midi_channel_mode_changed));
-
+ sigc::mem_fun(this, &MidiRegionView::midi_channel_mode_changed));
+
midi_view()->signal_midi_patch_settings_changed().connect(
- mem_fun(this, &MidiRegionView::midi_patch_settings_changed));
+ sigc::mem_fun(this, &MidiRegionView::midi_patch_settings_changed));
}
bool
switch (ev->type) {
case GDK_SCROLL:
fine = Keyboard::modifier_state_equals (ev->scroll.state, Keyboard::Level4Modifier);
-
+
if (ev->scroll.direction == GDK_SCROLL_UP) {
change_velocities (true, fine, false);
return true;
bool end = (ev->key.keyval == GDK_period);
bool shorter = Keyboard::modifier_state_contains (ev->key.state, Keyboard::PrimaryModifier);
fine = Keyboard::modifier_state_contains (ev->key.state, Keyboard::SecondaryModifier);
-
+
change_note_lengths (fine, shorter, start, end);
return true;
return true;
} else if (ev->key.keyval == GDK_Down) {
-
+
bool allow_smush = Keyboard::modifier_state_contains (ev->key.state, Keyboard::SecondaryModifier);
fine = Keyboard::modifier_state_contains (ev->key.state, Keyboard::TertiaryModifier);
-
+
if (Keyboard::modifier_state_contains (ev->key.state, Keyboard::PrimaryModifier)) {
change_velocities (false, fine, allow_smush);
} else {
return true;
} else if (ev->key.keyval == GDK_Left) {
-
+
nudge_notes (false);
return true;
} else if (_pressed_button != 1) {
return false;
}
-
+
switch (_mouse_state) {
case Pressed: // Clicked
switch (editor.current_mouse_mode()) {
case MouseRange:
create_note_at(event_x, event_y, _default_note_length);
break;
- default:
+ default:
break;
}
_mouse_state = None;
const double x = drag_rect->property_x1();
const double length = trackview.editor().pixel_to_frame(
drag_rect->property_x2() - drag_rect->property_x1());
-
+
create_note_at(x, drag_rect->property_y1(), frames_to_beats(length));
}
drag_rect = 0;
default: break;
}
-
+
default: break;
}
void
MidiRegionView::show_list_editor ()
{
- MidiListEditor* mle = new MidiListEditor (trackview.session(), midi_region());
- mle->show ();
+ if (!_list_editor) {
+ _list_editor = new MidiListEditor (trackview.session(), midi_region());
+ }
+ _list_editor->present ();
}
/** Add a note to the model, and the view, at a canvas (click) coordinate.
MidiModel::DeltaCommand* cmd = _model->new_delta_command("add note");
cmd->add(new_note);
- _model->apply_command(trackview.session(), cmd);
+ _model->apply_command(*trackview.session(), cmd);
play_midi_note (new_note);
}
{
_model = model;
content_connection.disconnect ();
- content_connection = _model->ContentsChanged.connect(sigc::mem_fun(this, &MidiRegionView::redisplay_model));
+ _model->ContentsChanged.connect (content_connection, invalidator (*this), boost::bind (&MidiRegionView::redisplay_model, this), gui_context());
+
clear_events ();
if (_enable_display) {
redisplay_model();
}
}
-
-
+
+
void
MidiRegionView::start_delta_command(string name)
{
}
void
-MidiRegionView::diff_add_change (ArdourCanvas::CanvasNoteEvent* ev,
+MidiRegionView::diff_add_change (ArdourCanvas::CanvasNoteEvent* ev,
MidiModel::DiffCommand::Property property,
uint8_t val)
{
}
void
-MidiRegionView::diff_add_change (ArdourCanvas::CanvasNoteEvent* ev,
+MidiRegionView::diff_add_change (ArdourCanvas::CanvasNoteEvent* ev,
MidiModel::DiffCommand::Property property,
Evoral::MusicalTime val)
{
_diff_command->change (ev->note(), property, val);
}
}
-
+
void
MidiRegionView::apply_delta()
{
for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
_marked_for_selection.insert((*i)->note());
}
-
- _model->apply_command(trackview.session(), _delta_command);
- _delta_command = 0;
- midi_view()->midi_track()->diskstream()->playlist_modified();
+
+ _model->apply_command(*trackview.session(), _delta_command);
+ _delta_command = 0;
+ midi_view()->midi_track()->playlist_modified();
_marked_for_selection.clear();
_marked_for_velocity.clear();
return;
}
- _model->apply_command(trackview.session(), _diff_command);
- _diff_command = 0;
- midi_view()->midi_track()->diskstream()->playlist_modified();
+ _model->apply_command(*trackview.session(), _diff_command);
+ _diff_command = 0;
+ midi_view()->midi_track()->playlist_modified();
_marked_for_velocity.clear();
}
for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
_marked_for_selection.insert((*i)->note());
}
-
- _model->apply_command_as_subcommand(trackview.session(), _delta_command);
- _delta_command = 0;
- midi_view()->midi_track()->diskstream()->playlist_modified();
+
+ _model->apply_command_as_subcommand(*trackview.session(), _delta_command);
+ _delta_command = 0;
+ midi_view()->midi_track()->playlist_modified();
_marked_for_selection.clear();
_marked_for_velocity.clear();
for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
_marked_for_selection.insert((*i)->note());
}
-
- _model->apply_command_as_subcommand(trackview.session(), _diff_command);
- _diff_command = 0;
- midi_view()->midi_track()->diskstream()->playlist_modified();
+
+ _model->apply_command_as_subcommand(*trackview.session(), _diff_command);
+ _diff_command = 0;
+ midi_view()->midi_track()->playlist_modified();
_marked_for_selection.clear();
_marked_for_velocity.clear();
if (_optimization_iterator != _events.end()) {
++_optimization_iterator;
}
-
+
if (_optimization_iterator != _events.end() && (*_optimization_iterator)->note() == note) {
return *_optimization_iterator;
- }
+ }
for (_optimization_iterator = _events.begin(); _optimization_iterator != _events.end(); ++_optimization_iterator) {
if ((*_optimization_iterator)->note() == note) {
for (Events::iterator i = _events.begin(); i != _events.end(); ++i) {
(*i)->invalidate ();
}
-
- _model->read_lock();
-
+
+ MidiModel::ReadLock lock(_model->read_lock());
+
MidiModel::Notes& notes (_model->notes());
_optimization_iterator = _events.begin();
-
+
for (MidiModel::Notes::iterator n = notes.begin(); n != notes.end(); ++n) {
boost::shared_ptr<NoteType> note (*n);
bool visible;
if (note_in_region_range (note, visible)) {
-
+
if ((cne = find_canvas_note (note)) != 0) {
-
+
cne->validate ();
-
+
CanvasNote* cn;
CanvasHit* ch;
-
+
if ((cn = dynamic_cast<CanvasNote*>(cne)) != 0) {
update_note (cn);
} else if ((ch = dynamic_cast<CanvasHit*>(cne)) != 0) {
} else {
cne->hide ();
}
-
+
} else {
-
+
add_note (note, visible);
}
-
+
} else {
-
+
if ((cne = find_canvas_note (note)) != 0) {
cne->validate ();
cne->hide ();
}
}
}
-
+
/* remove note items that are no longer valid */
-
+
for (Events::iterator i = _events.begin(); i != _events.end(); ) {
if (!(*i)->valid ()) {
delete *i;
++i;
}
}
-
+
display_sysexes();
display_program_changes();
-
- _model->read_unlock();
-
+
_marked_for_selection.clear ();
_marked_for_velocity.clear ();
MIDI::Name::PatchPrimaryKey patch_key(msb, lsb, program_number);
- boost::shared_ptr<MIDI::Name::Patch> patch =
+ boost::shared_ptr<MIDI::Name::Patch> patch =
MIDI::Name::MidiPatchManager::instance().find_patch(
_model_name, _custom_device_mode, channel, patch_key);
}
}
-void
+void
MidiRegionView::display_sysexes()
{
for (MidiModel::SysExes::const_iterator i = _model->sysexes().begin(); i != _model->sysexes().end(); ++i) {
Evoral::MusicalTime time = (*i)->time();
assert(time >= 0);
-
+
ostringstream str;
str << hex;
for (uint32_t b = 0; b < (*i)->size(); ++b) {
}
}
string text = str.str();
-
+
ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
const double x = trackview.editor().frame_to_pixel(beats_to_frames(time));
-
+
double height = midi_stream_view()->contents_height();
-
+
boost::shared_ptr<CanvasSysEx> sysex = boost::shared_ptr<CanvasSysEx>(
new CanvasSysEx(*this, *group, text, height, x, 1.0));
-
+
// Show unless program change is beyond the region bounds
if (time - _region->start() >= _region->length() || time < _region->start()) {
sysex->hide();
} else {
sysex->show();
}
-
+
_sys_exes.push_back(sysex);
}
}
{
in_destructor = true;
+ delete _list_editor;
+
RegionViewGoingAway (this); /* EMIT_SIGNAL */
if (_active_notes) {
}
void
-MidiRegionView::region_resized (Change what_changed)
+MidiRegionView::region_resized (const PropertyChange& what_changed)
{
RegionView::region_resized(what_changed);
-
- if (what_changed & ARDOUR::PositionChanged) {
+
+ if (what_changed.contains (ARDOUR::Properties::position)) {
set_duration(_region->length(), 0);
if (_enable_display) {
redisplay_model();
}
- }
+ }
}
void
const double old_height = _height;
RegionView::set_height(height);
_height = height - FUDGE;
-
+
apply_note_range(midi_stream_view()->lowest_note(),
midi_stream_view()->highest_note(),
height != old_height + FUDGE);
-
+
if (name_pixbuf) {
name_pixbuf->raise_to_top();
}
CanvasNoteEvent* event = *i;
boost::shared_ptr<NoteType> note (event->note());
- if (note->note() < _current_range_min ||
+ if (note->note() < _current_range_min ||
note->note() > _current_range_max) {
event->hide();
} else {
event->show();
}
-
+
if (CanvasNote* cnote = dynamic_cast<CanvasNote*>(event)) {
const double y1 = midi_stream_view()->note_to_y(note->note());
const double y2 = y1 + floor(midi_stream_view()->note_height());
-
+
cnote->property_y1() = y1;
cnote->property_y2() = y2;
double x = trackview.editor().frame_to_pixel(
beats_to_frames(note->time()) - _region->start());
const double diamond_size = midi_stream_view()->note_height() / 2.0;
- double y = midi_stream_view()->note_to_y(event->note()->note())
+ double y = midi_stream_view()->note_to_y(event->note()->note())
+ ((diamond_size-2.0) / 4.0);
-
+
chit->set_height (diamond_size);
chit->move (x - chit->x1(), y - chit->y1());
chit->show ();
}
}
- ghost->GoingAway.connect (mem_fun(*this, &MidiRegionView::remove_ghost));
+ GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&RegionView::remove_ghost, this, _1), gui_context());
return ghost;
}
}
}
-void
+void
MidiRegionView::play_midi_note(boost::shared_ptr<NoteType> note)
{
- if (!trackview.editor().sound_notes()) {
+ if (no_sound_notes || !trackview.editor().sound_notes()) {
return;
}
RouteUI* route_ui = dynamic_cast<RouteUI*> (&trackview);
assert(route_ui);
-
+
route_ui->midi_track()->write_immediate_event(
note->on_event().size(), note->on_event().buffer());
-
+
const double note_length_beats = (note->off_event().time() - note->on_event().time());
nframes_t note_length_ms = beats_to_frames(note_length_beats)
- * (1000 / (double)route_ui->session().nominal_frame_rate());
- Glib::signal_timeout().connect(bind(mem_fun(this, &MidiRegionView::play_midi_note_off), note),
+ * (1000 / (double)route_ui->session()->nominal_frame_rate());
+ Glib::signal_timeout().connect(sigc::bind(sigc::mem_fun(this, &MidiRegionView::play_midi_note_off), note),
note_length_ms, G_PRIORITY_DEFAULT);
}
{
RouteUI* route_ui = dynamic_cast<RouteUI*> (&trackview);
assert(route_ui);
-
+
route_ui->midi_track()->write_immediate_event(
note->off_event().size(), note->off_event().buffer());
{
const nframes64_t note_start_frames = beats_to_frames(note->time());
- bool outside = (note_start_frames - _region->start() >= _region->length()) ||
+ bool outside = (note_start_frames - _region->start() >= _region->length()) ||
(note_start_frames < _region->start());
visible = (note->note() >= midi_stream_view()->lowest_note()) &&
const double x = trackview.editor().frame_to_pixel(note_start_frames - _region->start());
const double y1 = midi_stream_view()->note_to_y(note->note());
- const double note_endpixel =
+ const double note_endpixel =
trackview.editor().frame_to_pixel(note_end_frames - _region->start());
ev->property_x1() = x;
ev->property_x2() = trackview.editor().frame_to_pixel(_region->length());
}
ev->property_y2() = y1 + floor(midi_stream_view()->note_height());
-
+
if (note->length() == 0) {
if (_active_notes) {
assert(note->note() < 128);
const double diamond_size = midi_stream_view()->note_height() / 2.0;
const double y = midi_stream_view()->note_to_y(note->note()) + ((diamond_size-2) / 4.0);
- ev->move_event (x, y);
+ ev->move_to (x, y);
}
/** Add a MIDI note to the view (with length).
MidiRegionView::add_note(const boost::shared_ptr<NoteType> note, bool visible)
{
CanvasNoteEvent* event = 0;
-
+
assert(note->time() >= 0);
assert(midi_view()->note_mode() == Sustained || midi_view()->note_mode() == Percussive);
ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
if (midi_view()->note_mode() == Sustained) {
-
+
CanvasNote* ev_rect = new CanvasNote(*this, *group, note);
update_note (ev_rect);
if (event) {
if (_marked_for_selection.find(note) != _marked_for_selection.end()) {
note_selected(event, true);
- }
+ }
if (_marked_for_velocity.find(note) != _marked_for_velocity.end()) {
event->show_velocity();
}
void
-MidiRegionView::add_note (uint8_t channel, uint8_t number, uint8_t velocity,
+MidiRegionView::add_note (uint8_t channel, uint8_t number, uint8_t velocity,
Evoral::MusicalTime pos, Evoral::MusicalTime len)
{
boost::shared_ptr<NoteType> new_note (new NoteType (channel, pos, len, number, velocity));
-
+
start_delta_command (_("step add"));
delta_add_note (new_note, true, false);
apply_delta();
MidiRegionView::add_pgm_change(PCEvent& program, const string& displaytext)
{
assert(program.time >= 0);
-
+
ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
const double x = trackview.editor().frame_to_pixel(beats_to_frames(program.time));
-
+
double height = midi_stream_view()->contents_height();
-
+
boost::shared_ptr<CanvasProgramChange> pgm_change = boost::shared_ptr<CanvasProgramChange>(
new CanvasProgramChange(*this, *group,
- displaytext,
- height,
- x, 1.0,
- _model_name,
- _custom_device_mode,
+ displaytext,
+ height,
+ x, 1.0,
+ _model_name,
+ _custom_device_mode,
program.time, program.channel, program.value));
-
+
// Show unless program change is beyond the region bounds
if (program.time - _region->start() >= _region->length() || program.time < _region->start()) {
pgm_change->hide();
} else {
pgm_change->show();
}
-
+
_pgm_changes.push_back(pgm_change);
}
lsb = lsb_control->get_float(true, time);
cerr << " got lsb " << lsb;
}
-
+
Evoral::Parameter program_change(MidiPgmChangeAutomation, channel, 0);
boost::shared_ptr<Evoral::Control> program_control = _model->control(program_change);
float program_number = -1.0;
program_number = program_control->get_float(true, time);
cerr << " got program " << program_number << endl;
}
-
+
key.msb = (int) floor(msb + 0.5);
key.lsb = (int) floor(lsb + 0.5);
key.program_number = (int) floor(program_number + 0.5);
}
-void
+void
MidiRegionView::alter_program_change(PCEvent& old_program, const MIDI::Name::PatchPrimaryKey& new_patch)
{
// TODO: Get the real event here and alter them at the original times
if (lsb_control != 0) {
lsb_control->set_float(float(new_patch.lsb), true, old_program.time);
}
-
+
Evoral::Parameter program_change(MidiPgmChangeAutomation, old_program.channel, 0);
boost::shared_ptr<Evoral::Control> program_control = _model->control(program_change);
-
+
assert(program_control != 0);
program_control->set_float(float(new_patch.program_number), true, old_program.time);
-
+
redisplay_model();
}
alter_program_change(program_change_event, new_patch);
}
-void
+void
MidiRegionView::previous_program(CanvasProgramChange& program)
{
MIDI::Name::PatchPrimaryKey key;
get_patch_key_at(program.event_time(), program.channel(), key);
-
- boost::shared_ptr<MIDI::Name::Patch> patch =
+
+ boost::shared_ptr<MIDI::Name::Patch> patch =
MIDI::Name::MidiPatchManager::instance().previous_patch(
_model_name,
- _custom_device_mode,
- program.channel(),
+ _custom_device_mode,
+ program.channel(),
key);
-
+
PCEvent program_change_event(program.event_time(), program.program(), program.channel());
if (patch) {
alter_program_change(program_change_event, patch->patch_primary_key());
}
}
-void
+void
MidiRegionView::next_program(CanvasProgramChange& program)
{
MIDI::Name::PatchPrimaryKey key;
get_patch_key_at(program.event_time(), program.channel(), key);
-
- boost::shared_ptr<MIDI::Name::Patch> patch =
+
+ boost::shared_ptr<MIDI::Name::Patch> patch =
MIDI::Name::MidiPatchManager::instance().next_patch(
_model_name,
- _custom_device_mode,
- program.channel(),
- key);
+ _custom_device_mode,
+ program.channel(),
+ key);
PCEvent program_change_event(program.event_time(), program.program(), program.channel());
if (patch) {
}
}
+void
+MidiRegionView::select_matching_notes (uint8_t notenum, uint16_t channel_mask, bool add, bool extend)
+{
+ uint8_t low_note = 127;
+ uint8_t high_note = 0;
+ MidiModel::Notes& notes (_model->notes());
+ _optimization_iterator = _events.begin();
+
+ if (extend && _selection.empty()) {
+ extend = false;
+ }
+
+ if (extend) {
+
+ /* scan existing selection to get note range */
+
+ for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
+ if ((*i)->note()->note() < low_note) {
+ low_note = (*i)->note()->note();
+ }
+ if ((*i)->note()->note() > high_note) {
+ high_note = (*i)->note()->note();
+ }
+ }
+
+ low_note = min (low_note, notenum);
+ high_note = max (high_note, notenum);
+ }
+
+ no_sound_notes = true;
+
+ for (MidiModel::Notes::iterator n = notes.begin(); n != notes.end(); ++n) {
+
+ boost::shared_ptr<NoteType> note (*n);
+ CanvasNoteEvent* cne;
+ bool select = false;
+
+ if (((0x0001 << note->channel()) & channel_mask) != 0) {
+ if (extend) {
+ if ((note->note() >= low_note && note->note() <= high_note)) {
+ select = true;
+ }
+ } else if (note->note() == notenum) {
+ select = true;
+ }
+ }
+
+ if (select) {
+ if ((cne = find_canvas_note (note)) != 0) {
+ // extend is false because we've taken care of it,
+ // since it extends by time range, not pitch.
+ note_selected (cne, add, false);
+ }
+ }
+
+ add = true; // we need to add all remaining matching notes, even if the passed in value was false (for "set")
+
+ }
+
+ no_sound_notes = false;
+}
+
+void
+MidiRegionView::toggle_matching_notes (uint8_t notenum, uint16_t channel_mask)
+{
+ MidiModel::Notes& notes (_model->notes());
+ _optimization_iterator = _events.begin();
+
+ for (MidiModel::Notes::iterator n = notes.begin(); n != notes.end(); ++n) {
+
+ boost::shared_ptr<NoteType> note (*n);
+ CanvasNoteEvent* cne;
+
+ if (note->note() == notenum && (((0x0001 << note->channel()) & channel_mask) != 0)) {
+ if ((cne = find_canvas_note (note)) != 0) {
+ if (cne->selected()) {
+ note_deselected (cne);
+ } else {
+ note_selected (cne, true, false);
+ }
+ }
+ }
+ }
+}
+
void
MidiRegionView::note_selected(ArdourCanvas::CanvasNoteEvent* ev, bool add, bool extend)
{
for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
if ((*i)->note()->end_time() > latest) {
latest = (*i)->note()->end_time();
- }
+ }
if ((*i)->note()->time() < earliest) {
earliest = (*i)->note()->time();
}
if (ev->note()->time() < earliest) {
earliest = ev->note()->time();
}
-
- for (Events::iterator i = _events.begin(); i != _events.end(); ++i) {
-
+
+ for (Events::iterator i = _events.begin(); i != _events.end(); ++i) {
+
/* find notes entirely within OR spanning the earliest..latest range */
-
+
if (((*i)->note()->time() >= earliest && (*i)->note()->end_time() <= latest) ||
((*i)->note()->time() <= earliest && (*i)->note()->end_time() >= latest)) {
add_to_selection (*i);
- }
+ }
#if 0
/* if events were guaranteed to be time sorted, we could do this.
but as of sept 10th 2009, they no longer are.
*/
-
+
if ((*i)->note()->time() > latest) {
break;
}
for (Events::iterator i = _events.begin(); i != _events.end(); ++i) {
/* check if any corner of the note is inside the rect
-
+
Notes:
1) this is computing "touched by", not "contained by" the rect.
2) this does not require that events be sorted in time.
ev->selected (false);
ev->hide_velocity ();
-
+
if (_selection.empty()) {
PublicEditor& editor (trackview.editor());
editor.get_selection().remove (this);
}
if (_selection.insert (ev).second) {
+ cerr << "Added CNE to selection, size now " << _selection.size() << endl;
ev->selected (true);
play_midi_note ((ev)->note());
}
}
void
-MidiRegionView::note_dropped(CanvasNoteEvent* ev, double dt, int8_t dnote)
+MidiRegionView::note_dropped(CanvasNoteEvent *, double dt, int8_t dnote)
{
assert (!_selection.empty());
/*
cerr << "dnote: " << (int) dnote << endl;
- cerr << "lowest note (streamview): " << int(midi_stream_view()->lowest_note())
+ cerr << "lowest note (streamview): " << int(midi_stream_view()->lowest_note())
<< " highest note (streamview): " << int(midi_stream_view()->highest_note()) << endl;
- cerr << "lowest note (selection): " << int(lowest_note_in_selection) << " highest note(selection): "
+ cerr << "lowest note (selection): " << int(lowest_note_in_selection) << " highest note(selection): "
<< int(highest_note_in_selection) << endl;
cerr << "selection size: " << _selection.size() << endl;
cerr << "Highest note in selection: " << (int) highest_note_in_selection << endl;
*/
// Make sure the note pitch does not exceed the MIDI standard range
- if (dnote <= 127 && (highest_note_in_selection + dnote > 127)) {
+ if (highest_note_in_selection + dnote > 127) {
highest_note_difference = highest_note_in_selection - 127;
}
-
+
start_diff_command(_("move notes"));
for (Selection::iterator i = _selection.begin(); i != _selection.end() ; ++i) {
// keep notes in standard midi range
clamp_to_0_127(new_pitch);
-
+
// keep original pitch if note is dragged outside valid midi range
if ((original_pitch != 0 && new_pitch == 0)
|| (original_pitch != 127 && new_pitch == 127)) {
}
apply_diff();
-
+
// care about notes being moved beyond the upper/lower bounds on the canvas
if (lowest_note_in_selection < midi_stream_view()->lowest_note() ||
highest_note_in_selection > midi_stream_view()->highest_note()) {
current_x = delta_x - get_end_position_pixels ();
}
}
-
+
if (at_front) {
resize_rect->property_x1() = snap_to_pixel(current_x);
resize_rect->property_x2() = canvas_note->x2();
current_x = region_start + delta_x;
}
}
-
+
current_x = snap_pixel_to_frame (current_x);
current_x = frames_to_beats (current_x);
} else {
Evoral::MusicalTime new_pos = event->note()->time() + front_delta;
-
+
if (new_pos < event->note()->end_time()) {
new_start = event->note()->time() + front_delta;
/* start moved toward the end, so move the end point back to where it used to be */
- new_length = event->note()->length() - front_delta;
+ new_length = event->note()->length() - front_delta;
change_start = true;
change_length = true;
}
if (event->note()->length() < -end_delta) {
can_change = false;
}
- }
+ }
if (can_change) {
new_length = event->note()->length() + end_delta;
new_time = 0;
} else {
new_time = event->note()->time() + delta;
- }
+ }
} else {
new_time = event->note()->time() + delta;
}
}
start_diff_command(_("change velocities"));
-
+
for (Selection::iterator i = _selection.begin(); i != _selection.end();) {
Selection::iterator next = i;
++next;
change_note_velocity (*i, delta, true);
i = next;
}
-
+
apply_diff();
}
}
int8_t delta;
-
+
if (fine) {
delta = 1;
} else {
if (shorter) {
delta = -delta;
}
-
+
start_diff_command (_("change note lengths"));
for (Selection::iterator i = _selection.begin(); i != _selection.end(); ) {
Selection::iterator next = i;
++next;
-
+
/* note the negation of the delta for start */
trim_note (*i, (start ? -delta : 0), (end ? delta : 0));
return;
}
- /* pick a note as the point along the timeline to get the nudge distance.
- its not necessarily the earliest note, so we may want to pull the notes out
+ /* pick a note as the point along the timeline to get the nudge distance.
+ its not necessarily the earliest note, so we may want to pull the notes out
into a vector and sort before using the first one.
*/
nframes64_t unused;
nframes64_t distance;
- if ((distance = trackview.editor().get_nudge_distance (ref_point, unused)) == 0) {
+ if (trackview.editor().snap_mode() == Editing::SnapOff) {
+
+ /* grid is off - use nudge distance */
+
+ distance = trackview.editor().get_nudge_distance (ref_point, unused);
- /* no nudge distance set - use grid */
+ } else {
+
+ /* use grid */
nframes64_t next_pos = ref_point;
-
+
if (forward) {
/* XXX need check on max_frames, but that needs max_frames64 or something */
next_pos += 1;
- } else {
+ } else {
if (next_pos == 0) {
return;
}
next_pos -= 1;
}
-
+
cerr << "ref point was " << ref_point << " next was " << next_pos;
trackview.editor().snap_to (next_pos, (forward ? 1 : -1), false);
distance = ref_point - next_pos;
cerr << " final is " << next_pos << " distance = " << distance << endl;
- }
-
+ }
+
if (distance == 0) {
return;
}
note_selected(ev, true);
}
- PublicEditor& editor (trackview.editor());
char buf[4];
snprintf (buf, sizeof (buf), "%d", (int) ev->note()->note());
+ // This causes an infinite loop on note add sometimes
+ //PublicEditor& editor (trackview.editor());
//editor.show_verbose_canvas_cursor_with (Evoral::midi_note_name (ev->note()->note()));
- editor.show_verbose_canvas_cursor_with (buf);
+ //editor.show_verbose_canvas_cursor_with (buf);
}
void
PublicEditor& editor (trackview.editor());
editor.hide_verbose_canvas_cursor ();
}
-
+
void
MidiRegionView::switch_source(boost::shared_ptr<Source> src)
}
}
-void
+void
MidiRegionView::midi_channel_mode_changed(ChannelMode mode, uint16_t mask)
{
switch (mode) {
_last_channel_selection = mask;
}
-void
+void
MidiRegionView::midi_patch_settings_changed(std::string model, std::string custom_device_mode)
{
_model_name = model;
default:
break;
}
-
+
start_delta_command();
for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
MidiCutBuffer*
MidiRegionView::selection_as_cut_buffer () const
{
- NoteList notes;
+ Notes notes;
+
+ cerr << "Convert selection of " << _selection.size() << " into a cut buffer\n";
for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) {
- notes.push_back (boost::shared_ptr<NoteType> (new NoteType (*((*i)->note().get()))));
+ NoteType* n = (*i)->note().get();
+ cerr << "CNE's note is " << n << endl;
+ notes.insert (boost::shared_ptr<NoteType> (new NoteType (*n)));
}
- /* sort them into time order */
-
- Evoral::Sequence<Evoral::MusicalTime>::LaterNoteComparator cmp;
- sort (notes.begin(), notes.end(), cmp);
-
MidiCutBuffer* cb = new MidiCutBuffer (trackview.session());
cb->set (notes);
-
+
return cb;
}
Evoral::MusicalTime duration;
Evoral::MusicalTime end_point;
- duration = mcb.notes().back()->end_time() - mcb.notes().front()->time();
+ duration = (*mcb.notes().rbegin())->end_time() - (*mcb.notes().begin())->time();
paste_pos_beats = frames_to_beats (pos - _region->position());
- beat_delta = mcb.notes().front()->time() - paste_pos_beats;
+ beat_delta = (*mcb.notes().begin())->time() - paste_pos_beats;
paste_pos_beats = 0;
_selection.clear ();
for (int n = 0; n < (int) times; ++n) {
- for (NoteList::const_iterator i = mcb.notes().begin(); i != mcb.notes().end(); ++i) {
-
+ for (Notes::const_iterator i = mcb.notes().begin(); i != mcb.notes().end(); ++i) {
+
boost::shared_ptr<NoteType> copied_note (new NoteType (*((*i).get())));
copied_note->set_time (paste_pos_beats + copied_note->time() - beat_delta);
if (end_frame > region_end) {
- trackview.session().begin_reversible_command (_("paste"));
+ trackview.session()->begin_reversible_command (_("paste"));
- XMLNode& before (_region->get_state());
+ _region->clear_history ();
_region->set_length (end_frame, this);
- trackview.session().add_command (new MementoCommand<Region>(*_region, &before, &_region->get_state()));
+ trackview.session()->add_command (new StatefulDiffCommand (_region));
}
-
+
apply_delta ();
}
/* use the first one */
unique_select (_events.front());
-
+
}
void
}
void
-MidiRegionView::selection_as_notelist (NoteList& selected)
+MidiRegionView::selection_as_notelist (Notes& selected)
{
time_sort_events ();
for (Events::iterator i = _events.begin(); i != _events.end(); ++i) {
if ((*i)->selected()) {
- selected.push_back ((*i)->note());
+ selected.insert ((*i)->note());
}
}
}
-
-