mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-08 15:54:57 +01:00
Midi pencil undo (not yet serializable).
Formatting fixes for session.h (ie kill more of those damned 8 space expanded tabs). git-svn-id: svn://localhost/ardour2/trunk@2135 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
37c74810d2
commit
f542fa693c
7 changed files with 210 additions and 54 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2006 Paul Davis
|
Copyright (C) 2001-2007 Paul Davis
|
||||||
|
Author: Dave Robillard
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|
@ -24,6 +25,8 @@
|
||||||
|
|
||||||
#include <gtkmm2ext/gtk_ui.h>
|
#include <gtkmm2ext/gtk_ui.h>
|
||||||
|
|
||||||
|
#include <sigc++/signal.h>
|
||||||
|
|
||||||
#include <ardour/playlist.h>
|
#include <ardour/playlist.h>
|
||||||
#include <ardour/tempo.h>
|
#include <ardour/tempo.h>
|
||||||
#include <ardour/midi_region.h>
|
#include <ardour/midi_region.h>
|
||||||
|
|
@ -96,6 +99,9 @@ MidiRegionView::init (Gdk::Color& basic_color, bool wfd)
|
||||||
display_events();
|
display_events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
midi_region()->midi_source(0)->model()->ContentsChanged.connect(sigc::mem_fun(
|
||||||
|
this, &MidiRegionView::redisplay_model));
|
||||||
|
|
||||||
group->signal_event().connect (mem_fun (this, &MidiRegionView::canvas_event));
|
group->signal_event().connect (mem_fun (this, &MidiRegionView::canvas_event));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,13 +133,15 @@ MidiRegionView::canvas_event(GdkEvent* ev)
|
||||||
const Tempo& t = trackview.session().tempo_map().tempo_at(stamp);
|
const Tempo& t = trackview.session().tempo_map().tempo_at(stamp);
|
||||||
double dur = m.frames_per_bar(t, trackview.session().frame_rate()) / m.beats_per_bar();
|
double dur = m.frames_per_bar(t, trackview.session().frame_rate()) / m.beats_per_bar();
|
||||||
|
|
||||||
|
MidiModel* model = midi_region()->midi_source(0)->model();
|
||||||
|
|
||||||
// Add a 1 beat long note (for now)
|
// Add a 1 beat long note (for now)
|
||||||
const MidiModel::Note new_note(stamp, dur, (uint8_t)note, 0x40);
|
const MidiModel::Note new_note(stamp, dur, (uint8_t)note, 0x40);
|
||||||
|
|
||||||
MidiModel::Notes& notes = midi_region()->midi_source(0)->model()->notes();
|
model->begin_command();
|
||||||
MidiModel::Notes::iterator i = upper_bound(notes.begin(), notes.end(), new_note,
|
model->add_note(new_note);
|
||||||
MidiModel::NoteTimeComparator());
|
model->finish_command();
|
||||||
notes.insert(i, new_note);
|
|
||||||
view->update_bounds(new_note.note);
|
view->update_bounds(new_note.note);
|
||||||
|
|
||||||
add_note(new_note);
|
add_note(new_note);
|
||||||
|
|
@ -144,6 +152,14 @@ MidiRegionView::canvas_event(GdkEvent* ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MidiRegionView::redisplay_model()
|
||||||
|
{
|
||||||
|
clear_events();
|
||||||
|
display_events();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MidiRegionView::clear_events()
|
MidiRegionView::clear_events()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
|
|
||||||
#include <libgnomecanvasmm.h>
|
#include <libgnomecanvasmm.h>
|
||||||
#include <libgnomecanvasmm/polygon.h>
|
#include <libgnomecanvasmm/polygon.h>
|
||||||
#include <sigc++/signal.h>
|
|
||||||
#include <ardour/midi_region.h>
|
#include <ardour/midi_region.h>
|
||||||
#include <ardour/midi_model.h>
|
#include <ardour/midi_model.h>
|
||||||
#include <ardour/types.h>
|
#include <ardour/types.h>
|
||||||
|
|
@ -94,6 +93,7 @@ class MidiRegionView : public RegionView
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
void redisplay_model();
|
||||||
void display_events();
|
void display_events();
|
||||||
void clear_events();
|
void clear_events();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,15 @@
|
||||||
#define __ardour_midi_model_h__
|
#define __ardour_midi_model_h__
|
||||||
|
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
|
#include <pbd/command.h>
|
||||||
#include <ardour/types.h>
|
#include <ardour/types.h>
|
||||||
#include <ardour/midi_buffer.h>
|
#include <ardour/midi_buffer.h>
|
||||||
|
|
||||||
namespace ARDOUR {
|
namespace ARDOUR {
|
||||||
|
|
||||||
|
class Session;
|
||||||
|
|
||||||
|
|
||||||
/** This is a slightly higher level (than MidiBuffer) model of MIDI note data.
|
/** This is a slightly higher level (than MidiBuffer) model of MIDI note data.
|
||||||
* Currently it only represents note data, which is represented as complete
|
* Currently it only represents note data, which is represented as complete
|
||||||
* note events (ie with a start time and a duration) rather than separate
|
* note events (ie with a start time and a duration) rather than separate
|
||||||
|
|
@ -39,13 +43,16 @@ public:
|
||||||
Note(double s=0, double d=0, uint8_t n=0, uint8_t v=0)
|
Note(double s=0, double d=0, uint8_t n=0, uint8_t v=0)
|
||||||
: start(s), duration(d), note(n), velocity(v) {}
|
: start(s), duration(d), note(n), velocity(v) {}
|
||||||
|
|
||||||
|
inline bool operator==(const Note& other)
|
||||||
|
{ return start == other.start && note == other.note; }
|
||||||
|
|
||||||
double start;
|
double start;
|
||||||
double duration;
|
double duration;
|
||||||
uint8_t note;
|
uint8_t note;
|
||||||
uint8_t velocity;
|
uint8_t velocity;
|
||||||
};
|
};
|
||||||
|
|
||||||
MidiModel(size_t size=0);
|
MidiModel(Session& s, size_t size=0);
|
||||||
|
|
||||||
void clear() { _notes.clear(); }
|
void clear() { _notes.clear(); }
|
||||||
|
|
||||||
|
|
@ -73,13 +80,47 @@ public:
|
||||||
inline Notes& notes() { return _notes; }
|
inline Notes& notes() { return _notes; }
|
||||||
inline const Notes& notes() const { return _notes; }
|
inline const Notes& notes() const { return _notes; }
|
||||||
|
|
||||||
|
void begin_command();
|
||||||
|
Command* current_command() { return _command; }
|
||||||
|
void finish_command();
|
||||||
|
|
||||||
|
// Commands
|
||||||
|
void add_note(const Note& note);
|
||||||
|
void remove_note(const Note& note);
|
||||||
|
|
||||||
|
sigc::signal<void> ContentsChanged;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
class MidiEditCommand : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MidiEditCommand (MidiModel& m) : _model(m) {}
|
||||||
|
//MidiEditCommand (MidiModel&, const XMLNode& node);
|
||||||
|
|
||||||
|
void operator()();
|
||||||
|
void undo();
|
||||||
|
|
||||||
|
/*int set_state (const XMLNode&);
|
||||||
|
XMLNode& get_state ();*/
|
||||||
|
|
||||||
|
void add_note(const Note& note);
|
||||||
|
void remove_note(const Note& note);
|
||||||
|
|
||||||
|
private:
|
||||||
|
MidiModel& _model;
|
||||||
|
std::list<Note> _added_notes;
|
||||||
|
std::list<Note> _removed_notes;
|
||||||
|
};
|
||||||
|
|
||||||
void append_note_on(double time, uint8_t note, uint8_t velocity);
|
void append_note_on(double time, uint8_t note, uint8_t velocity);
|
||||||
void append_note_off(double time, uint8_t note);
|
void append_note_off(double time, uint8_t note);
|
||||||
|
|
||||||
|
Session& _session;
|
||||||
|
|
||||||
Notes _notes;
|
Notes _notes;
|
||||||
Notes _write_notes;
|
Notes _write_notes;
|
||||||
|
|
||||||
|
MidiEditCommand* _command; ///< In-progress command
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ARDOUR */
|
} /* namespace ARDOUR */
|
||||||
|
|
|
||||||
|
|
@ -673,8 +673,9 @@ class Session : public PBD::StatefulDestructible
|
||||||
|
|
||||||
/* flattening stuff */
|
/* flattening stuff */
|
||||||
|
|
||||||
int write_one_audio_track (AudioTrack&, nframes_t start, nframes_t cnt, bool overwrite, vector<boost::shared_ptr<Source> >&,
|
int write_one_audio_track (AudioTrack&, nframes_t start, nframes_t cnt, bool overwrite,
|
||||||
InterThreadInfo& wot);
|
vector<boost::shared_ptr<Source> >&, InterThreadInfo& wot);
|
||||||
|
|
||||||
int freeze (InterThreadInfo&);
|
int freeze (InterThreadInfo&);
|
||||||
|
|
||||||
/* session-wide solo/mute/rec-enable */
|
/* session-wide solo/mute/rec-enable */
|
||||||
|
|
@ -1112,9 +1113,9 @@ class Session : public PBD::StatefulDestructible
|
||||||
|
|
||||||
nframes_t _last_roll_location;
|
nframes_t _last_roll_location;
|
||||||
nframes_t _last_record_location;
|
nframes_t _last_record_location;
|
||||||
|
|
||||||
bool pending_locate_roll;
|
bool pending_locate_roll;
|
||||||
nframes_t pending_locate_frame;
|
nframes_t pending_locate_frame;
|
||||||
|
|
||||||
bool pending_locate_flush;
|
bool pending_locate_flush;
|
||||||
bool pending_abort;
|
bool pending_abort;
|
||||||
bool pending_auto_loop;
|
bool pending_auto_loop;
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,16 @@
|
||||||
#include <ardour/midi_model.h>
|
#include <ardour/midi_model.h>
|
||||||
#include <ardour/midi_events.h>
|
#include <ardour/midi_events.h>
|
||||||
#include <ardour/types.h>
|
#include <ardour/types.h>
|
||||||
|
#include <ardour/session.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace ARDOUR;
|
using namespace ARDOUR;
|
||||||
|
|
||||||
|
|
||||||
MidiModel::MidiModel(size_t size)
|
MidiModel::MidiModel(Session& s, size_t size)
|
||||||
: _notes(size)
|
: _session(s)
|
||||||
|
, _notes(size)
|
||||||
|
, _command(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,3 +143,98 @@ MidiModel::append_note_off(double time, uint8_t note_num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MidiModel::add_note(const Note& note)
|
||||||
|
{
|
||||||
|
Notes::iterator i = upper_bound(_notes.begin(), _notes.end(), note, NoteTimeComparator());
|
||||||
|
_notes.insert(i, note);
|
||||||
|
if (_command)
|
||||||
|
_command->add_note(note);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MidiModel::remove_note(const Note& note)
|
||||||
|
{
|
||||||
|
Notes::iterator n = find(_notes.begin(), _notes.end(), note);
|
||||||
|
if (n != _notes.end())
|
||||||
|
_notes.erase(n);
|
||||||
|
|
||||||
|
if (_command)
|
||||||
|
_command->remove_note(note);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MidiModel::begin_command()
|
||||||
|
{
|
||||||
|
assert(!_command);
|
||||||
|
_session.begin_reversible_command("midi edit");
|
||||||
|
_command = new MidiEditCommand(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MidiModel::finish_command()
|
||||||
|
{
|
||||||
|
_session.commit_reversible_command(_command);
|
||||||
|
_command = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MidiEditCommand
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MidiModel::MidiEditCommand::add_note(const Note& note)
|
||||||
|
{
|
||||||
|
//cerr << "MEC: apply" << endl;
|
||||||
|
|
||||||
|
_removed_notes.remove(note);
|
||||||
|
_added_notes.push_back(note);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MidiModel::MidiEditCommand::remove_note(const Note& note)
|
||||||
|
{
|
||||||
|
//cerr << "MEC: remove" << endl;
|
||||||
|
|
||||||
|
_added_notes.remove(note);
|
||||||
|
_removed_notes.push_back(note);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MidiModel::MidiEditCommand::operator()()
|
||||||
|
{
|
||||||
|
//cerr << "MEC: apply" << endl;
|
||||||
|
assert(!_model.current_command());
|
||||||
|
|
||||||
|
for (std::list<Note>::iterator i = _added_notes.begin(); i != _added_notes.end(); ++i)
|
||||||
|
_model.add_note(*i);
|
||||||
|
|
||||||
|
for (std::list<Note>::iterator i = _removed_notes.begin(); i != _removed_notes.end(); ++i)
|
||||||
|
_model.remove_note(*i);
|
||||||
|
|
||||||
|
_model.ContentsChanged(); /* EMIT SIGNAL */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MidiModel::MidiEditCommand::undo()
|
||||||
|
{
|
||||||
|
//cerr << "MEC: undo" << endl;
|
||||||
|
assert(!_model.current_command());
|
||||||
|
|
||||||
|
for (std::list<Note>::iterator i = _added_notes.begin(); i != _added_notes.end(); ++i)
|
||||||
|
_model.remove_note(*i);
|
||||||
|
|
||||||
|
for (std::list<Note>::iterator i = _removed_notes.begin(); i != _removed_notes.end(); ++i)
|
||||||
|
_model.add_note(*i);
|
||||||
|
|
||||||
|
_model.ContentsChanged(); /* EMIT SIGNAL */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ sigc::signal<void,MidiSource *> MidiSource::MidiSourceCreated;
|
||||||
|
|
||||||
MidiSource::MidiSource (Session& s, string name)
|
MidiSource::MidiSource (Session& s, string name)
|
||||||
: Source (s, name, DataType::MIDI)
|
: Source (s, name, DataType::MIDI)
|
||||||
, _model(new MidiModel())
|
, _model(new MidiModel(s))
|
||||||
, _model_loaded (false)
|
, _model_loaded (false)
|
||||||
{
|
{
|
||||||
_read_data_count = 0;
|
_read_data_count = 0;
|
||||||
|
|
@ -53,7 +53,7 @@ MidiSource::MidiSource (Session& s, string name)
|
||||||
|
|
||||||
MidiSource::MidiSource (Session& s, const XMLNode& node)
|
MidiSource::MidiSource (Session& s, const XMLNode& node)
|
||||||
: Source (s, node)
|
: Source (s, node)
|
||||||
, _model(new MidiModel())
|
, _model(new MidiModel(s))
|
||||||
, _model_loaded (false)
|
, _model_loaded (false)
|
||||||
{
|
{
|
||||||
_read_data_count = 0;
|
_read_data_count = 0;
|
||||||
|
|
|
||||||
|
|
@ -787,7 +787,7 @@ SMFSource::load_model(bool lock, bool force_reload)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! _model)
|
if (! _model)
|
||||||
_model = new MidiModel();
|
_model = new MidiModel(_session);
|
||||||
|
|
||||||
_model->start_write();
|
_model->start_write();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue