Skip to content

Commit

Permalink
Attempt to remove mutex calls from instrumenttrack::processinevent
Browse files Browse the repository at this point in the history
  • Loading branch information
diizy committed Jul 9, 2014
1 parent d4b0cc1 commit 4eb486b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
5 changes: 4 additions & 1 deletion include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#ifndef INSTRUMENT_TRACK_H
#define INSTRUMENT_TRACK_H

#include <QtCore/QAtomicPointer>
#include <QtCore/QAtomicInt>

#include "AudioPort.h"
#include "InstrumentFunctions.h"
#include "InstrumentSoundShaping.h"
Expand Down Expand Up @@ -227,7 +230,7 @@ protected slots:
AudioPort m_audioPort;
MidiPort m_midiPort;

NotePlayHandle* m_notes[NumKeys];
QAtomicPointer<NotePlayHandle> m_notes[NumKeys];
int m_runningMidiNotes[NumKeys];
bool m_sustainPedalPressed;

Expand Down
20 changes: 8 additions & 12 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ MidiEvent InstrumentTrack::applyMasterKey( const MidiEvent& event )

void InstrumentTrack::processInEvent( const MidiEvent& event, const MidiTime& time, f_cnt_t offset )
{
engine::mixer()->lock();
bool eventHandled = false;

switch( event.type() )
Expand All @@ -275,20 +274,17 @@ void InstrumentTrack::processInEvent( const MidiEvent& event, const MidiTime& ti
case MidiNoteOn:
if( event.velocity() > 0 )
{
if( m_notes[event.key()] == NULL )
{
// create (timed) note-play-handle
NotePlayHandle* nph = new NotePlayHandle( this, offset,
NotePlayHandle* nph;
m_notes[event.key()].testAndSetOrdered( NULL, ( nph = new NotePlayHandle( this, offset,
typeInfo<f_cnt_t>::max() / 2,
note( MidiTime(), MidiTime(), event.key(), event.volume( midiPort()->baseVelocity() ) ),
NULL, event.channel(),
NotePlayHandle::OriginMidiInput );
if( engine::mixer()->addPlayHandle( nph ) )
{
m_notes[event.key()] = nph;
}
NotePlayHandle::OriginMidiInput ) ) );
if( ! engine::mixer()->addPlayHandle( nph ) )
{
m_notes[event.key()].testAndSetOrdered( nph, NULL );
}

qDebug( "ok" );
eventHandled = true;
break;
}
Expand Down Expand Up @@ -369,7 +365,6 @@ void InstrumentTrack::processInEvent( const MidiEvent& event, const MidiTime& ti
qWarning( "InstrumentTrack: unhandled MIDI event %d", event.type() );
}

engine::mixer()->unlock();
}


Expand All @@ -393,6 +388,7 @@ void InstrumentTrack::processOutEvent( const MidiEvent& event, const MidiTime& t

if( key >= 0 && key < NumKeys )
{

if( m_runningMidiNotes[key] > 0 )
{
m_instrument->handleMidiEvent( MidiEvent( MidiNoteOff, midiPort()->realOutputChannel(), key, 0 ), time, offset );
Expand Down

0 comments on commit 4eb486b

Please sign in to comment.