Skip to content

Commit dec3185

Browse files
committed
Merge pull request #1088 from diizy/memmgr
LMMS Memory Manager
2 parents 6f96315 + 815a70a commit dec3185

File tree

84 files changed

+1518
-452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1518
-452
lines changed

include/AudioPort.h

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,55 +22,43 @@
2222
*
2323
*/
2424

25-
#ifndef _AUDIO_PORT_H
26-
#define _AUDIO_PORT_H
25+
#ifndef AUDIO_PORT_H
26+
#define AUDIO_PORT_H
2727

2828
#include <QtCore/QString>
2929
#include <QtCore/QMutex>
3030
#include <QtCore/QMutexLocker>
3131

3232
#include "Mixer.h"
33+
#include "MemoryManager.h"
34+
#include "PlayHandle.h"
3335

3436
class EffectChain;
37+
class FloatModel;
3538

3639
class AudioPort : public ThreadableJob
3740
{
41+
MM_OPERATORS
3842
public:
39-
AudioPort( const QString & _name, bool _has_effect_chain = true );
43+
AudioPort( const QString & _name, bool _has_effect_chain = true,
44+
FloatModel * volumeModel = NULL, FloatModel * panningModel = NULL );
4045
virtual ~AudioPort();
4146

42-
inline sampleFrame * firstBuffer()
47+
inline sampleFrame * buffer()
4348
{
44-
return m_firstBuffer;
49+
return m_portBuffer;
4550
}
4651

47-
inline sampleFrame * secondBuffer()
52+
inline void lockBuffer()
4853
{
49-
return m_secondBuffer;
54+
m_portBufferLock.lock();
5055
}
5156

52-
inline void lockFirstBuffer()
57+
inline void unlockBuffer()
5358
{
54-
m_firstBufferLock.lock();
59+
m_portBufferLock.unlock();
5560
}
5661

57-
inline void lockSecondBuffer()
58-
{
59-
m_secondBufferLock.lock();
60-
}
61-
62-
inline void unlockFirstBuffer()
63-
{
64-
m_firstBufferLock.unlock();
65-
}
66-
67-
inline void unlockSecondBuffer()
68-
{
69-
m_secondBufferLock.unlock();
70-
}
71-
72-
void nextPeriod();
73-
7462

7563
// indicate whether JACK & Co should provide output-buffer at ext. port
7664
inline bool extOutputEnabled() const
@@ -110,28 +98,20 @@ class AudioPort : public ThreadableJob
11098
bool processEffects();
11199

112100
// ThreadableJob stuff
113-
virtual void doProcessing( sampleFrame * );
101+
virtual void doProcessing();
114102
virtual bool requiresProcessing() const
115103
{
116104
return true;
117105
}
118106

119-
120-
enum bufferUsages
121-
{
122-
NoUsage,
123-
FirstBuffer,
124-
BothBuffers
125-
} ;
126-
107+
void addPlayHandle( PlayHandle * handle );
108+
void removePlayHandle( PlayHandle * handle );
127109

128110
private:
129-
volatile bufferUsages m_bufferUsage;
111+
volatile bool m_bufferUsage;
130112

131-
sampleFrame * m_firstBuffer;
132-
sampleFrame * m_secondBuffer;
133-
QMutex m_firstBufferLock;
134-
QMutex m_secondBufferLock;
113+
sampleFrame * m_portBuffer;
114+
QMutex m_portBufferLock;
135115

136116
bool m_extOutputEnabled;
137117
fx_ch_t m_nextFxChannel;
@@ -140,6 +120,11 @@ class AudioPort : public ThreadableJob
140120

141121
EffectChain * m_effects;
142122

123+
PlayHandleList m_playHandles;
124+
QMutex m_playHandleLock;
125+
126+
FloatModel * m_volumeModel;
127+
FloatModel * m_panningModel;
143128

144129
friend class Mixer;
145130
friend class MixerWorkerThread;

include/AutomatableModel.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "Model.h"
3333
#include "MidiTime.h"
3434
#include "ValueBuffer.h"
35-
35+
#include "MemoryManager.h"
3636

3737
// simple way to map a property of a view to a model
3838
#define mapPropertyFromModelPtr(type,getfunc,setfunc,modelname) \
@@ -66,6 +66,7 @@ class ControllerConnection;
6666
class EXPORT AutomatableModel : public Model, public JournallingObject
6767
{
6868
Q_OBJECT
69+
MM_OPERATORS
6970
public:
7071
typedef QVector<AutomatableModel *> AutoModelVector;
7172

include/BufferManager.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* BufferManager.h - A buffer caching/memory management system
3+
*
4+
* Copyright (c) 2014 Vesa Kivimäki <contact/dot/diizy/at/nbl/dot/fi>
5+
* Copyright (c) 2006-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
6+
*
7+
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
8+
*
9+
* This program is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 2 of the License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU General Public
20+
* License along with this program (see COPYING); if not, write to the
21+
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22+
* Boston, MA 02110-1301 USA.
23+
*
24+
*/
25+
26+
#ifndef BUFFER_MANAGER_H
27+
#define BUFFER_MANAGER_H
28+
29+
#include "MemoryManager.h"
30+
#include "lmms_basics.h"
31+
#include "engine.h"
32+
#include "Mixer.h"
33+
#include <QtCore/QAtomicInt>
34+
#include <QtCore/QReadWriteLock>
35+
36+
37+
const int BM_INITIAL_BUFFERS = 512;
38+
//const int BM_INCREMENT = 64;
39+
40+
class EXPORT BufferManager
41+
{
42+
public:
43+
static void init( fpp_t framesPerPeriod );
44+
static sampleFrame * acquire();
45+
static void release( sampleFrame * buf );
46+
static void refresh();
47+
// static void extend( int c );
48+
49+
private:
50+
static sampleFrame ** s_available;
51+
static QAtomicInt s_availableIndex;
52+
53+
static sampleFrame ** s_released;
54+
static QAtomicInt s_releasedIndex;
55+
// static QReadWriteLock s_mutex;
56+
static int s_size;
57+
};
58+
59+
#endif

include/ConfigManager.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include <QtCore/QVector>
3535

3636
#include "export.h"
37-
37+
#include "MemoryManager.h"
3838

3939
class engine;
4040

@@ -49,6 +49,7 @@ const QString LOCALE_PATH = "locale/";
4949

5050
class EXPORT ConfigManager
5151
{
52+
MM_OPERATORS
5253
public:
5354
static inline ConfigManager * inst()
5455
{

include/DataFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@
3232

3333
#include "export.h"
3434
#include "lmms_basics.h"
35-
35+
#include "MemoryManager.h"
3636

3737
class EXPORT DataFile : public QDomDocument
3838
{
39+
MM_OPERATORS
3940
public:
4041
enum Types
4142
{

include/DetuningHelper.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@
2323
*
2424
*/
2525

26-
#ifndef _DETUNING_HELPER_H
27-
#define _DETUNING_HELPER_H
26+
#ifndef DETUNING_HELPER_H
27+
#define DETUNING_HELPER_H
2828

2929
#include "InlineAutomation.h"
30-
30+
#include "MemoryManager.h"
3131

3232
class DetuningHelper : public InlineAutomation
3333
{
34+
MM_OPERATORS
3435
public:
3536
DetuningHelper() :
3637
InlineAutomation()

include/Effect.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
#include "Mixer.h"
3232
#include "AutomatableModel.h"
3333
#include "TempoSyncKnobModel.h"
34-
34+
#include "MemoryManager.h"
3535

3636
class EffectChain;
3737
class EffectControls;
3838

3939

4040
class EXPORT Effect : public Plugin
4141
{
42+
MM_OPERATORS
4243
public:
4344
Effect( const Plugin::Descriptor * _desc,
4445
Model * _parent,

include/FxMixer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class FxChannel : public ThreadableJob
7676
void processed();
7777

7878
private:
79-
virtual void doProcessing( sampleFrame * _working_buffer );
79+
virtual void doProcessing();
8080
};
8181

8282

include/Instrument.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class track;
4343

4444
class EXPORT Instrument : public Plugin
4545
{
46+
MM_OPERATORS
4647
public:
4748
enum Flag
4849
{

include/InstrumentPlayHandle.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@
2828
#include "PlayHandle.h"
2929
#include "Instrument.h"
3030
#include "NotePlayHandle.h"
31+
#include "export.h"
3132

32-
33-
class InstrumentPlayHandle : public PlayHandle
33+
class EXPORT InstrumentPlayHandle : public PlayHandle
3434
{
3535
public:
36-
InstrumentPlayHandle( Instrument* instrument ) :
37-
PlayHandle( TypeInstrumentPlayHandle ),
38-
m_instrument( instrument )
39-
{
40-
}
36+
InstrumentPlayHandle( Instrument * instrument, InstrumentTrack* instrumentTrack );
4137

4238
virtual ~InstrumentPlayHandle()
4339
{
@@ -88,6 +84,7 @@ class InstrumentPlayHandle : public PlayHandle
8884

8985
private:
9086
Instrument* m_instrument;
87+
InstrumentTrack * m_instrumentTrack;
9188

9289
} ;
9390

0 commit comments

Comments
 (0)