Fix genererally retarded and broken note range / diskstream display / etc. related things (correctly display region contents on initial session load).

git-svn-id: svn://localhost/ardour2/branches/3.0@4583 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2009-02-15 19:44:27 +00:00
parent ecaf107ed3
commit 166395c96b
16 changed files with 153 additions and 137 deletions

View file

@ -137,7 +137,8 @@ AudioStreamView::add_region_view_internal (boost::shared_ptr<Region> r, bool wai
case Normal: case Normal:
if (recording) { if (recording) {
region_view = new AudioRegionView (canvas_group, _trackview, region, region_view = new AudioRegionView (canvas_group, _trackview, region,
_samples_per_unit, region_color, recording, TimeAxisViewItem::Visibility(TimeAxisViewItem::ShowFrame | TimeAxisViewItem::HideFrameRight)); _samples_per_unit, region_color, recording, TimeAxisViewItem::Visibility(
TimeAxisViewItem::ShowFrame | TimeAxisViewItem::HideFrameRight));
} else { } else {
region_view = new AudioRegionView (canvas_group, _trackview, region, region_view = new AudioRegionView (canvas_group, _trackview, region,
_samples_per_unit, region_color); _samples_per_unit, region_color);
@ -379,16 +380,19 @@ AudioStreamView::redisplay_diskstream ()
} }
if (_trackview.is_audio_track()) { if (_trackview.is_audio_track()) {
_trackview.get_diskstream()->playlist()->foreach_region (static_cast<StreamView*>(this), &StreamView::add_region_view); _trackview.get_diskstream()->playlist()->foreach_region(
static_cast<StreamView*>(this),
&StreamView::add_region_view);
boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist>(_trackview.get_diskstream()->playlist()); boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist>(
_trackview.get_diskstream()->playlist());
if (apl) if (apl)
apl->foreach_crossfade (this, &AudioStreamView::add_crossfade); apl->foreach_crossfade (this, &AudioStreamView::add_crossfade);
} }
RegionViewList copy; RegionViewList copy;
/* Place regions */ // Build a list of region views sorted by layer, and remove invalids
for (i = region_views.begin(); i != region_views.end(); ) { for (i = region_views.begin(); i != region_views.end(); ) {
tmp = i; tmp = i;
tmp++; tmp++;
@ -402,9 +406,6 @@ AudioStreamView::redisplay_diskstream ()
(*i)->enable_display(true); (*i)->enable_display(true);
} }
/* Sort regionviews by layer so that when we call region_layered ()
the canvas layering works out (in non-stacked mode). */
if (copy.size() == 0) { if (copy.size() == 0) {
copy.push_front((*i)); copy.push_front((*i));
i = tmp; i = tmp;
@ -447,8 +448,7 @@ AudioStreamView::redisplay_diskstream ()
xi = tmpx; xi = tmpx;
} }
/* now fix layering */ // Fix canvas layering by raising each in the sorted list order
for (RegionViewList::iterator i = copy.begin(); i != copy.end(); ++i) { for (RegionViewList::iterator i = copy.begin(); i != copy.end(); ++i) {
region_layered (*i); region_layered (*i);
} }

View file

@ -41,6 +41,9 @@ public:
{ {
} }
void show() { Diamond::show(); }
void hide() { Diamond::hide(); }
double x1() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return x1; } double x1() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return x1; }
double y1() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return y1; } double y1() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return y1; }
double x2() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return x2; } double x2() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return x2; }

View file

@ -59,6 +59,8 @@ public:
virtual ~CanvasNoteEvent(); virtual ~CanvasNoteEvent();
virtual void show() = 0;
virtual void hide() = 0;
virtual bool on_event(GdkEvent* ev); virtual bool on_event(GdkEvent* ev);
bool selected() const { return _selected; } bool selected() const { return _selected; }
@ -71,10 +73,10 @@ public:
void show_velocity(); void show_velocity();
void hide_velocity(); void hide_velocity();
/** /** Channel changed for this specific event */
* This slot is called, when a new channel is selected for the single event
* */
void on_channel_change(uint8_t channel); void on_channel_change(uint8_t channel);
/** Channel selection changed */
void on_channel_selection_change(uint16_t selection); void on_channel_selection_change(uint16_t selection);
void show_channel_selector(); void show_channel_selector();
@ -111,7 +113,7 @@ public:
return UINT_INTERPOLATE(color, 0x000000ff, 0.5); return UINT_INTERPOLATE(color, 0x000000ff, 0.5);
} }
/// dividing the hue circle in 16 parts, hand adjusted for equal look, courtesy Thorsten Wilms /// hue circle divided into 16 equal-looking parts, courtesy Thorsten Wilms
static const uint32_t midi_channel_colors[16]; static const uint32_t midi_channel_colors[16];
protected: protected:

View file

@ -41,6 +41,9 @@ public:
void set_outline_color(uint32_t c) { property_outline_color_rgba() = c; hide(); show(); } void set_outline_color(uint32_t c) { property_outline_color_rgba() = c; hide(); show(); }
void set_fill_color(uint32_t c) { property_fill_color_rgba() = c; hide(); show(); } void set_fill_color(uint32_t c) { property_fill_color_rgba() = c; hide(); show(); }
void show() { SimpleRect::show(); }
void hide() { SimpleRect::hide(); }
bool on_event(GdkEvent* ev); bool on_event(GdkEvent* ev);
enum NoteEnd { enum NoteEnd {
@ -58,16 +61,12 @@ public:
MidiRegionView& region, MidiRegionView& region,
Group& group, Group& group,
const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>()) const boost::shared_ptr<NoteType> note = boost::shared_ptr<NoteType>())
: SimpleRect(group), CanvasNoteEvent(region, this, note), _note_state(None) : SimpleRect(group), CanvasNoteEvent(region, this, note), _note_state(None)
{ {
} }
protected: protected:
NoteState _note_state; NoteState _note_state;
private:
}; };
} // namespace Gnome } // namespace Gnome

View file

@ -482,7 +482,6 @@ void
MidiRegionView::display_model(boost::shared_ptr<MidiModel> model) MidiRegionView::display_model(boost::shared_ptr<MidiModel> model)
{ {
_model = model; _model = model;
if (_enable_display) { if (_enable_display) {
redisplay_model(); redisplay_model();
} }
@ -549,8 +548,9 @@ void
MidiRegionView::redisplay_model() MidiRegionView::redisplay_model()
{ {
// Don't redisplay the model if we're currently recording and displaying that // Don't redisplay the model if we're currently recording and displaying that
if (_active_notes) if (_active_notes) {
return; return;
}
if (_model) { if (_model) {
clear_events(); clear_events();
@ -754,7 +754,8 @@ MidiRegionView::apply_note_range (uint8_t min, uint8_t max, bool force)
Item* item = dynamic_cast<Item*>(event); Item* item = dynamic_cast<Item*>(event);
assert(item); assert(item);
if (event && event->note()) { 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)) { if (canvas_item_visible(item)) {
item->hide(); item->hide();
} }
@ -787,7 +788,6 @@ MidiRegionView::apply_note_range (uint8_t min, uint8_t max, bool force)
} }
} }
} }
} }
} }
@ -917,6 +917,16 @@ MidiRegionView::play_midi_note_off(boost::shared_ptr<NoteType> note)
return false; 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). /** Add a MIDI note to the view (with length).
* *
@ -933,14 +943,6 @@ MidiRegionView::add_note(const boost::shared_ptr<NoteType> note)
const nframes64_t note_start_frames = beats_to_frames(note->time()); const nframes64_t note_start_frames = beats_to_frames(note->time());
const nframes64_t note_end_frames = beats_to_frames(note->end_time()); const nframes64_t note_end_frames = beats_to_frames(note->end_time());
// dont display notes beyond the region bounds
if (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;
}
ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group(); ArdourCanvas::Group* const group = (ArdourCanvas::Group*)get_canvas_group();
CanvasNoteEvent* event = 0; CanvasNoteEvent* event = 0;
@ -955,14 +957,14 @@ MidiRegionView::add_note(const boost::shared_ptr<NoteType> note)
CanvasNote* ev_rect = new CanvasNote(*this, *group, note); CanvasNote* ev_rect = new CanvasNote(*this, *group, note);
ev_rect->property_x1() = x; ev_rect->property_x1() = x;
ev_rect->property_y1() = y1; ev_rect->property_y1() = y1;
if (note->length() > 0) if (note->length() > 0) {
ev_rect->property_x2() = note_endpixel; ev_rect->property_x2() = note_endpixel;
else } else {
ev_rect->property_x2() = trackview.editor().frame_to_pixel(_region->length()); ev_rect->property_x2() = trackview.editor().frame_to_pixel(_region->length());
}
ev_rect->property_y2() = y1 + floor(midi_stream_view()->note_height()); ev_rect->property_y2() = y1 + floor(midi_stream_view()->note_height());
if (note->length() == 0) { if (note->length() == 0) {
if (_active_notes) { if (_active_notes) {
assert(note->note() < 128); assert(note->note() < 128);
// If this note is already active there's a stuck note, // If this note is already active there's a stuck note,
@ -985,12 +987,9 @@ MidiRegionView::add_note(const boost::shared_ptr<NoteType> note)
ev_rect->property_outline_what() = (guint32) 0xF; ev_rect->property_outline_what() = (guint32) 0xF;
} }
ev_rect->show();
_events.push_back(ev_rect);
event = ev_rect; event = ev_rect;
MidiGhostRegion* gr; MidiGhostRegion* gr;
for (std::vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) { for (std::vector<GhostRegion*>::iterator g = ghosts.begin(); g != ghosts.end(); ++g) {
if ((gr = dynamic_cast<MidiGhostRegion*>(*g)) != 0) { if ((gr = dynamic_cast<MidiGhostRegion*>(*g)) != 0) {
gr->add_note(ev_rect); gr->add_note(ev_rect);
@ -1003,8 +1002,6 @@ MidiRegionView::add_note(const boost::shared_ptr<NoteType> note)
CanvasHit* ev_diamond = new CanvasHit(*this, *group, diamond_size, note); CanvasHit* ev_diamond = new CanvasHit(*this, *group, diamond_size, note);
ev_diamond->move(x, y); ev_diamond->move(x, y);
ev_diamond->show();
_events.push_back(ev_diamond);
event = ev_diamond; event = ev_diamond;
} else { } else {
event = 0; event = 0;
@ -1015,6 +1012,12 @@ MidiRegionView::add_note(const boost::shared_ptr<NoteType> note)
note_selected(event, true); note_selected(event, true);
} }
event->on_channel_selection_change(_last_channel_selection); event->on_channel_selection_change(_last_channel_selection);
_events.push_back(event);
if (note_in_visible_range(note)) {
event->show();
} else {
event->hide();
}
} }
} }
@ -1348,7 +1351,7 @@ MidiRegionView::note_dropped(CanvasNoteEvent* ev, double dt, uint8_t dnote)
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 // keep notes in standard midi range
clamp_0_to_127(new_pitch); clamp_to_0_127(new_pitch);
// keep original pitch if note is dragged outside valid midi range // keep original pitch if note is dragged outside valid midi range
if ((original_pitch != 0 && new_pitch == 0) if ((original_pitch != 0 && new_pitch == 0)
@ -1556,7 +1559,7 @@ MidiRegionView::change_note_velocity(CanvasNoteEvent* event, int8_t velocity, bo
if (relative) { if (relative) {
uint8_t new_velocity = copy->velocity() + velocity; uint8_t new_velocity = copy->velocity() + velocity;
clamp_0_to_127(new_velocity); clamp_to_0_127(new_velocity);
copy->set_velocity(new_velocity); copy->set_velocity(new_velocity);
} else { } else {
copy->set_velocity(velocity); copy->set_velocity(velocity);

View file

@ -177,6 +177,9 @@ class MidiRegionView : public RegionView
void move_selection(double dx, double dy); void move_selection(double dx, double dy);
void note_dropped(ArdourCanvas::CanvasNoteEvent* ev, double d_frames, uint8_t d_note); void note_dropped(ArdourCanvas::CanvasNoteEvent* ev, double d_frames, uint8_t d_note);
/** Return true iff the note is within the currently visible range */
bool note_in_visible_range(const boost::shared_ptr<NoteType> note) const;
/** Get the region position in pixels relative to session. */ /** Get the region position in pixels relative to session. */
double get_position_pixels(); double get_position_pixels();

View file

@ -24,28 +24,29 @@
#include <gtkmm2ext/gtk_ui.h> #include <gtkmm2ext/gtk_ui.h>
#include <ardour/midi_diskstream.h>
#include <ardour/midi_playlist.h> #include <ardour/midi_playlist.h>
#include <ardour/midi_region.h> #include <ardour/midi_region.h>
#include <ardour/midi_source.h> #include <ardour/midi_source.h>
#include <ardour/midi_diskstream.h>
#include <ardour/midi_track.h> #include <ardour/midi_track.h>
#include <ardour/smf_source.h>
#include <ardour/region_factory.h> #include <ardour/region_factory.h>
#include <ardour/smf_source.h>
#include "midi_streamview.h"
#include "region_view.h"
#include "midi_region_view.h"
#include "midi_time_axis.h"
#include "canvas-simplerect.h"
#include "region_selection.h"
#include "selection.h"
#include "public_editor.h"
#include "ardour_ui.h" #include "ardour_ui.h"
#include "rgb_macros.h" #include "canvas-simplerect.h"
#include "gui_thread.h" #include "gui_thread.h"
#include "utils.h"
#include "simplerect.h"
#include "lineset.h" #include "lineset.h"
#include "midi_region_view.h"
#include "midi_streamview.h"
#include "midi_time_axis.h"
#include "midi_util.h"
#include "public_editor.h"
#include "region_selection.h"
#include "region_view.h"
#include "rgb_macros.h"
#include "selection.h"
#include "simplerect.h"
#include "utils.h"
using namespace std; using namespace std;
using namespace ARDOUR; using namespace ARDOUR;
@ -62,10 +63,11 @@ MidiStreamView::MidiStreamView (MidiTimeAxisView& tv)
, _data_note_min(60) , _data_note_min(60)
, _data_note_max(71) , _data_note_max(71)
{ {
if (tv.is_track()) if (tv.is_track()) {
stream_base_color = ARDOUR_UI::config()->canvasvar_MidiTrackBase.get(); stream_base_color = ARDOUR_UI::config()->canvasvar_MidiTrackBase.get();
else } else {
stream_base_color = ARDOUR_UI::config()->canvasvar_MidiBusBase.get(); stream_base_color = ARDOUR_UI::config()->canvasvar_MidiBusBase.get();
}
use_rec_regions = tv.editor().show_waveforms_recording (); use_rec_regions = tv.editor().show_waveforms_recording ();
@ -82,7 +84,10 @@ MidiStreamView::MidiStreamView (MidiTimeAxisView& tv)
_note_lines->property_x2() = trackview().editor().frame_to_pixel (max_frames); _note_lines->property_x2() = trackview().editor().frame_to_pixel (max_frames);
_note_lines->property_y2() = 0; _note_lines->property_y2() = 0;
_note_lines->signal_event().connect (bind (mem_fun (_trackview.editor(), &PublicEditor::canvas_stream_view_event), _note_lines, &_trackview)); _note_lines->signal_event().connect(bind(
mem_fun(_trackview.editor(), &PublicEditor::canvas_stream_view_event),
_note_lines, &_trackview));
_note_lines->lower_to_bottom(); _note_lines->lower_to_bottom();
ColorsChanged.connect(mem_fun(*this, &MidiStreamView::draw_note_lines)); ColorsChanged.connect(mem_fun(*this, &MidiStreamView::draw_note_lines));
@ -90,7 +95,8 @@ MidiStreamView::MidiStreamView (MidiTimeAxisView& tv)
note_range_adjustment.set_page_size(_highest_note - _lowest_note); note_range_adjustment.set_page_size(_highest_note - _lowest_note);
note_range_adjustment.set_value(_lowest_note); note_range_adjustment.set_value(_lowest_note);
note_range_adjustment.signal_value_changed().connect (mem_fun (*this, &MidiStreamView::note_range_adjustment_changed)); note_range_adjustment.signal_value_changed().connect(
mem_fun(*this, &MidiStreamView::note_range_adjustment_changed));
} }
MidiStreamView::~MidiStreamView () MidiStreamView::~MidiStreamView ()
@ -101,10 +107,8 @@ static void
veto_note_range(uint8_t& min, uint8_t& max) veto_note_range(uint8_t& min, uint8_t& max)
{ {
/* Legal notes, thanks */ /* Legal notes, thanks */
if (max > 127) clamp_to_0_127(min);
max = 127; clamp_to_0_127(max);
if (min > 127)
min = 127;
/* Always display at least one octave in [0, 127] */ /* Always display at least one octave in [0, 127] */
if (max == 127) { if (max == 127) {
@ -186,6 +190,7 @@ MidiStreamView::display_region(MidiRegionView* region_view, bool load_model)
source->model()->highest_note()); source->model()->highest_note());
// Display region contents // Display region contents
region_view->set_height(height);
region_view->display_model(source->model()); region_view->display_model(source->model());
} }
@ -197,6 +202,18 @@ MidiStreamView::display_diskstream (boost::shared_ptr<Diskstream> ds)
NoteRangeChanged(); NoteRangeChanged();
} }
void
MidiStreamView::update_contents_metrics(boost::shared_ptr<Region> r)
{
boost::shared_ptr<MidiRegion> mr = boost::dynamic_pointer_cast<MidiRegion>(r);
if (mr) {
mr->midi_source(0)->load_model();
_range_dirty = update_data_note_range(
mr->model()->lowest_note(),
mr->model()->highest_note());
}
}
bool bool
MidiStreamView::update_data_note_range(uint8_t min, uint8_t max) MidiStreamView::update_data_note_range(uint8_t min, uint8_t max)
{ {
@ -212,29 +229,22 @@ MidiStreamView::update_data_note_range(uint8_t min, uint8_t max)
return dirty; return dirty;
} }
// FIXME: code duplication with AudioStreamView
void void
MidiStreamView::redisplay_diskstream () MidiStreamView::redisplay_diskstream ()
{ {
list<RegionView *>::iterator i, tmp; if (!_trackview.is_midi_track()) {
return;
}
list<RegionView*>::iterator i, tmp;
// Load models if necessary, and find note range of all our contents
_range_dirty = false; _range_dirty = false;
_data_note_min = 127; _data_note_min = 127;
_data_note_max = 0; _data_note_max = 0;
_trackview.get_diskstream()->playlist()->foreach_region(
for (i = region_views.begin(); i != region_views.end(); ++i) { static_cast<StreamView*>(this),
(*i)->set_valid (false); &StreamView::update_contents_metrics);
(*i)->enable_display (false);
// Load model if it isn't already, to get note range
MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
if (mrv) {
mrv->midi_region()->midi_source(0)->load_model();
_range_dirty = update_data_note_range(
mrv->midi_region()->model()->lowest_note(),
mrv->midi_region()->model()->highest_note());
}
}
// No notes, use default range // No notes, use default range
if (!_range_dirty) { if (!_range_dirty) {
@ -242,28 +252,25 @@ MidiStreamView::redisplay_diskstream ()
_data_note_max = 71; _data_note_max = 71;
} }
bool range_changed = false;
// Extend visible range to show newly recorded data, if necessary // Extend visible range to show newly recorded data, if necessary
if (_data_note_min < _lowest_note) { _lowest_note = std::min(_lowest_note, _data_note_min);
_lowest_note = _data_note_min; _highest_note = std::max(_highest_note, _data_note_max);
range_changed = true;
}
if (_data_note_max > _highest_note) {
_highest_note = _data_note_max;
range_changed = true;
}
veto_note_range(_lowest_note, _highest_note); veto_note_range(_lowest_note, _highest_note);
if (_trackview.is_midi_track()) { // Flag region views as invalid and disable drawing
_trackview.get_diskstream()->playlist()->foreach_region ( for (i = region_views.begin(); i != region_views.end(); ++i) {
static_cast<StreamView*>(this), &StreamView::add_region_view); (*i)->set_valid(false);
(*i)->enable_display(false);
} }
RegionViewList copy; // Add and display region views, and flag existing ones as valid
_trackview.get_diskstream()->playlist()->foreach_region(
static_cast<StreamView*>(this),
&StreamView::add_region_view);
/* Place regions */ // Build a list of region views sorted by layer, and remove invalids
RegionViewList copy;
for (i = region_views.begin(); i != region_views.end(); ) { for (i = region_views.begin(); i != region_views.end(); ) {
tmp = i; tmp = i;
tmp++; tmp++;
@ -273,14 +280,8 @@ MidiStreamView::redisplay_diskstream ()
region_views.erase (i); region_views.erase (i);
i = tmp; i = tmp;
continue; continue;
} else {
(*i)->enable_display(true);
(*i)->set_height(height); // apply note range
} }
/* Sort regionviews by layer so that when we call region_layered ()
the canvas layering works out (in non-stacked mode). */
if (copy.size() == 0) { if (copy.size() == 0) {
copy.push_front((*i)); copy.push_front((*i));
i = tmp; i = tmp;
@ -311,14 +312,13 @@ MidiStreamView::redisplay_diskstream ()
i = tmp; i = tmp;
} }
/* Fix canvas layering */ // Fix canvas layering by raising each in the sorted list order
for (RegionViewList::iterator j = copy.begin(); j != copy.end(); ++j) { for (RegionViewList::iterator j = copy.begin(); j != copy.end(); ++j) {
region_layered (*j); region_layered (*j);
} }
/* Update note range and re-draw note lines if necessary */ // Update note range (not to regions which are already good) and draw note lines
apply_note_range(_lowest_note, _highest_note); apply_note_range(_lowest_note, _highest_note, false);
NoteRangeChanged();
} }
@ -378,11 +378,11 @@ MidiStreamView::set_note_range(VisibleNoteRange r)
_highest_note = _data_note_max; _highest_note = _data_note_max;
} }
apply_note_range(_lowest_note, _highest_note); apply_note_range(_lowest_note, _highest_note, true);
} }
void void
MidiStreamView::apply_note_range(uint8_t lowest, uint8_t highest) MidiStreamView::apply_note_range(uint8_t lowest, uint8_t highest, bool to_region_views)
{ {
_highest_note = highest; _highest_note = highest;
_lowest_note = lowest; _lowest_note = lowest;
@ -390,9 +390,11 @@ MidiStreamView::apply_note_range(uint8_t lowest, uint8_t highest)
note_range_adjustment.set_value(_lowest_note); note_range_adjustment.set_value(_lowest_note);
draw_note_lines(); draw_note_lines();
if (to_region_views) {
for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) { for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
((MidiRegionView*)(*i))->apply_note_range(lowest, highest); ((MidiRegionView*)(*i))->apply_note_range(lowest, highest);
} }
}
NoteRangeChanged(); NoteRangeChanged();
} }
@ -716,6 +718,6 @@ MidiStreamView::note_range_adjustment_changed()
_lowest_note = lowest; _lowest_note = lowest;
_highest_note = highest; _highest_note = highest;
apply_note_range(lowest, highest); apply_note_range(lowest, highest, true);
} }

View file

@ -121,8 +121,9 @@ class MidiStreamView : public StreamView
void update_contents_height (); void update_contents_height ();
void draw_note_lines(); void draw_note_lines();
void apply_note_range(uint8_t lowest, uint8_t highest); void apply_note_range(uint8_t lowest, uint8_t highest, bool to_region_views);
bool update_data_note_range(uint8_t min, uint8_t max); bool update_data_note_range(uint8_t min, uint8_t max);
void update_contents_metrics(boost::shared_ptr<ARDOUR::Region> r);
void color_handler (); void color_handler ();

View file

@ -20,11 +20,11 @@
#ifndef __gtk_ardour_midi_util_h__ #ifndef __gtk_ardour_midi_util_h__
#define __gtk_ardour_midi_util_h__ #define __gtk_ardour_midi_util_h__
inline static void clamp_0_to_127(uint8_t &val) inline static void clamp_to_0_127(uint8_t &val)
{ {
if( (127 < val) && (val < 192) ) { if ((127 < val) && (val < 192)) {
val = 127; val = 127;
} else if( (192 <= val) && (val < 255) ) { } else if ((192 <= val) && (val < 255)) {
val = 0; val = 0;
} }
} }

View file

@ -93,6 +93,7 @@ public:
void get_selectables (nframes_t start, nframes_t end, list<Selectable* >&); void get_selectables (nframes_t start, nframes_t end, list<Selectable* >&);
void get_inverted_selectables (Selection&, list<Selectable* >& results); void get_inverted_selectables (Selection&, list<Selectable* >& results);
virtual void update_contents_metrics(boost::shared_ptr<ARDOUR::Region> r) {}
void add_region_view (boost::shared_ptr<ARDOUR::Region>); void add_region_view (boost::shared_ptr<ARDOUR::Region>);
void region_layered (RegionView*); void region_layered (RegionView*);
virtual void update_contents_height (); virtual void update_contents_height ();

View file

@ -27,10 +27,11 @@
#include <pbd/undo.h> #include <pbd/undo.h>
#include <ardour/ardour.h> #include <ardour/ardour.h>
#include <ardour/region.h>
#include <ardour/gain.h> #include <ardour/gain.h>
#include <ardour/logcurve.h> #include <ardour/logcurve.h>
#include <ardour/midi_model.h>
#include <ardour/midi_source.h> #include <ardour/midi_source.h>
#include <ardour/region.h>
class XMLNode; class XMLNode;

View file

@ -21,24 +21,21 @@
#define __ardour_midi_source_h__ #define __ardour_midi_source_h__
#include <string> #include <string>
#include <time.h> #include <time.h>
#include <glibmm/thread.h>
#include <sigc++/signal.h> #include <sigc++/signal.h>
#include <glibmm/thread.h>
#include <ardour/source.h>
#include <ardour/ardour.h>
#include <ardour/buffer.h>
#include <ardour/midi_model.h>
#include <pbd/stateful.h> #include <pbd/stateful.h>
#include <pbd/xml++.h> #include <pbd/xml++.h>
#include <evoral/Sequence.hpp>
#include <ardour/ardour.h>
#include <ardour/buffer.h>
#include <ardour/source.h>
using std::string; using std::string;
namespace ARDOUR { namespace ARDOUR {
class MidiModel;
template<typename T> class MidiRingBuffer; template<typename T> class MidiRingBuffer;
/** Source for MIDI data */ /** Source for MIDI data */
@ -93,7 +90,7 @@ class MidiSource : public Source
virtual void load_model(bool lock=true, bool force_reload=false) = 0; virtual void load_model(bool lock=true, bool force_reload=false) = 0;
virtual void destroy_model() = 0; virtual void destroy_model() = 0;
void set_note_mode(NoteMode mode) { if (_model) _model->set_note_mode(mode); } void set_note_mode(NoteMode mode);
boost::shared_ptr<MidiModel> model() { return _model; } boost::shared_ptr<MidiModel> model() { return _model; }
void set_model(boost::shared_ptr<MidiModel> m) { _model = m; } void set_model(boost::shared_ptr<MidiModel> m) { _model = m; }

View file

@ -403,7 +403,7 @@ AudioFileSource::move_to_trash (const ustring& trash_dir_name)
if (::rename (_path.c_str(), newpath.c_str()) != 0) { if (::rename (_path.c_str(), newpath.c_str()) != 0) {
PBD::error << string_compose ( PBD::error << string_compose (
_("cannot rename midi file source from %1 to %2 (%3)"), _("cannot rename audio file source from %1 to %2 (%3)"),
_path, newpath, strerror (errno)) << endmsg; _path, newpath, strerror (errno)) << endmsg;
return -1; return -1;
} }

View file

@ -33,6 +33,7 @@
#include <pbd/basename.h> #include <pbd/basename.h>
#include <ardour/audioengine.h> #include <ardour/audioengine.h>
#include <ardour/midi_model.h>
#include <ardour/midi_ring_buffer.h> #include <ardour/midi_ring_buffer.h>
#include <ardour/midi_source.h> #include <ardour/midi_source.h>
#include <ardour/session.h> #include <ardour/session.h>
@ -51,9 +52,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)
, _timeline_position(0) , _timeline_position(0)
, _model(new MidiModel(this))
, _writing (false) , _writing (false)
, _model_iter(*_model.get(), 0.0)
, _last_read_end(0) , _last_read_end(0)
{ {
_read_data_count = 0; _read_data_count = 0;
@ -63,9 +62,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)
, _timeline_position(0) , _timeline_position(0)
, _model(new MidiModel(this))
, _writing (false) , _writing (false)
, _model_iter(*_model.get(), 0.0)
, _last_read_end(0) , _last_read_end(0)
{ {
_read_data_count = 0; _read_data_count = 0;
@ -237,3 +234,11 @@ MidiSource::session_saved()
} }
} }
void
MidiSource::set_note_mode(NoteMode mode)
{
if (_model) {
_model->set_note_mode(mode);
}
}

View file

@ -35,12 +35,13 @@
#include <evoral/SMFReader.hpp> #include <evoral/SMFReader.hpp>
#include <evoral/Control.hpp> #include <evoral/Control.hpp>
#include <ardour/smf_source.h>
#include <ardour/session.h>
#include <ardour/midi_ring_buffer.h>
#include <ardour/tempo.h>
#include <ardour/audioengine.h> #include <ardour/audioengine.h>
#include <ardour/event_type_map.h> #include <ardour/event_type_map.h>
#include <ardour/midi_model.h>
#include <ardour/midi_ring_buffer.h>
#include <ardour/session.h>
#include <ardour/smf_source.h>
#include <ardour/tempo.h>
#include "i18n.h" #include "i18n.h"
@ -167,7 +168,7 @@ SMFSource::read_unlocked (MidiRingBuffer<nframes_t>& dst, nframes_t start, nfram
_last_read_end = start + dur; _last_read_end = start + dur;
while (!Evoral::SMF::eof()) { while (true) {
ret = read_event(&ev_delta_t, &ev_size, &ev_buffer); ret = read_event(&ev_delta_t, &ev_size, &ev_buffer);
if (ret == -1) { // EOF if (ret == -1) { // EOF
break; break;
@ -623,7 +624,7 @@ SMFSource::load_model(bool lock, bool force_reload)
Glib::Mutex::Lock lm (_lock); Glib::Mutex::Lock lm (_lock);
} }
if (_model && !force_reload && !_model->empty()) { if (_model && !force_reload) {
return; return;
} }

View file

@ -57,7 +57,6 @@ public:
uint16_t num_tracks() const; uint16_t num_tracks() const;
uint16_t ppqn() const; uint16_t ppqn() const;
bool is_empty() const { return _empty; } bool is_empty() const { return _empty; }
bool eof() const { assert(false); return true; }
void begin_write(); void begin_write();
void append_event_delta(uint32_t delta_t, uint32_t size, const uint8_t* buf); void append_event_delta(uint32_t delta_t, uint32_t size, const uint8_t* buf);
@ -69,7 +68,6 @@ private:
std::string _path; std::string _path;
smf_t* _smf; smf_t* _smf;
smf_track_t* _smf_track; smf_track_t* _smf_track;
bool _empty; ///< true iff file contains(non-empty) events bool _empty; ///< true iff file contains(non-empty) events
}; };