Add dedicated manager for noteplayhandles

This caches and reuses nph's independently of the generic memory manager.
This commit is contained in:
Vesa
2014-08-23 20:37:21 +03:00
parent 5e4308507b
commit 42e67d27a1
9 changed files with 175 additions and 37 deletions

View File

@@ -216,20 +216,7 @@ public:
// play-handle stuff
bool addPlayHandle( PlayHandle* handle )
{
if( criticalXRuns() == false )
{
m_playHandleMutex.lock();
m_newPlayHandles.append( handle );
m_playHandleMutex.unlock();
return true;
}
delete handle;
return false;
}
bool addPlayHandle( PlayHandle* handle );
void removePlayHandle( PlayHandle* handle );

View File

@@ -57,7 +57,7 @@ public:
OriginCount
};
typedef Origins Origin;
NotePlayHandle( InstrumentTrack* instrumentTrack,
const f_cnt_t offset,
const f_cnt_t frames,
@@ -65,7 +65,13 @@ public:
NotePlayHandle* parent = NULL,
int midiEventChannel = -1,
Origin origin = OriginPattern );
virtual ~NotePlayHandle();
virtual ~NotePlayHandle() {}
void done();
void * operator new ( size_t size, void * p )
{
return p;
}
virtual void setVolume( volume_t volume );
virtual void setPanning( panning_t panning );
@@ -292,7 +298,7 @@ private:
bpm_t m_origTempo; // original tempo
f_cnt_t m_origFrames; // original m_frames
const int m_origBaseNote;
int m_origBaseNote;
float m_frequency;
float m_unpitchedFrequency;
@@ -300,10 +306,37 @@ private:
BaseDetuning* m_baseDetuning;
MidiTime m_songGlobalParentOffset;
const int m_midiChannel;
const Origin m_origin;
int m_midiChannel;
Origin m_origin;
bool m_frequencyNeedsUpdate; // used to update pitch
} ;
const int INITIAL_NPH_CACHE = 256;
const int NPH_CACHE_INCREMENT = 16;
class NotePlayHandleManager
{
MM_OPERATORS
public:
static void init();
static NotePlayHandle * acquire( InstrumentTrack* instrumentTrack,
const f_cnt_t offset,
const f_cnt_t frames,
const note& noteToPlay,
NotePlayHandle* parent = NULL,
int midiEventChannel = -1,
NotePlayHandle::Origin origin = NotePlayHandle::OriginPattern );
static void release( NotePlayHandle * nph );
static void extend( int i );
static void cleanup();
private:
static NotePlayHandleList s_nphCache;
static NotePlayHandleList s_available;
static QMutex s_mutex;
};
#endif

View File

@@ -55,6 +55,14 @@ public:
{
}
PlayHandle & operator = ( PlayHandle & p )
{
m_type = p.m_type;
m_offset = p.m_offset;
m_affinity = p.m_affinity;
return *this;
}
virtual ~PlayHandle()
{
}
@@ -119,7 +127,7 @@ public:
private:
Type m_type;
f_cnt_t m_offset;
const QThread* m_affinity;
QThread* m_affinity;
QMutex m_processingLock;
} ;