Index: libs/ardour/midi_model.cc
===================================================================
--- libs/ardour/midi_model.cc	(Revision 3179)
+++ libs/ardour/midi_model.cc	(Arbeitskopie)
@@ -36,6 +36,34 @@
 using namespace ARDOUR;
 
 
+void 
+MidiModel::write_lock()        
+{ 
+	_lock.writer_lock(); 
+	_automation_lock.lock(); 
+}
+
+void 
+MidiModel::write_unlock()      
+{ 
+	_lock.writer_unlock(); 
+	_automation_lock.unlock(); 
+}
+
+void 
+MidiModel::read_lock()   const 
+{ 
+	_lock.reader_lock(); 
+	/*_automation_lock.lock();*/ 
+}
+
+void 
+MidiModel::read_unlock() const 
+{ 
+	_lock.reader_unlock(); 
+	/*_automation_lock.unlock();*/ 
+}
+
 // Read iterator (const_iterator)
 
 MidiModel::const_iterator::const_iterator(const MidiModel& model, double t)
@@ -106,18 +134,21 @@
 	if (_event.size() == 0) {
 		//cerr << "Created MIDI iterator @ " << t << " is at end." << endl;
 		_is_end = true;
-		_model->read_unlock();
-		_locked = false;
-	} /*else {
+		if(_locked) {
+			_model->read_unlock();
+			_locked = false;
+		}
+	} else {
 		printf("MIDI Iterator = %X @ %lf\n", _event.type(), _event.time());
-	}*/
+	}
 }
 
 
 MidiModel::const_iterator::~const_iterator()
 {
-	if (_locked)
+	if (_locked) {
 		_model->read_unlock();
+	}
 }
 		
 
@@ -182,22 +213,20 @@
 			type = CC;
 
 	if (type == NOTE_ON) {
-		//cerr << "********** MIDI Iterator = note on" << endl;
+		cerr << "********** MIDI Iterator = note on" << endl;
 		_event = MIDI::Event((*_note_iter)->on_event(), false);
 		_active_notes.push(*_note_iter);
 		++_note_iter;
 	} else if (type == NOTE_OFF) {
-		//cerr << "********** MIDI Iterator = note off" << endl;
+		cerr << "********** MIDI Iterator = note off" << endl;
 		_event = MIDI::Event(_active_notes.top()->off_event(), false);
 		_active_notes.pop();
 	} else if (type == CC) {
-		//cerr << "********** MIDI Iterator = CC" << endl;
+		cerr << "********** MIDI Iterator = CC" << endl;
 		_model->control_to_midi_event(_event, *_control_iter);
 	} else {
-		//cerr << "********** MIDI Iterator = END" << endl;
+		cerr << "********** MIDI Iterator = END" << endl;
 		_is_end = true;
-		_model->read_unlock();
-		_locked = false;
 	}
 
 	assert(_is_end || _event.size() > 0);
@@ -233,9 +262,6 @@
 	_control_iter = other._control_iter;
 	
 	assert( ! _event.owns_buffer());
-	
-	if (_locked)
-		_model->read_lock();
 
 	return *this;
 }
@@ -265,16 +291,16 @@
 size_t
 MidiModel::read(MidiRingBuffer& dst, nframes_t start, nframes_t nframes, nframes_t stamp_offset) const
 {
-	//cerr << this << " MM::read @ " << start << " * " << nframes << " + " << stamp_offset << endl;
-	//cerr << this << " MM # notes: " << n_notes() << endl;
+	cerr << this << " MM::read @ " << start << " * " << nframes << " + " << stamp_offset << endl;
+	cerr << this << " MM # notes: " << n_notes() << endl;
 
 	size_t read_events = 0;
 
 	if (start != _next_read) {
 		_read_iter = const_iterator(*this, (double)start);
-		//cerr << "Repositioning iterator from " << _next_read << " to " << start << endl;
+		cerr << "Repositioning iterator from " << _next_read << " to " << start << endl;
 	} else {
-		//cerr << "Using cached iterator at " << _next_read << endl;
+		cerr << "Using cached iterator at " << _next_read << endl;
 	}
 
 	_next_read = start + nframes;
@@ -282,11 +308,15 @@
 	while (_read_iter != end() && _read_iter->time() < start + nframes) {
 		assert(_read_iter->size() > 0);
 		dst.write(_read_iter->time() + stamp_offset, _read_iter->size(), _read_iter->buffer());
-		//cerr << this << " MM::read event @ " << _read_iter->time() << endl;
+		cerr << this << " MM::read event @ " << _read_iter->time()  
+		     << "type: " << int(_read_iter->type()) 
+		     << "note: " << int(_read_iter->note()) 
+		     << "velocity: " << int(_read_iter->velocity()) 
+		     << endl;
 		++_read_iter;
 		++read_events;
 	}
-
+	
 	return read_events;
 }
 	
Index: libs/ardour/ardour/midi_model.h
===================================================================
--- libs/ardour/ardour/midi_model.h	(Revision 3179)
+++ libs/ardour/ardour/midi_model.h	(Arbeitskopie)
@@ -58,10 +58,10 @@
 	MidiModel(Session& s, size_t size=0);
 	
 	// This is crap.
-	void write_lock()        { _lock.writer_lock(); _automation_lock.lock(); }
-	void write_unlock()      { _lock.writer_unlock(); _automation_lock.unlock(); }
-	void read_lock()   const { _lock.reader_lock(); /*_automation_lock.lock();*/ }
-	void read_unlock() const { _lock.reader_unlock(); /*_automation_lock.unlock();*/ }
+	void write_lock();
+	void write_unlock();
+	void read_lock()   const;
+	void read_unlock() const;
 
 	void clear() { _notes.clear(); }
 
@@ -164,7 +164,7 @@
 		friend class MidiModel;
 
 		const MidiModel* _model;
-		MIDI::Event        _event;
+		MIDI::Event      _event;
 
 		typedef std::priority_queue<
 				boost::shared_ptr<Note>, std::deque< boost::shared_ptr<Note> >,
