updated Temporal::Beats ... GUI edition

This commit is contained in:
Paul Davis 2020-07-13 18:03:18 -06:00
parent 4dc048b28a
commit 0a469527f1
14 changed files with 80 additions and 83 deletions

View file

@ -247,7 +247,7 @@ AutomationRegionView::paste (samplepos_t pos
/* add multi-paste offset if applicable */ /* add multi-paste offset if applicable */
if (parameter_is_midi (src_type)) { if (parameter_is_midi (src_type)) {
// convert length to samples (incl tempo-ramps) // convert length to samples (incl tempo-ramps)
len = DoubleBeatsSamplesConverter (view->session()->tempo_map(), pos).to (len * paste_count); len = BeatsSamplesConverter (view->session()->tempo_map(), pos).to (Temporal::Beats::from_double (len * paste_count));
pos += view->editor ().get_paste_offset (pos, paste_count > 0 ? 1 : 0, len); pos += view->editor ().get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
} else { } else {
pos += view->editor ().get_paste_offset (pos, paste_count, len); pos += view->editor ().get_paste_offset (pos, paste_count, len);
@ -258,7 +258,7 @@ AutomationRegionView::paste (samplepos_t pos
pos - _source_relative_time_converter.origin_b()); pos - _source_relative_time_converter.origin_b());
XMLNode& before = my_list->get_state(); XMLNode& before = my_list->get_state();
my_list->paste(*slist, model_pos, DoubleBeatsSamplesConverter (view->session()->tempo_map(), pos)); my_list->paste(*slist, model_pos, BeatsSamplesConverter (view->session()->tempo_map(), pos));
view->session()->add_command( view->session()->add_command(
new MementoCommand<ARDOUR::AutomationList>(_line->memento_command_binder(), &before, &my_list->get_state())); new MementoCommand<ARDOUR::AutomationList>(_line->memento_command_binder(), &before, &my_list->get_state()));

View file

@ -858,7 +858,7 @@ AutomationTimeAxisView::paste_one (samplepos_t pos, unsigned paste_count, float
if (parameter_is_midi (src_type)) { if (parameter_is_midi (src_type)) {
// convert length to samples (incl tempo-ramps) // convert length to samples (incl tempo-ramps)
len = DoubleBeatsSamplesConverter (_session->tempo_map(), pos).to (len * paste_count); len = BeatsSamplesConverter (_session->tempo_map(), pos).to (Temporal::Beats::from_double (len * paste_count));
pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len); pos += _editor.get_paste_offset (pos, paste_count > 0 ? 1 : 0, len);
} else { } else {
pos += _editor.get_paste_offset (pos, paste_count, len); pos += _editor.get_paste_offset (pos, paste_count, len);
@ -868,7 +868,7 @@ AutomationTimeAxisView::paste_one (samplepos_t pos, unsigned paste_count, float
double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ()); double const model_pos = _line->time_converter().from (pos - _line->time_converter().origin_b ());
XMLNode &before = alist->get_state(); XMLNode &before = alist->get_state();
alist->paste (**p, model_pos, DoubleBeatsSamplesConverter (_session->tempo_map(), pos)); alist->paste (**p, model_pos, BeatsSamplesConverter (_session->tempo_map(), pos));
_session->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state())); _session->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
return true; return true;

View file

@ -4154,16 +4154,16 @@ Editor::get_grid_type_as_beats (bool& success, samplepos_t position)
const unsigned divisions = get_grid_beat_divisions(position); const unsigned divisions = get_grid_beat_divisions(position);
if (divisions) { if (divisions) {
return Temporal::Beats(1.0 / (double)get_grid_beat_divisions(position)); return Temporal::Beats::from_double (1.0 / (double)get_grid_beat_divisions(position));
} }
switch (_grid_type) { switch (_grid_type) {
case GridTypeBeat: case GridTypeBeat:
return Temporal::Beats(4.0 / _session->tempo_map().meter_at_sample (position).note_divisor()); return Temporal::Beats::from_double (4.0 / _session->tempo_map().meter_at_sample (position).note_divisor());
case GridTypeBar: case GridTypeBar:
if (_session) { if (_session) {
const Meter& m = _session->tempo_map().meter_at_sample (position); const Meter& m = _session->tempo_map().meter_at_sample (position);
return Temporal::Beats((4.0 * m.divisions_per_bar()) / m.note_divisor()); return Temporal::Beats::from_double ((4.0 * m.divisions_per_bar()) / m.note_divisor());
} }
break; break;
default: default:

View file

@ -5935,11 +5935,11 @@ NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
} }
/** @return Current total drag x change in quarter notes */ /** @return Current total drag x change in quarter notes */
double Temporal::Beats
NoteDrag::total_dx (GdkEvent * event) const NoteDrag::total_dx (GdkEvent * event) const
{ {
if (_x_constrained) { if (_x_constrained) {
return 0; return Temporal::Beats();
} }
TempoMap& map (_editor->session()->tempo_map()); TempoMap& map (_editor->session()->tempo_map());
@ -5948,10 +5948,10 @@ NoteDrag::total_dx (GdkEvent * event) const
sampleoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x()); sampleoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x());
/* primary note time */ /* primary note time */
sampleoffset_t const n = map.sample_at_quarter_note (_region->session_relative_qn (_primary->note()->time().to_double())); sampleoffset_t const n = map.sample_at_quarter_note (_region->session_relative_qn (_primary->note()->time()));
/* primary note time in quarter notes */ /* primary note time in quarter notes */
double const n_qn = _region->session_relative_qn (_primary->note()->time().to_double()); double const n_qn = _region->session_relative_qn (_primary->note()->time());
/* new time of the primary note in session samples */ /* new time of the primary note in session samples */
sampleoffset_t st = n + dx + snap_delta (event->button.state); sampleoffset_t st = n + dx + snap_delta (event->button.state);
@ -5959,7 +5959,7 @@ NoteDrag::total_dx (GdkEvent * event) const
/* possibly snap and return corresponding delta in quarter notes */ /* possibly snap and return corresponding delta in quarter notes */
MusicSample snap (st, 0); MusicSample snap (st, 0);
_editor->snap_to_with_modifier (snap, event, RoundNearest, SnapToGrid_Unscaled); _editor->snap_to_with_modifier (snap, event, RoundNearest, SnapToGrid_Unscaled);
double ret = map.exact_qn_at_sample (snap.sample, snap.division) - n_qn - snap_delta_music (event->button.state); Temporal::Beats ret = Temporal::Beats::from_double (map.exact_qn_at_sample (snap.sample, snap.division) - n_qn - snap_delta_music (event->button.state));
/* prevent the earliest note being dragged earlier than the region's start position */ /* prevent the earliest note being dragged earlier than the region's start position */
if (_earliest + ret < _region->midi_region()->start_beats()) { if (_earliest + ret < _region->midi_region()->start_beats()) {
@ -6000,7 +6000,7 @@ NoteDrag::motion (GdkEvent * event, bool first_move)
} }
/* Total change in x and y since the start of the drag */ /* Total change in x and y since the start of the drag */
double const dx_qn = total_dx (event); Temporal::Beats const dx_qn = total_dx (event);
int8_t const dy = total_dy (); int8_t const dy = total_dy ();
/* Now work out what we have to do to the note canvas items to set this new drag delta */ /* Now work out what we have to do to the note canvas items to set this new drag delta */
@ -6690,7 +6690,7 @@ HitCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
} }
const samplepos_t start = map.sample_at_quarter_note (eqaf) - _region_view->region()->position(); const samplepos_t start = map.sample_at_quarter_note (eqaf) - _region_view->region()->position();
Temporal::Beats length = Temporal::Beats(1.0 / 32.0); /* 1/32 beat = 1/128 note */ Temporal::Beats length = Temporal::Beats::from_double (1.0 / 32.0); /* 1/32 beat = 1/128 note */
_editor->begin_reversible_command (_("Create Hit")); _editor->begin_reversible_command (_("Create Hit"));
_region_view->clear_note_selection(); _region_view->clear_note_selection();

View file

@ -597,7 +597,7 @@ public:
private: private:
double total_dx (GdkEvent * event) const; // total movement in quarter notes Temporal::Beats total_dx (GdkEvent * event) const; // total movement in quarter notes
int8_t total_dy () const; int8_t total_dy () const;
MidiRegionView* _region; MidiRegionView* _region;

View file

@ -4450,7 +4450,7 @@ Editor::cut_copy_points (Editing::CutCopyOp op, Temporal::Beats earliest, bool m
lists[al].copy->fast_simple_add ((*ctrl_evt)->when, (*ctrl_evt)->value); lists[al].copy->fast_simple_add ((*ctrl_evt)->when, (*ctrl_evt)->value);
if (midi) { if (midi) {
/* Update earliest MIDI start time in beats */ /* Update earliest MIDI start time in beats */
earliest = std::min(earliest, Temporal::Beats((*ctrl_evt)->when)); earliest = std::min(earliest, Temporal::Beats::from_double ((*ctrl_evt)->when));
} else { } else {
/* Update earliest session start time in samples */ /* Update earliest session start time in samples */
start.sample = std::min(start.sample, (*sel_point)->line().session_position(ctrl_evt)); start.sample = std::min(start.sample, (*sel_point)->line().session_position(ctrl_evt));
@ -4470,7 +4470,9 @@ Editor::cut_copy_points (Editing::CutCopyOp op, Temporal::Beats earliest, bool m
snap_to(start, RoundDownMaybe); snap_to(start, RoundDownMaybe);
} }
const double line_offset = midi ? earliest.to_double() : start.sample; /* XXX NUTEMPO BROKEN FOR MIDI */
//const double line_offset = midi ? earliest.to_double() : start.sample;
const double line_offset = start.sample;
for (Lists::iterator i = lists.begin(); i != lists.end(); ++i) { for (Lists::iterator i = lists.begin(); i != lists.end(); ++i) {
/* Correct this copy list so that it is relative to the earliest /* Correct this copy list so that it is relative to the earliest
start time, so relative ordering between points is preserved start time, so relative ordering between points is preserved
@ -5700,7 +5702,7 @@ Editor::apply_midi_note_edit_op_to_region (MidiOperator& op, MidiRegionView& mrv
vector<Evoral::Sequence<Temporal::Beats>::Notes> v; vector<Evoral::Sequence<Temporal::Beats>::Notes> v;
v.push_back (selected); v.push_back (selected);
Temporal::Beats pos_beats = Temporal::Beats (mrv.midi_region()->beat()) - mrv.midi_region()->start_beats(); Temporal::Beats pos_beats = Temporal::Beats::from_double (mrv.midi_region()->beat() - mrv.midi_region()->start_beats());
return op (mrv.midi_region()->model(), pos_beats, v); return op (mrv.midi_region()->model(), pos_beats, v);
} }

View file

@ -23,7 +23,6 @@ using namespace ARDOUR;
MidiCutBuffer::MidiCutBuffer (Session* s) MidiCutBuffer::MidiCutBuffer (Session* s)
: AutomatableSequence<Temporal::Beats> (*s) : AutomatableSequence<Temporal::Beats> (*s)
, _origin (0)
{ {
} }

View file

@ -293,7 +293,7 @@ MidiListEditor::scroll_event (GdkEventScroll* ev)
switch (prop) { switch (prop) {
case MidiModel::NoteDiffCommand::StartTime: case MidiModel::NoteDiffCommand::StartTime:
if (note->time() + fdelta >= 0) { if (note->time() + fdelta >= Temporal::Beats()) {
cmd->change (note, prop, note->time() + fdelta); cmd->change (note, prop, note->time() + fdelta);
} else { } else {
cmd->change (note, prop, Temporal::Beats()); cmd->change (note, prop, Temporal::Beats());
@ -303,11 +303,10 @@ MidiListEditor::scroll_event (GdkEventScroll* ev)
cmd->change (note, prop, (uint8_t) (note->velocity() + idelta)); cmd->change (note, prop, (uint8_t) (note->velocity() + idelta));
break; break;
case MidiModel::NoteDiffCommand::Length: case MidiModel::NoteDiffCommand::Length:
if (note->length().to_double() + fdelta >= if (note->length() + fdelta >= Temporal::Beats::one_tick()) {
Temporal::Beats::tick().to_double()) {
cmd->change (note, prop, note->length() + fdelta); cmd->change (note, prop, note->length() + fdelta);
} else { } else {
cmd->change (note, prop, Temporal::Beats::tick()); cmd->change (note, prop, Temporal::Beats::one_tick());
} }
break; break;
case MidiModel::NoteDiffCommand::Channel: case MidiModel::NoteDiffCommand::Channel:
@ -336,7 +335,7 @@ MidiListEditor::scroll_event (GdkEventScroll* ev)
switch (prop) { switch (prop) {
case MidiModel::NoteDiffCommand::StartTime: case MidiModel::NoteDiffCommand::StartTime:
if (note->time() + fdelta >= 0) { if (note->time() + fdelta >= Temporal::Beats()) {
cmd->change (note, prop, note->time() + fdelta); cmd->change (note, prop, note->time() + fdelta);
} else { } else {
cmd->change (note, prop, Temporal::Beats()); cmd->change (note, prop, Temporal::Beats());
@ -346,11 +345,10 @@ MidiListEditor::scroll_event (GdkEventScroll* ev)
cmd->change (note, prop, (uint8_t) (note->velocity() + idelta)); cmd->change (note, prop, (uint8_t) (note->velocity() + idelta));
break; break;
case MidiModel::NoteDiffCommand::Length: case MidiModel::NoteDiffCommand::Length:
if (note->length() + fdelta >= if (note->length() + fdelta >= Temporal::Beats::one_tick()) {
Temporal::Beats::tick().to_double()) {
cmd->change (note, prop, note->length() + fdelta); cmd->change (note, prop, note->length() + fdelta);
} else { } else {
cmd->change (note, prop, Temporal::Beats::tick()); cmd->change (note, prop, Temporal::Beats::one_tick());
} }
break; break;
case MidiModel::NoteDiffCommand::Channel: case MidiModel::NoteDiffCommand::Channel:
@ -593,7 +591,7 @@ MidiListEditor::edited (const std::string& path, const std::string& text)
int ival; int ival;
bool apply = false; bool apply = false;
int idelta = 0; int idelta = 0;
double fdelta = 0; Temporal::Beats delta;
char const * opname; char const * opname;
switch (edit_column) { switch (edit_column) {
case 0: // start case 0: // start
@ -696,7 +694,7 @@ MidiListEditor::edited (const std::string& path, const std::string& text)
} }
if (fval > 0.0) { if (fval > 0.0) {
fdelta = fval - note->length().to_double(); delta = fval - note->length();
prop = MidiModel::NoteDiffCommand::Length; prop = MidiModel::NoteDiffCommand::Length;
opname = _("change note length"); opname = _("change note length");
apply = true; apply = true;
@ -724,7 +722,7 @@ MidiListEditor::edited (const std::string& path, const std::string& text)
cmd->change (note, prop, (uint8_t) (note->velocity() + idelta)); cmd->change (note, prop, (uint8_t) (note->velocity() + idelta));
break; break;
case MidiModel::NoteDiffCommand::Length: case MidiModel::NoteDiffCommand::Length:
cmd->change (note, prop, note->length() + fdelta); cmd->change (note, prop, note->length() + delta);
break; break;
case MidiModel::NoteDiffCommand::Channel: case MidiModel::NoteDiffCommand::Channel:
cmd->change (note, prop, (uint8_t) (note->channel() + idelta)); cmd->change (note, prop, (uint8_t) (note->channel() + idelta));

View file

@ -110,16 +110,15 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Container* parent,
: RegionView (parent, tv, r, spu, basic_color) : RegionView (parent, tv, r, spu, basic_color)
, _current_range_min(0) , _current_range_min(0)
, _current_range_max(0) , _current_range_max(0)
, _region_relative_time_converter(r->session().tempo_map(), r->position()) , _region_relative_time_converter(r->session().tempo_map(), Temporal::Beats::from_double (r->position()))
, _source_relative_time_converter(r->session().tempo_map(), r->position() - r->start()) , _source_relative_time_converter(r->session().tempo_map(), Temporal::Beats::from_double (r->position() - r->start()))
, _region_relative_time_converter_double(r->session().tempo_map(), r->position()) , _region_relative_time_converter_double(r->session().tempo_map(), Temporal::Beats::from_double (r->position()))
, _active_notes(0) , _active_notes(0)
, _note_group (new ArdourCanvas::Container (group)) , _note_group (new ArdourCanvas::Container (group))
, _note_diff_command (0) , _note_diff_command (0)
, _ghost_note(0) , _ghost_note(0)
, _step_edit_cursor (0) , _step_edit_cursor (0)
, _step_edit_cursor_width (1.0) , _step_edit_cursor_width (1, 0)
, _step_edit_cursor_position (0.0)
, _channel_selection_scoped_note (0) , _channel_selection_scoped_note (0)
, _mouse_state(None) , _mouse_state(None)
, _pressed_button(0) , _pressed_button(0)
@ -164,8 +163,7 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Container* parent,
, _note_diff_command (0) , _note_diff_command (0)
, _ghost_note(0) , _ghost_note(0)
, _step_edit_cursor (0) , _step_edit_cursor (0)
, _step_edit_cursor_width (1.0) , _step_edit_cursor_width (1,0)
, _step_edit_cursor_position (0.0)
, _channel_selection_scoped_note (0) , _channel_selection_scoped_note (0)
, _mouse_state(None) , _mouse_state(None)
, _pressed_button(0) , _pressed_button(0)
@ -219,8 +217,7 @@ MidiRegionView::MidiRegionView (const MidiRegionView& other)
, _note_diff_command (0) , _note_diff_command (0)
, _ghost_note(0) , _ghost_note(0)
, _step_edit_cursor (0) , _step_edit_cursor (0)
, _step_edit_cursor_width (1.0) , _step_edit_cursor_width (1,0)
, _step_edit_cursor_position (0.0)
, _channel_selection_scoped_note (0) , _channel_selection_scoped_note (0)
, _mouse_state(None) , _mouse_state(None)
, _pressed_button(0) , _pressed_button(0)
@ -249,8 +246,7 @@ MidiRegionView::MidiRegionView (const MidiRegionView& other, boost::shared_ptr<M
, _note_diff_command (0) , _note_diff_command (0)
, _ghost_note(0) , _ghost_note(0)
, _step_edit_cursor (0) , _step_edit_cursor (0)
, _step_edit_cursor_width (1.0) , _step_edit_cursor_width (1,0)
, _step_edit_cursor_position (0.0)
, _channel_selection_scoped_note (0) , _channel_selection_scoped_note (0)
, _mouse_state(None) , _mouse_state(None)
, _pressed_button(0) , _pressed_button(0)
@ -1635,8 +1631,8 @@ MidiRegionView::note_in_region_range (const boost::shared_ptr<NoteType> note, bo
const boost::shared_ptr<ARDOUR::MidiRegion> midi_reg = midi_region(); const boost::shared_ptr<ARDOUR::MidiRegion> midi_reg = midi_region();
/* must compare double explicitly as Beats::operator< rounds to ppqn */ /* must compare double explicitly as Beats::operator< rounds to ppqn */
const bool outside = (note->time().to_double() < midi_reg->start_beats() || const bool outside = (note->time() < midi_reg->start_beats() ||
note->time().to_double() >= midi_reg->start_beats() + midi_reg->length_beats()); note->time() >= midi_reg->start_beats() + midi_reg->length_beats());
visible = (note->note() >= _current_range_min) && visible = (note->note() >= _current_range_min) &&
(note->note() <= _current_range_max); (note->note() <= _current_range_max);
@ -1668,7 +1664,7 @@ MidiRegionView::update_sustained (Note* ev, bool update_ghost_regions)
boost::shared_ptr<NoteType> note = ev->note(); boost::shared_ptr<NoteType> note = ev->note();
const double session_source_start = _region->quarter_note() - mr->start_beats(); const double session_source_start = _region->quarter_note() - mr->start_beats();
const samplepos_t note_start_samples = map.sample_at_quarter_note (note->time().to_double() + session_source_start) - _region->position(); const samplepos_t note_start_samples = map.sample_at_quarter_note (note->time() + session_source_start) - _region->position();
const double x0 = max (0.,trackview.editor().sample_to_pixel (note_start_samples)); const double x0 = max (0.,trackview.editor().sample_to_pixel (note_start_samples));
double x1; double x1;
@ -1685,7 +1681,7 @@ MidiRegionView::update_sustained (Note* ev, bool update_ghost_regions)
/* normal note */ /* normal note */
double note_end_time = note->end_time().to_double(); Temporal::Beats note_end_time = note->end_time();
if (note->end_time() > mr->start_beats() + mr->length_beats()) { if (note->end_time() > mr->start_beats() + mr->length_beats()) {
note_end_time = mr->start_beats() + mr->length_beats(); note_end_time = mr->start_beats() + mr->length_beats();
@ -1740,7 +1736,7 @@ MidiRegionView::update_hit (Hit* ev, bool update_ghost_regions)
{ {
boost::shared_ptr<NoteType> note = ev->note(); boost::shared_ptr<NoteType> note = ev->note();
const double note_time_qn = note->time().to_double() + (_region->quarter_note() - midi_region()->start_beats()); const double note_time_qn = note->time() + (_region->quarter_note() - midi_region()->start_beats());
const samplepos_t note_start_samples = trackview.session()->tempo_map().sample_at_quarter_note (note_time_qn) - _region->position(); const samplepos_t note_start_samples = trackview.session()->tempo_map().sample_at_quarter_note (note_time_qn) - _region->position();
const double x = trackview.editor().sample_to_pixel(note_start_samples); const double x = trackview.editor().sample_to_pixel(note_start_samples);
@ -2548,7 +2544,7 @@ MidiRegionView::move_selection(double dx_qn, double dy, double cumulative_dy)
if (n->note()->time() == earliest) { if (n->note()->time() == earliest) {
to_play.push_back (n->note()); to_play.push_back (n->note());
} }
double const note_time_qn = session_relative_qn (n->note()->time().to_double()); double const note_time_qn = session_relative_qn (n->note()->time());
double dx = 0.0; double dx = 0.0;
if (midi_view()->note_mode() == Sustained) { if (midi_view()->note_mode() == Sustained) {
dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn)) dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn))
@ -2567,8 +2563,7 @@ MidiRegionView::move_selection(double dx_qn, double dy, double cumulative_dy)
/* update length */ /* update length */
if (midi_view()->note_mode() == Sustained) { if (midi_view()->note_mode() == Sustained) {
Note* sus = dynamic_cast<Note*> (*i); Note* sus = dynamic_cast<Note*> (*i);
double const len_dx = editor->sample_to_pixel_unrounded ( double const len_dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn + n->note()->length()));
tmap.sample_at_quarter_note (note_time_qn + dx_qn + n->note()->length().to_double()));
sus->set_x1 (n->item()->canvas_to_item (ArdourCanvas::Duple (len_dx, 0)).x); sus->set_x1 (n->item()->canvas_to_item (ArdourCanvas::Duple (len_dx, 0)).x);
} }
@ -2632,7 +2627,7 @@ MidiRegionView::copy_selection (NoteBase* primary)
} }
void void
MidiRegionView::move_copies (double dx_qn, double dy, double cumulative_dy) MidiRegionView::move_copies (Temporal::Beats const & dx_qn, double dy, double cumulative_dy)
{ {
typedef vector<boost::shared_ptr<NoteType> > PossibleChord; typedef vector<boost::shared_ptr<NoteType> > PossibleChord;
Editor* editor = dynamic_cast<Editor*> (&trackview.editor()); Editor* editor = dynamic_cast<Editor*> (&trackview.editor());
@ -2645,7 +2640,7 @@ MidiRegionView::move_copies (double dx_qn, double dy, double cumulative_dy)
if (n->note()->time() == earliest) { if (n->note()->time() == earliest) {
to_play.push_back (n->note()); to_play.push_back (n->note());
} }
double const note_time_qn = session_relative_qn (n->note()->time().to_double()); Temporal::Beats const note_time_qn = Temporal::Beats::from_double (session_relative_qn (n->note()->time()));
double dx = 0.0; double dx = 0.0;
if (midi_view()->note_mode() == Sustained) { if (midi_view()->note_mode() == Sustained) {
dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn)) dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn))
@ -2662,8 +2657,7 @@ MidiRegionView::move_copies (double dx_qn, double dy, double cumulative_dy)
if (midi_view()->note_mode() == Sustained) { if (midi_view()->note_mode() == Sustained) {
Note* sus = dynamic_cast<Note*> (*i); Note* sus = dynamic_cast<Note*> (*i);
double const len_dx = editor->sample_to_pixel_unrounded ( double const len_dx = editor->sample_to_pixel_unrounded (tmap.sample_at_quarter_note (note_time_qn + dx_qn + n->note()->length()));
tmap.sample_at_quarter_note (note_time_qn + dx_qn + n->note()->length().to_double()));
sus->set_x1 (n->item()->canvas_to_item (ArdourCanvas::Duple (len_dx, 0)).x); sus->set_x1 (n->item()->canvas_to_item (ArdourCanvas::Duple (len_dx, 0)).x);
} }
@ -2693,7 +2687,7 @@ MidiRegionView::move_copies (double dx_qn, double dy, double cumulative_dy)
} }
void void
MidiRegionView::note_dropped(NoteBase *, double d_qn, int8_t dnote, bool copy) MidiRegionView::note_dropped(NoteBase *, Temporal::Beats const & d_qn, int8_t dnote, bool copy)
{ {
uint8_t lowest_note_in_selection = 127; uint8_t lowest_note_in_selection = 127;
uint8_t highest_note_in_selection = 0; uint8_t highest_note_in_selection = 0;
@ -2727,9 +2721,9 @@ MidiRegionView::note_dropped(NoteBase *, double d_qn, int8_t dnote, bool copy)
for (Selection::iterator i = _selection.begin(); i != _selection.end() ; ++i) { for (Selection::iterator i = _selection.begin(); i != _selection.end() ; ++i) {
Temporal::Beats new_time = Temporal::Beats ((*i)->note()->time().to_double() + d_qn); Temporal::Beats new_time = Temporal::Beats ((*i)->note()->time() + d_qn);
if (new_time < 0) { if (new_time < Temporal::Beats()) {
continue; continue;
} }
@ -2766,9 +2760,9 @@ MidiRegionView::note_dropped(NoteBase *, double d_qn, int8_t dnote, bool copy)
for (CopyDragEvents::iterator i = _copy_drag_events.begin(); i != _copy_drag_events.end() ; ++i) { for (CopyDragEvents::iterator i = _copy_drag_events.begin(); i != _copy_drag_events.end() ; ++i) {
/* update time */ /* update time */
Temporal::Beats new_time = Temporal::Beats ((*i)->note()->time().to_double() + d_qn); Temporal::Beats new_time = (*i)->note()->time() + d_qn;
if (new_time < 0) { if (new_time < Temporal::Beats()) {
continue; continue;
} }
@ -3005,9 +2999,7 @@ MidiRegionView::update_resizing (NoteBase* primary, bool at_front, double delta_
snapped_x = trackview.editor ().pixel_to_sample (current_x); snapped_x = trackview.editor ().pixel_to_sample (current_x);
} }
const Temporal::Beats beats = Temporal::Beats (tmap.exact_beat_at_sample (snapped_x + midi_region()->position(), divisions) const Temporal::Beats beats = Temporal::Beats::from_double (tmap.exact_beat_at_sample (snapped_x + midi_region()->position(), divisions) - midi_region()->beat()) + midi_region()->start_beats();
- midi_region()->beat())
+ midi_region()->start_beats();
Temporal::Beats len = Temporal::Beats(); Temporal::Beats len = Temporal::Beats();
@ -3026,7 +3018,8 @@ MidiRegionView::update_resizing (NoteBase* primary, bool at_front, double delta_
len = std::max (Temporal::Beats (0,1), len); len = std::max (Temporal::Beats (0,1), len);
char buf[16]; char buf[16];
snprintf (buf, sizeof (buf), "%.3g beats", len.to_double()); /* represent as float frac to help out the user */
snprintf (buf, sizeof (buf), "%.3g beats", len.get_beats() + (len.get_ticks()/(double)Temporal::ticks_per_beat));
show_verbose_cursor (buf, 0, 0); show_verbose_cursor (buf, 0, 0);
cursor_set = true; cursor_set = true;
@ -3106,7 +3099,7 @@ MidiRegionView::commit_resizing (NoteBase* primary, bool at_front, double delta_
/* and then to beats */ /* and then to beats */
const double e_qaf = tmap.exact_qn_at_sample (current_fr + midi_region()->position(), divisions); const double e_qaf = tmap.exact_qn_at_sample (current_fr + midi_region()->position(), divisions);
const double quarter_note_start = _region->quarter_note() - midi_region()->start_beats(); const double quarter_note_start = _region->quarter_note() - midi_region()->start_beats();
const Temporal::Beats x_beats = Temporal::Beats (e_qaf - quarter_note_start); const Temporal::Beats x_beats = Temporal::Beats::from_double (e_qaf - quarter_note_start);
if (at_front && x_beats < canvas_note->note()->end_time()) { if (at_front && x_beats < canvas_note->note()->end_time()) {
const Temporal::Beats new_start = x_beats - (sign * snap_delta_beats); const Temporal::Beats new_start = x_beats - (sign * snap_delta_beats);
@ -3192,7 +3185,7 @@ MidiRegionView::trim_note (NoteBase* event, Temporal::Beats front_delta, Tempora
*/ */
if (!!front_delta) { if (!!front_delta) {
if (front_delta < 0) { if (front_delta < std::numeric_limits<Temporal::Beats>::lowest()) {
if (event->note()->time() < -front_delta) { if (event->note()->time() < -front_delta) {
new_start = Temporal::Beats(); new_start = Temporal::Beats();
@ -3225,7 +3218,7 @@ MidiRegionView::trim_note (NoteBase* event, Temporal::Beats front_delta, Tempora
if (!!end_delta) { if (!!end_delta) {
bool can_change = true; bool can_change = true;
if (end_delta < 0) { if (end_delta < Temporal::Beats()) {
if (event->note()->length() < -end_delta) { if (event->note()->length() < -end_delta) {
can_change = false; can_change = false;
} }
@ -3407,7 +3400,7 @@ MidiRegionView::change_note_lengths (bool fine, bool shorter, Temporal::Beats de
{ {
if (!delta) { if (!delta) {
if (fine) { if (fine) {
delta = Temporal::Beats(1.0/128.0); delta = Temporal::Beats::ticks (Temporal::ticks_per_beat / 128);
} else { } else {
/* grab the current grid distance */ /* grab the current grid distance */
delta = get_grid_beats(_region->position()); delta = get_grid_beats(_region->position());
@ -3962,7 +3955,11 @@ MidiRegionView::update_ghost_note (double x, double y, uint32_t state)
} }
/* ghost note may have been snapped before region */ /* ghost note may have been snapped before region */
<<<<<<< HEAD
if (snapped_beats.to_double() < 0.0) { if (snapped_beats.to_double() < 0.0) {
=======
if (_ghost_note && snapped_beats < Temporal::Beats()) {
>>>>>>> 5ec97dc85c (updated Temporal::Beats ... GUI edition)
_ghost_note->hide(); _ghost_note->hide();
return; return;
} }
@ -4326,8 +4323,7 @@ MidiRegionView::get_velocity_for_add (MidiModel::TimeType time) const
MidiModel::Notes::const_iterator n = m; MidiModel::Notes::const_iterator n = m;
--n; --n;
const double frac = ((time - (*n)->time()).to_double() / const double frac = (time - (*n)->time()) / ((*m)->time() - (*n)->time());
((*m)->time() - (*n)->time()).to_double());
return (*n)->velocity() + (frac * ((*m)->velocity() - (*n)->velocity())); return (*n)->velocity() + (frac * ((*m)->velocity() - (*n)->velocity()));
} }
@ -4344,19 +4340,19 @@ MidiRegionView::snap_sample_to_grid_underneath (samplepos_t p, int32_t divisions
double eqaf = map.exact_qn_at_sample (p + _region->position(), divisions); double eqaf = map.exact_qn_at_sample (p + _region->position(), divisions);
if (divisions != 0 && shift_snap) { if (divisions != 0 && shift_snap) {
const double qaf = map.quarter_note_at_sample (p + _region->position()); const Temporal::Beats qaf = Temporal::Beats::from_double (map.quarter_note_at_sample (p + _region->position()));
/* Hack so that we always snap to the note that we are over, instead of snapping /* Hack so that we always snap to the note that we are over, instead of snapping
to the next one if we're more than halfway through the one we're over. to the next one if we're more than halfway through the one we're over.
*/ */
const Temporal::Beats grid_beats = get_grid_beats (p + _region->position()); const Temporal::Beats grid_beats = get_grid_beats (p + _region->position());
const double rem = eqaf - qaf; const double rem = eqaf - qaf;
if (rem >= 0.0) { if (rem >= 0.0) {
eqaf -= grid_beats.to_double(); eqaf -= grid_beats;
} }
} }
const double session_start_off = _region->quarter_note() - midi_region()->start_beats(); const double session_start_off = _region->quarter_note() - midi_region()->start_beats();
return Temporal::Beats (eqaf - session_start_off); return Temporal::Beats::from_double (eqaf - session_start_off);
} }
ChannelMode ChannelMode
@ -4381,7 +4377,7 @@ MidiRegionView::get_grid_beats(samplepos_t pos) const
bool success = false; bool success = false;
Temporal::Beats beats = editor.get_grid_type_as_beats (success, pos); Temporal::Beats beats = editor.get_grid_type_as_beats (success, pos);
if (!success) { if (!success) {
beats = Temporal::Beats(1); beats = Temporal::Beats (1, 0);
} }
return beats; return beats;
} }

View file

@ -211,9 +211,9 @@ public:
Temporal::Beats earliest_in_selection (); Temporal::Beats earliest_in_selection ();
void move_selection(double dx, double dy, double cumulative_dy); void move_selection(double dx, double dy, double cumulative_dy);
void note_dropped (NoteBase* ev, double d_qn, int8_t d_note, bool copy); void note_dropped (NoteBase* ev, Temporal::Beats const & d_qn, int8_t d_note, bool copy);
NoteBase* copy_selection (NoteBase* primary); NoteBase* copy_selection (NoteBase* primary);
void move_copies(double dx_qn, double dy, double cumulative_dy); void move_copies(Temporal::Beats const & dx_qn, double dy, double cumulative_dy);
void select_notes (std::list<Evoral::event_id_t>, bool allow_audition); void select_notes (std::list<Evoral::event_id_t>, bool allow_audition);
void select_matching_notes (uint8_t notenum, uint16_t channel_mask, bool add, bool extend); void select_matching_notes (uint8_t notenum, uint16_t channel_mask, bool add, bool extend);
@ -306,8 +306,8 @@ public:
return _source_relative_time_converter; return _source_relative_time_converter;
} }
ARDOUR::DoubleBeatsSamplesConverter const & region_relative_time_converter_double () const { ARDOUR::BeatsSamplesConverter const & region_relative_time_converter_double () const {
return _region_relative_time_converter_double; return _region_relative_time_converter;
} }
double session_relative_qn (double qn) const; double session_relative_qn (double qn) const;
@ -485,7 +485,7 @@ public:
ARDOUR::BeatsSamplesConverter _region_relative_time_converter; ARDOUR::BeatsSamplesConverter _region_relative_time_converter;
ARDOUR::BeatsSamplesConverter _source_relative_time_converter; ARDOUR::BeatsSamplesConverter _source_relative_time_converter;
ARDOUR::DoubleBeatsSamplesConverter _region_relative_time_converter_double; ARDOUR::BeatsSamplesConverter _region_relative_time_converter_double;
boost::shared_ptr<ARDOUR::MidiModel> _model; boost::shared_ptr<ARDOUR::MidiModel> _model;
Events _events; Events _events;

View file

@ -189,8 +189,8 @@ QuantizeDialog::strength () const
return strength_adjustment.get_value (); return strength_adjustment.get_value ();
} }
float Temporal::Beats
QuantizeDialog::threshold () const QuantizeDialog::threshold () const
{ {
return threshold_adjustment.get_value (); return Temporal::Beats::from_double (threshold_adjustment.get_value ());
} }

View file

@ -27,6 +27,8 @@
#include <gtkmm/checkbutton.h> #include <gtkmm/checkbutton.h>
#include <gtkmm/spinbutton.h> #include <gtkmm/spinbutton.h>
#include "temporal/beats.h"
#include "ardour/types.h" #include "ardour/types.h"
#include "ardour_dialog.h" #include "ardour_dialog.h"
@ -49,7 +51,7 @@ public:
bool snap_start() const { return snap_start_button.get_active(); } bool snap_start() const { return snap_start_button.get_active(); }
bool snap_end() const { return snap_end_button.get_active(); } bool snap_end() const { return snap_end_button.get_active(); }
float strength() const; float strength() const;
float threshold () const; Temporal::Beats threshold () const;
float swing () const; float swing () const;
private: private:

View file

@ -443,7 +443,7 @@ StepEditor::region_removed (boost::weak_ptr<Region> wr)
step_edit_region.reset(); step_edit_region.reset();
step_edit_region_view = 0; step_edit_region_view = 0;
// force a recompute of the insert position // force a recompute of the insert position
step_edit_beat_pos = Temporal::Beats(-1); step_edit_beat_pos = Temporal::Beats::from_double (-1);
} }
} }

View file

@ -62,7 +62,7 @@ StepEntry::instance()
StepEntry::StepEntry () StepEntry::StepEntry ()
: ArdourWindow (string()) : ArdourWindow (string())
, _current_note_length (1.0) , _current_note_length (1, 0)
, _current_note_velocity (64) , _current_note_velocity (64)
, triplet_button ("3") , triplet_button ("3")
, dot_adjustment (0.0, 0.0, 3.0, 1.0, 1.0) , dot_adjustment (0.0, 0.0, 3.0, 1.0, 1.0)
@ -549,7 +549,7 @@ StepEntry::note_length ()
base_time *= 1 + ((dots - 1.0)/dots); base_time *= 1 + ((dots - 1.0)/dots);
} }
return Temporal::Beats(base_time); return Temporal::Beats::from_double (base_time);
} }
uint8_t uint8_t