summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-01-19 07:00:43 +0000
committerDavid Robillard <d@drobilla.net>2013-01-19 07:00:43 +0000
commitfc77ae0738565770abde1a25f650a035cf082af0 (patch)
treef4edb7bcdcddf186fcf5cf4fb033e602580e4008 /gtk2_ardour
parentd251c68d7676a18ab9ed935e22558e2b18981b41 (diff)
Replace a bunch of potential crashes with graceful handling of the situation.
We really need some kind of more sophisticated assert macro that can be switched to non-fatal logging mode for release builds. A log message, which is often all that would happen, is a lot better than a trainwrecked performance... git-svn-id: svn://localhost/ardour2/branches/3.0@13892 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/automation_streamview.cc6
-rw-r--r--gtk2_ardour/automation_time_axis.cc9
-rw-r--r--gtk2_ardour/midi_channel_selector.cc10
-rw-r--r--gtk2_ardour/midi_region_view.cc52
-rw-r--r--gtk2_ardour/midi_streamview.cc43
-rw-r--r--gtk2_ardour/midi_time_axis.cc3
6 files changed, 57 insertions, 66 deletions
diff --git a/gtk2_ardour/automation_streamview.cc b/gtk2_ardour/automation_streamview.cc
index 65df722e3c..7b2c1ab751 100644
--- a/gtk2_ardour/automation_streamview.cc
+++ b/gtk2_ardour/automation_streamview.cc
@@ -249,9 +249,9 @@ AutomationStreamView::interpolation () const
}
AutomationRegionView* v = dynamic_cast<AutomationRegionView*> (region_views.front());
- assert (v);
-
- return v->line()->the_list()->interpolation ();
+ if (v) {
+ return v->line()->the_list()->interpolation ();
+ }
}
/** Clear all automation displayed in this view */
diff --git a/gtk2_ardour/automation_time_axis.cc b/gtk2_ardour/automation_time_axis.cc
index 8b090cf001..9fa412652d 100644
--- a/gtk2_ardour/automation_time_axis.cc
+++ b/gtk2_ardour/automation_time_axis.cc
@@ -192,8 +192,9 @@ AutomationTimeAxisView::AutomationTimeAxisView (
/* ask for notifications of any new RegionViews */
if (show_regions) {
- assert(_view);
- _view->attach ();
+ if (_view) {
+ _view->attach ();
+ }
} else {
/* no regions, just a single line for the entire track (e.g. bus gain) */
@@ -706,9 +707,7 @@ AutomationTimeAxisView::clear_lines ()
void
AutomationTimeAxisView::add_line (boost::shared_ptr<AutomationLine> line)
{
- assert(line);
- assert(!_line);
- if (_control) {
+ if (_control && line) {
assert(line->the_list() == _control->list());
_control->alist()->automation_state_changed.connect (
diff --git a/gtk2_ardour/midi_channel_selector.cc b/gtk2_ardour/midi_channel_selector.cc
index cdaf42e51f..6770f0e60d 100644
--- a/gtk2_ardour/midi_channel_selector.cc
+++ b/gtk2_ardour/midi_channel_selector.cc
@@ -17,7 +17,9 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <algorithm>
#include <sstream>
+
#include "midi_channel_selector.h"
#include "gtkmm/separator.h"
#include "i18n.h"
@@ -31,10 +33,10 @@ MidiChannelSelector::MidiChannelSelector(int n_rows, int n_columns, int start_ro
: Table(n_rows, n_columns, true)
, _recursion_counter(0)
{
- assert(n_rows >= 4);
- assert(n_rows >= start_row + 4);
- assert(n_columns >=4);
- assert(n_columns >= start_column + 4);
+ n_rows = std::max(4, n_rows);
+ n_rows = std::max(4, start_row + 4);
+ n_columns = std::max(4, n_columns);
+ n_columns = std::max(4, start_column + 4);
property_column_spacing() = 0;
property_row_spacing() = 0;
diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc
index 54a0bc4f2d..48f942f2b5 100644
--- a/gtk2_ardour/midi_region_view.cc
+++ b/gtk2_ardour/midi_region_view.cc
@@ -18,7 +18,6 @@
*/
#include <cmath>
-#include <cassert>
#include <algorithm>
#include <ostream>
@@ -915,13 +914,14 @@ MidiRegionView::show_list_editor ()
void
MidiRegionView::create_note_at (framepos_t t, double y, double length, bool snap_t)
{
+ if (length < 2 * DBL_EPSILON) {
+ return;
+ }
+
MidiTimeAxisView* const mtv = dynamic_cast<MidiTimeAxisView*>(&trackview);
MidiStreamView* const view = mtv->midi_view();
- double note = view->y_to_note(y);
-
- assert(note >= 0.0);
- assert(note <= 127.0);
+ const double note = view->y_to_note(y);
// Start of note in frames relative to region start
if (snap_t) {
@@ -929,13 +929,11 @@ MidiRegionView::create_note_at (framepos_t t, double y, double length, bool snap
t = snap_frame_to_grid_underneath (t, grid_frames);
}
- assert (t >= 0);
- assert (length != 0);
-
- const boost::shared_ptr<NoteType> new_note (new NoteType (mtv->get_channel_for_add (),
- region_frames_to_region_beats(t + _region->start()),
- length,
- (uint8_t)note, 0x40));
+ const boost::shared_ptr<NoteType> new_note (
+ new NoteType (mtv->get_channel_for_add (),
+ region_frames_to_region_beats(t + _region->start()),
+ length,
+ (uint8_t)note, 0x40));
if (_model->contains (new_note)) {
return;
@@ -1285,7 +1283,6 @@ MidiRegionView::display_sysexes()
boost::static_pointer_cast<const Evoral::MIDIEvent<Evoral::MusicalTime> > (*i);
Evoral::MusicalTime time = (*i)->time();
- assert (time >= 0);
if (mev) {
if (mev->is_spp() || mev->is_mtc_quarter() || mev->is_mtc_full()) {
@@ -1367,7 +1364,6 @@ void
MidiRegionView::reset_width_dependent_items (double pixel_width)
{
RegionView::reset_width_dependent_items(pixel_width);
- assert(_pixel_width == pixel_width);
if (_enable_display) {
redisplay_model();
@@ -1495,9 +1491,11 @@ MidiRegionView::add_ghost (TimeAxisView& tv)
void
MidiRegionView::begin_write()
{
- assert(!_active_notes);
+ if (_active_notes) {
+ delete[] _active_notes;
+ }
_active_notes = new CanvasNote*[128];
- for (unsigned i=0; i < 128; ++i) {
+ for (unsigned i = 0; i < 128; ++i) {
_active_notes[i] = 0;
}
}
@@ -1657,8 +1655,7 @@ MidiRegionView::update_note (CanvasNote* ev, bool update_ghost_regions)
ev->property_y2() = y1 + floor(midi_stream_view()->note_height());
if (note->length() == 0) {
- if (_active_notes) {
- assert(note->note() < 128);
+ if (_active_notes && note->note() < 128) {
// If this note is already active there's a stuck note,
// finish the old note rectangle
if (_active_notes[note->note()]) {
@@ -1712,9 +1709,6 @@ MidiRegionView::add_note(const boost::shared_ptr<NoteType> note, bool visible)
{
CanvasNoteEvent* event = 0;
- assert(note->time() >= 0);
- assert(midi_view()->note_mode() == Sustained || midi_view()->note_mode() == Percussive);
-
//ArdourCanvas::Group* const group = (ArdourCanvas::Group*) get_canvas_group();
if (midi_view()->note_mode() == Sustained) {
@@ -1816,8 +1810,6 @@ MidiRegionView::step_sustain (Evoral::MusicalTime beats)
void
MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch, const string& displaytext, bool active_channel)
{
- assert (patch->time() >= 0);
-
framecnt_t region_frames = source_beats_to_region_frames (patch->time());
const double x = trackview.editor().frame_to_pixel (region_frames);
@@ -1868,7 +1860,10 @@ MidiRegionView::get_patch_key_at (double time, uint8_t channel, MIDI::Name::Patc
key.bank_number = key.program_number = 0;
}
- assert (key.is_sane());
+ if (!key.is_sane()) {
+ error << string_compose(_("insane MIDI patch key %1:%2"),
+ key.bank_number, key.program_number) << endmsg;
+ }
}
void
@@ -2436,11 +2431,9 @@ MidiRegionView::move_selection(double dx, double dy, double cumulative_dy)
void
MidiRegionView::note_dropped(CanvasNoteEvent *, frameoffset_t dt, int8_t dnote)
{
- assert (!_selection.empty());
-
uint8_t lowest_note_in_selection = 127;
uint8_t highest_note_in_selection = 0;
- uint8_t highest_note_difference = 0;
+ uint8_t highest_note_difference = 0;
// find highest and lowest notes first
@@ -3714,11 +3707,10 @@ MidiRegionView::data_recorded (boost::weak_ptr<MidiSource> w)
for (MidiBuffer::iterator i = buf->begin(); i != buf->end(); ++i) {
Evoral::MIDIEvent<MidiBuffer::TimeType> const ev (*i, false);
- assert (ev.buffer ());
- if(ev.is_channel_event()) {
+ if (ev.is_channel_event()) {
if (_last_channel_mode == FilterChannels) {
- if(((uint16_t(1) << ev.channel()) & _last_channel_selection) == 0) {
+ if (((uint16_t(1) << ev.channel()) & _last_channel_selection) == 0) {
continue;
}
}
diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc
index 843ca1bfc2..90e6147763 100644
--- a/gtk2_ardour/midi_streamview.cc
+++ b/gtk2_ardour/midi_streamview.cc
@@ -17,7 +17,6 @@
*/
#include <cmath>
-#include <cassert>
#include <utility>
#include <gtkmm.h>
@@ -49,6 +48,8 @@
#include "simplerect.h"
#include "utils.h"
+#include "i18n.h"
+
using namespace std;
using namespace ARDOUR;
using namespace PBD;
@@ -400,7 +401,6 @@ MidiStreamView::apply_note_range_to_regions ()
void
MidiStreamView::update_note_range(uint8_t note_num)
{
- assert(note_num <= 127);
_data_note_min = min(_data_note_min, note_num);
_data_note_max = max(_data_note_max, note_num);
}
@@ -461,21 +461,23 @@ MidiStreamView::setup_rec_box ()
boost::shared_ptr<MidiRegion> region (boost::dynamic_pointer_cast<MidiRegion>
(RegionFactory::create (sources, plist, false)));
-
- assert(region);
- region->set_start (_trackview.track()->current_capture_start() - _trackview.track()->get_capture_start_frame (0));
- region->set_position (_trackview.track()->current_capture_start());
- RegionView* rv = add_region_view_internal (region, false);
- MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (rv);
- mrv->begin_write ();
-
- rec_regions.push_back (make_pair (region, rv));
-
- // rec regions are destroyed in setup_rec_box
-
- /* we add the region later */
-
- setup_new_rec_layer_time (region);
+ if (region) {
+ region->set_start (_trackview.track()->current_capture_start()
+ - _trackview.track()->get_capture_start_frame (0));
+ region->set_position (_trackview.track()->current_capture_start());
+ RegionView* rv = add_region_view_internal (region, false);
+ MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (rv);
+ mrv->begin_write ();
+
+
+ /* rec region will be destroyed in setup_rec_box */
+ rec_regions.push_back (make_pair (region, rv));
+
+ /* we add the region later */
+ setup_new_rec_layer_time (region);
+ } else {
+ error << _("failed to create MIDI region") << endmsg;
+ }
}
/* start a new rec box */
@@ -486,8 +488,6 @@ MidiStreamView::setup_rec_box ()
gdouble const xend = xstart;
uint32_t fill_color;
- assert(_trackview.midi_track()->mode() == Normal);
-
fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get();
ArdourCanvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*_canvas_group);
@@ -661,7 +661,8 @@ MidiStreamView::leave_internal_edit_mode ()
StreamView::leave_internal_edit_mode ();
for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (*i);
- assert (mrv);
- mrv->clear_selection ();
+ if (mrv) {
+ mrv->clear_selection ();
+ }
}
}
diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc
index c654c9cb84..82faf1890c 100644
--- a/gtk2_ardour/midi_time_axis.cc
+++ b/gtk2_ardour/midi_time_axis.cc
@@ -1078,9 +1078,6 @@ MidiTimeAxisView::route_active_changed ()
controls_base_unselected_name = "MidiTrackControlsBaseInactiveUnselected";
}
} else {
-
- throw; // wha?
-
if (_route->active()) {
controls_ebox.set_name ("BusControlsBaseUnselected");
controls_base_selected_name = "BusControlsBaseSelected";