using namespace Editing;
using namespace ArdourCanvas;
-MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color& basic_color)
+MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv,
+ boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color& basic_color)
: RegionView (parent, tv, r, spu, basic_color)
, _force_channel(-1)
, _last_channel_selection(0xFFFF)
- , _default_note_length(0.0)
+ , _default_note_length(1.0)
, _current_range_min(0)
, _current_range_max(0)
, _model_name(string())
_note_group->raise_to_top();
}
-MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color& basic_color, TimeAxisViewItem::Visibility visibility)
+MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv,
+ boost::shared_ptr<MidiRegion> r, double spu, Gdk::Color& basic_color,
+ TimeAxisViewItem::Visibility visibility)
: RegionView (parent, tv, r, spu, basic_color, false, visibility)
, _force_channel(-1)
, _last_channel_selection(0xFFFF)
- , _default_note_length(0.0)
+ , _default_note_length(1.0)
, _model_name(string())
, _custom_device_mode(string())
, _active_notes(0)
: RegionView (other)
, _force_channel(-1)
, _last_channel_selection(0xFFFF)
- , _default_note_length(0.0)
+ , _default_note_length(1.0)
, _model_name(string())
, _custom_device_mode(string())
, _active_notes(0)
init (c, false);
}
-MidiRegionView::MidiRegionView (const MidiRegionView& other, boost::shared_ptr<MidiRegion> other_region)
- : RegionView (other, boost::shared_ptr<Region> (other_region))
+MidiRegionView::MidiRegionView (const MidiRegionView& other, boost::shared_ptr<MidiRegion> region)
+ : RegionView (other, boost::shared_ptr<Region> (region))
, _force_channel(-1)
, _last_channel_selection(0xFFFF)
- , _default_note_length(0.0)
+ , _default_note_length(1.0)
, _model_name(string())
, _custom_device_mode(string())
, _active_notes(0)
void
MidiRegionView::init (Gdk::Color& basic_color, bool wfd)
{
- if (wfd)
+ if (wfd) {
midi_region()->midi_source(0)->load_model();
-
- const Meter& m = trackview.session().tempo_map().meter_at(_region->position());
- const Tempo& t = trackview.session().tempo_map().tempo_at(_region->position());
- _default_note_length = m.frames_per_bar(t, trackview.session().frame_rate())
- / m.beats_per_bar();
+ }
_model = midi_region()->midi_source(0)->model();
_enable_display = false;
static ArdourCanvas::SimpleRect* drag_rect = NULL;
- if (trackview.editor.current_mouse_mode() != MouseNote)
+ if (trackview.editor().current_mouse_mode() != MouseNote)
return false;
-
- // Mmmm, spaghetti
+
+ const Editing::MidiEditMode midi_edit_mode = trackview.editor().current_midi_edit_mode();
switch (ev->type) {
case GDK_KEY_PRESS:
if (ev->key.keyval == GDK_Delete && !delete_mod) {
delete_mod = true;
- original_mode = trackview.editor.current_midi_edit_mode();
- trackview.editor.set_midi_edit_mode(MidiEditErase);
+ original_mode = midi_edit_mode;
+ trackview.editor().set_midi_edit_mode(MidiEditErase);
start_delta_command(_("erase notes"));
_mouse_state = EraseTouchDragging;
return true;
apply_command();
}
if (delete_mod) {
- trackview.editor.set_midi_edit_mode(original_mode);
+ trackview.editor().set_midi_edit_mode(original_mode);
_mouse_state = None;
delete_mod = false;
}
group->w2i(event_x, event_y);
// convert event_x to global frame
- event_frame = trackview.editor.pixel_to_frame(event_x) + _region->position();
- trackview.editor.snap_to(event_frame);
+ event_frame = trackview.editor().pixel_to_frame(event_x) + _region->position();
+ trackview.editor().snap_to(event_frame);
// convert event_frame back to local coordinates relative to position
event_frame -= _region->position();
case Pressed: // Drag start
// Select drag start
- if (_pressed_button == 1 && trackview.editor.current_midi_edit_mode() == MidiEditSelect) {
+ if (_pressed_button == 1 && midi_edit_mode == MidiEditSelect) {
group->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
Gdk::Cursor(Gdk::FLEUR), ev->motion.time);
last_x = event_x;
return true;
// Add note drag start
- } else if (trackview.editor.current_midi_edit_mode() == MidiEditPencil) {
+ } else if (midi_edit_mode == MidiEditPencil) {
group->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK,
Gdk::Cursor(Gdk::FLEUR), ev->motion.time);
last_x = event_x;
drag_start_y = event_y;
drag_rect = new ArdourCanvas::SimpleRect(*group);
- drag_rect->property_x1() = trackview.editor.frame_to_pixel(event_frame);
+ drag_rect->property_x1() = trackview.editor().frame_to_pixel(event_frame);
- drag_rect->property_y1() = midi_stream_view()->note_to_y(midi_stream_view()->y_to_note(event_y));
+ drag_rect->property_y1() = midi_stream_view()->note_to_y(
+ midi_stream_view()->y_to_note(event_y));
drag_rect->property_x2() = event_x;
- drag_rect->property_y2() = drag_rect->property_y1() + floor(midi_stream_view()->note_height());
+ drag_rect->property_y2() = drag_rect->property_y1()
+ + floor(midi_stream_view()->note_height());
drag_rect->property_outline_what() = 0xFF;
drag_rect->property_outline_color_rgba() = 0xFFFFFF99;
-
- drag_rect->property_fill_color_rgba() = 0xFFFFFF66;
+ drag_rect->property_fill_color_rgba() = 0xFFFFFF66;
_mouse_state = AddDragging;
return true;
}
if (_mouse_state == AddDragging)
- event_x = trackview.editor.frame_to_pixel(event_frame);
+ event_x = trackview.editor().frame_to_pixel(event_frame);
if (drag_rect) {
if (event_x > drag_start_x)
event_y = ev->motion.y;
group->w2i(event_x, event_y);
group->ungrab(ev->button.time);
- event_frame = trackview.editor.pixel_to_frame(event_x);
+ event_frame = trackview.editor().pixel_to_frame(event_x);
if (_pressed_button != 1) {
return false;
switch (_mouse_state) {
case Pressed: // Clicked
- switch (trackview.editor.current_midi_edit_mode()) {
+ switch (midi_edit_mode) {
case MidiEditSelect:
case MidiEditResize:
clear_selection();
_mouse_state = None;
if (drag_rect->property_x2() > drag_rect->property_x1() + 2) {
const double x = drag_rect->property_x1();
- const double length = trackview.editor.pixel_to_frame(
+ const double length = trackview.editor().pixel_to_frame(
drag_rect->property_x2() - drag_rect->property_x1());
- create_note_at(x, drag_rect->property_y1(), length);
+ create_note_at(x, drag_rect->property_y1(), frames_to_beats(length));
}
delete drag_rect;
}
-/** Add a note to the model, and the view, at a canvas (click) coordinate */
+/** Add a note to the model, and the view, at a canvas (click) coordinate.
+ * \param x horizontal position in pixels
+ * \param y vertical position in pixels
+ * \param length duration of the note in beats */
void
MidiRegionView::create_note_at(double x, double y, double length)
{
assert(note >= 0.0);
assert(note <= 127.0);
- nframes64_t new_note_time = trackview.editor.pixel_to_frame (x);
- assert(new_note_time >= 0);
- new_note_time += _region->start();
+ // Start of note in frames relative to region start
+ nframes64_t start_frames = snap_to_frame(trackview.editor().pixel_to_frame(x));
+ assert(start_frames >= 0);
- /*
- const Meter& m = trackview.session().tempo_map().meter_at(new_note_time);
- const Tempo& t = trackview.session().tempo_map().tempo_at(new_note_time);
- double length = m.frames_per_bar(t, trackview.session().frame_rate()) / m.beats_per_bar();
- */
-
- // we need to snap here again in nframes64_t in order to be sample accurate
- // since note time is region-absolute but snap_to_frame expects position-relative
- // time we have to coordinate transform back and forth here.
- nframes64_t new_note_time_position_relative = new_note_time - _region->start();
- new_note_time = snap_to_frame(new_note_time_position_relative) + _region->start();
-
- // we need to snap the length too to be sample accurate
- nframes64_t new_note_length = nframes_t(length);
- new_note_length = snap_to_frame(new_note_time_position_relative + new_note_length) + _region->start()
- - new_note_time;
+ // Snap length
+ length = frames_to_beats(
+ snap_to_frame(start_frames + beats_to_frames(length)) - start_frames);
+
+ const boost::shared_ptr<NoteType> new_note(new NoteType(0,
+ frames_to_beats(start_frames + _region->start()), length,
+ (uint8_t)note, 0x40));
- const boost::shared_ptr<Evoral::Note> new_note(new Evoral::Note(
- 0, new_note_time, new_note_length, (uint8_t)note, 0x40));
view->update_note_range(new_note->note());
MidiModel::DeltaCommand* cmd = _model->new_delta_command("add note");
}
}
- for (Events::iterator i = _events.begin(); i != _events.end(); ++i)
+ for (Events::iterator i = _events.begin(); i != _events.end(); ++i) {
delete *i;
+ }
_events.clear();
_pgm_changes.clear();
MidiRegionView::display_model(boost::shared_ptr<MidiModel> model)
{
_model = model;
-
- if (_enable_display)
+ if (_enable_display) {
redisplay_model();
+ }
}
void
MidiRegionView::start_delta_command(string name)
{
- if (!_delta_command)
+ if (!_delta_command) {
_delta_command = _model->new_delta_command(name);
+ }
}
void
-MidiRegionView::command_add_note(const boost::shared_ptr<Evoral::Note> note, bool selected)
+MidiRegionView::command_add_note(const boost::shared_ptr<NoteType> note, bool selected)
{
- if (_delta_command)
+ if (_delta_command) {
_delta_command->add(note);
-
- if (selected)
+ }
+ if (selected) {
_marked_for_selection.insert(note);
+ }
}
void
MidiRegionView::redisplay_model()
{
// Don't redisplay the model if we're currently recording and displaying that
- if (_active_notes)
+ if (_active_notes) {
return;
+ }
if (_model) {
-
clear_events();
_model->read_lock();
-
MidiModel::Notes notes = _model->notes();
/*
- cerr << endl << _model->midi_source()->name() << " : redisplaying " << notes.size() << " notes:" << endl;
+ cerr << _model->midi_source()->name() << " : redisplaying " << notes.size() << endl;
for (MidiModel::Notes::iterator i = notes.begin(); i != notes.end(); ++i) {
cerr << "NOTE time: " << (*i)->time()
<< " pitch: " << int((*i)->note())
add_note(_model->note_at(i));
}
- find_and_insert_program_change_flags();
+ display_program_change_flags();
- // Is this necessary?
- /*for (Automatable::Controls::const_iterator i = _model->controls().begin();
- i != _model->controls().end(); ++i) {
-
- assert(i->second);
-
- boost::shared_ptr<AutomationTimeAxisView> at
- = midi_view()->automation_child(i->second->parameter());
- if (!at)
- continue;
-
- Gdk::Color col = midi_stream_view()->get_region_color();
-
- boost::shared_ptr<AutomationRegionView> arv;
-
- {
- Glib::Mutex::Lock list_lock (i->second->list()->lock());
-
- arv = boost::shared_ptr<AutomationRegionView>(
- new AutomationRegionView(at->canvas_display,
- *at.get(), _region, i->second->list(),
- midi_stream_view()->get_samples_per_unit(), col));
- }
-
- arv->set_duration(_region->length(), this);
- arv->init(col, true);
-
- _automation_children.insert(std::make_pair(i->second->parameter(), arv));
- }*/
_model->read_unlock();
} else {
}
void
-MidiRegionView::find_and_insert_program_change_flags()
+MidiRegionView::display_program_change_flags()
{
- // Draw program change 'flags'
for (Automatable::Controls::iterator control = _model->controls().begin();
control != _model->controls().end(); ++control) {
if (control->first.type() == MidiPgmChangeAutomation) {
Glib::Mutex::Lock list_lock (control->second->list()->lock());
- uint8_t channel = control->first.channel();
+ uint8_t channel = control->first.channel();
for (AutomationList::const_iterator event = control->second->list()->begin();
event != control->second->list()->end(); ++event) {
double event_time = (*event)->when;
double program_number = floor((*event)->value + 0.5);
- //cerr << " got program change on channel " << int(channel) << " time: " << event_time << " number: " << program_number << endl;
+ //cerr << " got program change on channel " << int(channel)
+ // << " time: " << event_time << " number: " << program_number << endl;
// find bank select msb and lsb for the program change
Evoral::Parameter bank_select_msb(MidiCCAutomation, channel, MIDI_CTL_MSB_BANK);
lsb = uint8_t(floor(lsb_control->get_float(true, event_time) + 0.5));
}
- //cerr << " got msb " << int(msb) << " and lsb " << int(lsb) << " thread_id: " << pthread_self() << endl;
+ //cerr << " got msb " << int(msb) << " and lsb " << int(lsb)
+ // << " thread_id: " << pthread_self() << endl;
MIDI::Name::PatchPrimaryKey patch_key(msb, lsb, program_number);
_model_name,
_custom_device_mode,
channel,
- patch_key
- );
+ patch_key);
ControlEvent program_change(nframes_t(event_time), uint8_t(program_number), channel);
if (patch != 0) {
- //cerr << " got patch with name " << patch->name() << " number " << patch->number() << endl;
+ //cerr << " got patch with name " << patch->name()
+ // << " number " << patch->number() << endl;
add_pgm_change(program_change, patch->name());
} else {
char buf[4];
}
break;
} else if (control->first.type() == MidiCCAutomation) {
- //cerr << " found CC Automation of channel " << int(control->first.channel()) << " and id " << control->first.id() << endl;
+ //cerr << " found CC Automation of channel " << int(control->first.channel())
+ // << " and id " << control->first.id() << endl;
}
}
}
RegionView::region_resized(what_changed);
if (what_changed & ARDOUR::PositionChanged) {
- if (_enable_display)
+ if (_enable_display) {
redisplay_model();
+ }
}
}
RegionView::reset_width_dependent_items(pixel_width);
assert(_pixel_width == pixel_width);
- if (_enable_display)
+ if (_enable_display) {
redisplay_model();
+ }
}
void
-MidiRegionView::set_height (gdouble height)
+MidiRegionView::set_height (double height)
{
- static const double FUDGE = 2;
+ static const double FUDGE = 2.0;
const double old_height = _height;
RegionView::set_height(height);
_height = height - FUDGE;
Item* item = dynamic_cast<Item*>(event);
assert(item);
if (event && event->note()) {
- if (event->note()->note() < _current_range_min || event->note()->note() > _current_range_max) {
+ if (event->note()->note() < _current_range_min
+ || event->note()->note() > _current_range_max) {
if (canvas_item_visible(item)) {
item->hide();
}
note->property_y1() = y1;
note->property_y2() = y2;
} else if (CanvasHit* hit = dynamic_cast<CanvasHit*>(event)) {
- double x = trackview.editor.frame_to_pixel((nframes64_t)
- event->note()->time() - _region->start());
+ double x = trackview.editor().frame_to_pixel(
+ beats_to_frames(event->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())
+ ((diamond_size-2.0) / 4.0);
}
}
}
-
}
}
audio waveforms under it.
*/
ghost = new MidiGhostRegion (*mtv->midi_view(), trackview, unit_position);
- }
- else {
+ } else {
ghost = new MidiGhostRegion (tv, trackview, unit_position);
}
void
MidiRegionView::resolve_note(uint8_t note, double end_time)
{
- if (midi_view()->note_mode() != Sustained)
+ if (midi_view()->note_mode() != Sustained) {
return;
+ }
if (_active_notes && _active_notes[note]) {
- _active_notes[note]->property_x2() = trackview.editor.frame_to_pixel((nframes64_t)end_time);
+ _active_notes[note]->property_x2() = trackview.editor().frame_to_pixel((nframes64_t)end_time);
_active_notes[note]->property_outline_what() = (guint32) 0xF; // all edges
_active_notes[note] = NULL;
}
for (unsigned i=0; i < 128; ++i) {
if (_active_notes[i]) {
- _active_notes[i]->property_x2() = trackview.editor.frame_to_pixel(_region->length());
+ _active_notes[i]->property_x2() = trackview.editor().frame_to_pixel(_region->length());
}
}
}
+void
+MidiRegionView::play_midi_note(boost::shared_ptr<NoteType> note)
+{
+ if (!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),
+ note_length_ms, G_PRIORITY_DEFAULT);
+}
+
+bool
+MidiRegionView::play_midi_note_off(boost::shared_ptr<NoteType> note)
+{
+ 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());
+
+ return false;
+}
+
+bool
+MidiRegionView::note_in_visible_range(const boost::shared_ptr<NoteType> note) const
+{
+ const nframes64_t note_start_frames = beats_to_frames(note->time());
+ bool outside = (note_start_frames - _region->start() >= _region->length())
+ || (note_start_frames < _region->start())
+ || (note->note() < midi_stream_view()->lowest_note())
+ || (note->note() > midi_stream_view()->highest_note());
+ return !outside;
+}
/** Add a MIDI note to the view (with length).
*
* event arrives, to properly display the note.
*/
void
-MidiRegionView::add_note(const boost::shared_ptr<Evoral::Note> note)
+MidiRegionView::add_note(const boost::shared_ptr<NoteType> note)
{
assert(note->time() >= 0);
assert(midi_view()->note_mode() == Sustained || midi_view()->note_mode() == Percussive);
- // dont display notes beyond the region bounds
- if ( note->time() - _region->start() >= _region->length() ||
- note->time() < _region->start() ||
- note->note() < midi_stream_view()->lowest_note() ||
- note->note() > midi_stream_view()->highest_note() ) {
- return;
- }
-
+ const nframes64_t note_start_frames = beats_to_frames(note->time());
+ const nframes64_t note_end_frames = beats_to_frames(note->end_time());
+
ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
CanvasNoteEvent* event = 0;
- const double x = trackview.editor.frame_to_pixel((nframes64_t)note->time() - _region->start());
+ const double x = trackview.editor().frame_to_pixel(note_start_frames - _region->start());
if (midi_view()->note_mode() == Sustained) {
-
const double y1 = midi_stream_view()->note_to_y(note->note());
const double note_endpixel =
- trackview.editor.frame_to_pixel((nframes64_t)note->end_time() - _region->start());
+ trackview.editor().frame_to_pixel(note_end_frames - _region->start());
CanvasNote* ev_rect = new CanvasNote(*this, *group, note);
ev_rect->property_x1() = x;
ev_rect->property_y1() = y1;
- if (note->length() > 0)
+ if (note->length() > 0) {
ev_rect->property_x2() = note_endpixel;
- else
- ev_rect->property_x2() = trackview.editor.frame_to_pixel(_region->length());
+ } else {
+ ev_rect->property_x2() = trackview.editor().frame_to_pixel(_region->length());
+ }
ev_rect->property_y2() = y1 + floor(midi_stream_view()->note_height());
if (note->length() == 0) {
-
if (_active_notes) {
assert(note->note() < 128);
// If this note is already active there's a stuck note,
// finish the old note rectangle
if (_active_notes[note->note()]) {
CanvasNote* const old_rect = _active_notes[note->note()];
- boost::shared_ptr<Evoral::Note> old_note = old_rect->note();
+ boost::shared_ptr<NoteType> old_note = old_rect->note();
cerr << "MidiModel: WARNING: Note has length 0: chan " << old_note->channel()
<< "note " << (int)old_note->note() << " @ " << old_note->time() << endl;
/* FIXME: How large to make it? Make it a diamond? */
ev_rect->property_outline_what() = (guint32) 0xF;
}
- ev_rect->show();
- _events.push_back(ev_rect);
event = ev_rect;
MidiGhostRegion* gr;
-
for (std::vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
if ((gr = dynamic_cast<MidiGhostRegion*>(*g)) != 0) {
gr->add_note(ev_rect);
}
} else if (midi_view()->note_mode() == Percussive) {
-
- //cerr << "MRV::add_note percussive " << note->note() << " @ " << note->time()
- // << " .. " << note->end_time() << endl;
-
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);
CanvasHit* ev_diamond = new CanvasHit(*this, *group, diamond_size, note);
ev_diamond->move(x, y);
- ev_diamond->show();
- _events.push_back(ev_diamond);
event = ev_diamond;
} else {
event = 0;
}
- if (event) {
+ if (event) {
if (_marked_for_selection.find(note) != _marked_for_selection.end()) {
note_selected(event, true);
}
event->on_channel_selection_change(_last_channel_selection);
+ _events.push_back(event);
+ if (note_in_visible_range(note)) {
+ event->show();
+ } else {
+ event->hide();
+ }
}
}
return;
ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
- const double x = trackview.editor.frame_to_pixel((nframes64_t)program.time - _region->start());
+ const double x = trackview.editor().frame_to_pixel((nframes64_t)program.time - _region->start());
double height = midi_stream_view()->contents_height();
void
MidiRegionView::get_patch_key_at(double time, uint8_t channel, MIDI::Name::PatchPrimaryKey& key)
{
-
cerr << "getting patch key at " << time << " for channel " << channel << endl;
Evoral::Parameter bank_select_msb(MidiCCAutomation, channel, MIDI_CTL_MSB_BANK);
boost::shared_ptr<Evoral::Control> msb_control = _model->control(bank_select_msb);
void
MidiRegionView::alter_program_change(ControlEvent& old_program, const MIDI::Name::PatchPrimaryKey& new_patch)
{
-
// TODO: Get the real event here and alter them at the original times
Evoral::Parameter bank_select_msb(MidiCCAutomation, old_program.channel, MIDI_CTL_MSB_BANK);
boost::shared_ptr<Evoral::Control> msb_control = _model->control(bank_select_msb);
_model_name,
_custom_device_mode,
program.channel(),
- key
- );
+ key);
ControlEvent program_change_event(program.event_time(), program.program(), program.channel());
if (patch) {
_model_name,
_custom_device_mode,
program.channel(),
- key
- );
+ key);
ControlEvent program_change_event(program.event_time(), program.program(), program.channel());
if (patch) {
alter_program_change(program_change_event, patch->patch_primary_key());
clear_selection_except(ev);
}
- _selection.insert(ev);
+ if (_selection.insert(ev).second) {
+ play_midi_note(ev->note());
+ }
if ( ! ev->selected()) {
ev->selected(true);
if (!(*i)->selected()) {
(*i)->selected(true);
_selection.insert(*i);
+ play_midi_note((*i)->note());
}
// Not inside rectangle
} else if ((*i)->selected()) {
if (!(*i)->selected()) {
(*i)->selected(true);
_selection.insert(*i);
+ play_midi_note((*i)->note());
}
// Not inside rectangle
} else if ((*i)->selected()) {
Selection::iterator next = i;
++next;
- const boost::shared_ptr<Evoral::Note> copy(new Evoral::Note(*(*i)->note().get()));
+ const boost::shared_ptr<NoteType> copy(new NoteType(*(*i)->note().get()));
// we need to snap here again in nframes64_t in order to be sample accurate
- double new_note_time = (*i)->note()->time();
- new_note_time += dt;
+ double start_frames = snap_to_frame(beats_to_frames((*i)->note()->time()) + dt);
// keep notes inside region if dragged beyond left region bound
- if (new_note_time < _region->start()) {
- new_note_time = _region->start();
+ if (start_frames < _region->start()) {
+ start_frames = _region->start();
}
- // since note time is region-absolute but snap_to_frame expects position-relative
- // time we have to coordinate transform back and forth here.
- new_note_time = snap_to_frame(nframes64_t(new_note_time) - _region->start()) + _region->start();
-
- copy->set_time(new_note_time);
+ copy->set_time(frames_to_beats(start_frames));
uint8_t original_pitch = (*i)->note()->note();
- uint8_t new_pitch = original_pitch + dnote - highest_note_difference;
+ uint8_t new_pitch = original_pitch + dnote - highest_note_difference;
// keep notes in standard midi range
- clamp_0_to_127(new_pitch);
+ clamp_to_0_127(new_pitch);
- //notes which are dragged beyond the standard midi range snap back to their original place
- if ((original_pitch != 0 && new_pitch == 0) || (original_pitch != 127 && new_pitch == 127)) {
+ // keep original pitch if note is dragged outside valid midi range
+ if ((original_pitch != 0 && new_pitch == 0)
+ || (original_pitch != 127 && new_pitch == 127)) {
new_pitch = original_pitch;
}
nframes64_t
MidiRegionView::snap_to_frame(double x)
{
- PublicEditor &editor = trackview.editor;
- // x is region relative
- // convert x to global frame
+ PublicEditor &editor = trackview.editor();
+ // x is region relative, convert it to global absolute frames
nframes64_t frame = editor.pixel_to_frame(x) + _region->position();
editor.snap_to(frame);
- // convert event_frame back to local coordinates relative to position
- frame -= _region->position();
- return frame;
+ return frame - _region->position(); // convert back to region relative
}
nframes64_t
MidiRegionView::snap_to_frame(nframes64_t x)
{
- PublicEditor &editor = trackview.editor;
+ PublicEditor &editor = trackview.editor();
// x is region relative
// convert x to global frame
nframes64_t frame = x + _region->position();
double
MidiRegionView::snap_to_pixel(double x)
{
- return (double) trackview.editor.frame_to_pixel(snap_to_frame(x));
+ return (double) trackview.editor().frame_to_pixel(snap_to_frame(x));
}
double
MidiRegionView::get_position_pixels()
{
nframes64_t region_frame = get_position();
- return trackview.editor.frame_to_pixel(region_frame);
+ return trackview.editor().frame_to_pixel(region_frame);
+}
+
+nframes64_t
+MidiRegionView::beats_to_frames(double beats) const
+{
+ const Meter& m = trackview.session().tempo_map().meter_at(_region->position());
+ const Tempo& t = trackview.session().tempo_map().tempo_at(_region->position());
+ return lrint(beats * m.frames_per_bar(t, trackview.session().frame_rate()) / m.beats_per_bar());
+}
+
+double
+MidiRegionView::frames_to_beats(nframes64_t frames) const
+{
+ const Meter& m = trackview.session().tempo_map().meter_at(_region->position());
+ const Tempo& t = trackview.session().tempo_map().tempo_at(_region->position());
+ return frames / m.frames_per_bar(t, trackview.session().frame_rate()) * m.beats_per_bar();
}
void
resize_data->canvas_note = note;
// create a new SimpleRect from the note which will be the resize preview
- SimpleRect *resize_rect =
- new SimpleRect(
- *group,
- note->x1(),
- note->y1(),
- note->x2(),
- note->y2());
+ SimpleRect *resize_rect = new SimpleRect(
+ *group, note->x1(), note->y1(), note->x2(), note->y2());
// calculate the colors: get the color settings
- uint32_t fill_color =
- UINT_RGBA_CHANGE_A(
- ARDOUR_UI::config()->canvasvar_MidiNoteSelected.get(),
- 128);
+ uint32_t fill_color = UINT_RGBA_CHANGE_A(
+ ARDOUR_UI::config()->canvasvar_MidiNoteSelected.get(),
+ 128);
// make the resize preview notes more transparent and bright
fill_color = UINT_INTERPOLATE(fill_color, 0xFFFFFF40, 0.5);
// calculate color based on note velocity
- resize_rect->property_fill_color_rgba() =
- UINT_INTERPOLATE(
+ resize_rect->property_fill_color_rgba() = UINT_INTERPOLATE(
CanvasNoteEvent::meter_style_fill_color(note->note()->velocity()),
fill_color,
0.85);
- resize_rect->property_outline_color_rgba() =
- CanvasNoteEvent::calculate_outline(ARDOUR_UI::config()->canvasvar_MidiNoteSelected.get());
+ resize_rect->property_outline_color_rgba() = CanvasNoteEvent::calculate_outline(
+ ARDOUR_UI::config()->canvasvar_MidiNoteSelected.get());
resize_data->resize_rect = resize_rect;
MidiRegionView::update_resizing(CanvasNote::NoteEnd note_end, double x, bool relative)
{
for (std::vector<NoteResizeData *>::iterator i = _resize_data.begin(); i != _resize_data.end(); ++i) {
- SimpleRect *resize_rect = (*i)->resize_rect;
- CanvasNote *canvas_note = (*i)->canvas_note;
+ SimpleRect* resize_rect = (*i)->resize_rect;
+ CanvasNote* canvas_note = (*i)->canvas_note;
const double region_start = get_position_pixels();
// transform to region start relative
current_frame += _region->start();
- const boost::shared_ptr<Evoral::Note> copy(new Evoral::Note(*(canvas_note->note().get())));
+ const boost::shared_ptr<NoteType> copy(new NoteType(*(canvas_note->note().get())));
// resize beginning of note
if (note_end == CanvasNote::NOTE_ON && current_frame < copy->end_time()) {
void
MidiRegionView::change_note_velocity(CanvasNoteEvent* event, int8_t velocity, bool relative)
{
- const boost::shared_ptr<Evoral::Note> copy(new Evoral::Note(*(event->note().get())));
+ const boost::shared_ptr<NoteType> copy(new NoteType(*(event->note().get())));
if (relative) {
uint8_t new_velocity = copy->velocity() + velocity;
- clamp_0_to_127(new_velocity);
+ clamp_to_0_127(new_velocity);
copy->set_velocity(new_velocity);
} else {
copy->set_velocity(velocity);
for (Selection::iterator i = _selection.begin(); i != _selection.end();) {
Selection::iterator next = i;
++next;
- change_note_velocity(*i, velocity, relative);
+ if ( !(*((*i)->note()) == *(ev->note())) ) {
+ change_note_velocity(*i, velocity, relative);
+ }
i = next;
}
++next;
CanvasNoteEvent* event = *i;
- const boost::shared_ptr<Evoral::Note> copy(new Evoral::Note(*(event->note().get())));
+ const boost::shared_ptr<NoteType> copy(new NoteType(*(event->note().get())));
copy->set_channel(channel);