framecnt_t
NoteCreateDrag::grid_frames (framepos_t t) const
{
- bool success;
- Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, t);
- if (!success) {
- grid_beats = Evoral::Beats(1);
- }
- return _region_view->region_beats_to_region_frames (grid_beats);
+ const Evoral::Beats grid_beats = _region_view->get_grid_beats (t);
+ const Evoral::Beats t_beats = _region_view->region_frames_to_region_beats (t);
+
+ return _region_view->region_beats_to_region_frames (t_beats + grid_beats)
+ - _region_view->region_beats_to_region_frames (t_beats);
}
void
const framepos_t pf = _drags->current_pointer_frame ();
const int32_t divisions = _editor->get_grid_music_divisions (event->button.state);
+ const Evoral::Beats grid_beats = _region_view->get_grid_beats (pf);
+
double eqaf = map.exact_qn_at_frame (pf, divisions);
if (divisions != 0) {
- bool success = false;
- Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, pf);
- if (!success) {
- grid_beats = Evoral::Beats(1);
- }
const double qaf = map.quarter_note_at_frame (pf);
}
_note[0] = map.frame_at_quarter_note (eqaf) - _region_view->region()->position();
- _note[1] = _note[0];
+ /* minimum initial length is grid beats */
+ _note[1] = map.frame_at_quarter_note (eqaf + grid_beats.to_double()) - _region_view->region()->position();
MidiStreamView* sv = _region_view->midi_stream_view ();
- double const x = _editor->sample_to_pixel (_note[0]);
+ double const x0 = _editor->sample_to_pixel (_note[0]);
+ double const x1 = _editor->sample_to_pixel (_note[1]);
double const y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
- _drag_rect->set (ArdourCanvas::Rect (x, y, x, y + floor (_region_view->midi_stream_view()->note_height ())));
+ _drag_rect->set (ArdourCanvas::Rect (x0, y, x1, y + floor (_region_view->midi_stream_view()->note_height ())));
_drag_rect->set_outline_all ();
_drag_rect->set_outline_color (0xffffff99);
_drag_rect->set_fill_color (0xffffff66);
double eqaf = map.exact_qn_at_frame (pf, divisions);
if (divisions != 0) {
- bool success = false;
- Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, pf);
- if (!success) {
- grid_beats = Evoral::Beats(1);
- }
+
+ const Evoral::Beats grid_beats = _region_view->get_grid_beats (pf);
const double qaf = map.quarter_note_at_frame (pf);
/* Hack so that we always snap to the note that we are over, instead of snapping
void
NoteCreateDrag::finished (GdkEvent* ev, bool had_movement)
{
- if (!had_movement) {
- return;
- }
-
+ /* we create a note even if there was no movement */
framepos_t const start = min (_note[0], _note[1]);
framepos_t const start_sess_rel = start + _region_view->region()->position();
- framecnt_t length = (framecnt_t) fabs ((double)(_note[0] - _note[1]));
-
+ framecnt_t length = max (_editor->pixel_to_sample (1.0), (framecnt_t) fabs ((double)(_note[0] - _note[1])));
framecnt_t const g = grid_frames (start);
- Evoral::Beats const one_tick = Evoral::Beats::ticks(1);
if (_editor->get_grid_music_divisions (ev->button.state) != 0 && length < g) {
length = g;
}
TempoMap& map (_editor->session()->tempo_map());
- const double qn_length = map.quarter_note_at_frame (start_sess_rel + length) - map.quarter_note_at_frame (start_sess_rel);
+ const double qn_length = map.quarter_notes_between_frames (start_sess_rel, start_sess_rel + length);
+ Evoral::Beats qn_length_beats = max (Evoral::Beats::ticks(1), Evoral::Beats (qn_length));
- Evoral::Beats qn_length_beats = max (one_tick, Evoral::Beats (qn_length));
_region_view->create_note_at (start, _drag_rect->y0(), qn_length_beats, ev->button.state, false);
}
}
+HitCreateDrag::HitCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv)
+ : Drag (e, i)
+ , _region_view (rv)
+ , _last_pos (0)
+ , _last_y (0.0)
+{
+}
+
+HitCreateDrag::~HitCreateDrag ()
+{
+}
+
+void
+HitCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
+{
+ Drag::start_grab (event, cursor);
+
+ TempoMap& map (_editor->session()->tempo_map());
+
+ const framepos_t pf = _drags->current_pointer_frame ();
+ const int32_t divisions = _editor->get_grid_music_divisions (event->button.state);
+
+ const double eqaf = map.exact_qn_at_frame (pf, divisions);
+
+ boost::shared_ptr<MidiRegion> mr = _region_view->midi_region();
+
+ if (eqaf >= mr->quarter_note() + mr->length_beats()) {
+ return;
+ }
+
+ const framepos_t start = map.frame_at_quarter_note (eqaf) - _region_view->region()->position();
+
+ MidiStreamView* sv = _region_view->midi_stream_view ();
+ const double y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
+
+ Evoral::Beats length = _region_view->get_grid_beats (pf);
+
+ _region_view->create_note_at (start, y, length, event->button.state, false);
+
+ _last_pos = start;
+ _last_y = y;
+}
+
+void
+HitCreateDrag::motion (GdkEvent* event, bool)
+{
+ TempoMap& map (_editor->session()->tempo_map());
+
+ const framepos_t pf = _drags->current_pointer_frame ();
+ const int32_t divisions = _editor->get_grid_music_divisions (event->button.state);
+
+ if (divisions == 0) {
+ return;
+ }
+
+ const double eqaf = map.exact_qn_at_frame (pf, divisions);
+ const framepos_t start = map.frame_at_quarter_note (eqaf) - _region_view->region()->position ();
+
+ MidiStreamView* sv = _region_view->midi_stream_view ();
+ const double y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
+
+ if (_last_pos == start && y == _last_y) {
+ return;
+ }
+
+ Evoral::Beats length = _region_view->get_grid_beats (pf);
+
+ boost::shared_ptr<MidiRegion> mr = _region_view->midi_region();
+ if (eqaf >= mr->quarter_note() + mr->length_beats()) {
+ return;
+ }
+
+ _region_view->create_note_at (start, y, length, event->button.state, false);
+
+ _last_pos = start;
+ _last_y = y;
+}
+
+void
+HitCreateDrag::finished (GdkEvent* /* ev */, bool /* had_movement */)
+{
+
+}
+
+double
+HitCreateDrag::y_to_region (double y) const
+{
+ double x = 0;
+ _region_view->get_canvas_group()->canvas_to_item (x, y);
+ return y;
+}
+
+void
+HitCreateDrag::aborted (bool)
+{
+ // umm..
+}
+
CrossfadeEdgeDrag::CrossfadeEdgeDrag (Editor* e, AudioRegionView* rv, ArdourCanvas::Item* i, bool start_yn)
: Drag (e, i)
, arv (rv)
{
line->set_position (pos);
line->show ();
+ line->track_canvas_item().reparent (_editor->_drag_motion_group);
}
RegionCutDrag::~RegionCutDrag ()
}
void
-RegionCutDrag::motion (GdkEvent*, bool)
+RegionCutDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
{
- framepos_t where = _drags->current_pointer_frame();
- _editor->snap_to (where);
+ Drag::start_grab (event, c);
+ motion (event, false);
+}
- line->set_position (where);
+void
+RegionCutDrag::motion (GdkEvent* event, bool)
+{
+ framepos_t pos = _drags->current_pointer_frame();
+ _editor->snap_to_with_modifier (pos, event);
+
+ line->set_position (pos);
}
void
_editor->get_track_canvas()->canvas()->re_enter();
framepos_t pos = _drags->current_pointer_frame();
+ _editor->snap_to_with_modifier (pos, event);
line->hide ();
return;
}
- _editor->split_regions_at (pos, rs, _editor->get_grid_music_divisions (event->button.state));
+ _editor->split_regions_at (pos, rs, _editor->get_grid_music_divisions (event->button.state),
+ false);
}
void