|
From: <pst...@us...> - 2013-04-08 03:56:34
|
Revision: 1019
http://sourceforge.net/p/jazzplusplus/code/1019
Author: pstieber
Date: 2013-04-08 03:56:31 +0000 (Mon, 08 Apr 2013)
Log Message:
-----------
1. Converted dynamic array code from macros to C++ template code.
2. Removed the DynamicArray.cpp source module.
3. Put the bit set code in a separate header file.
4. Updated the names of some audio data members.
Modified Paths:
--------------
trunk/jazz/src/Audio.cpp
trunk/jazz/src/Audio.h
trunk/jazz/src/DynamicArray.h
trunk/jazz/src/Makefile.am
trunk/jazz/src/Random.h
trunk/jazz/src/Track.h
trunk/jazz/src/mswin/WindowsAudioInterface.cpp
trunk/jazz/vc9/JazzPlusPlus-VC9.vcproj
Added Paths:
-----------
trunk/jazz/src/BitSet.h
Removed Paths:
-------------
trunk/jazz/src/DynamicArray.cpp
Modified: trunk/jazz/src/Audio.cpp
===================================================================
--- trunk/jazz/src/Audio.cpp 2013-04-07 23:54:34 UTC (rev 1018)
+++ trunk/jazz/src/Audio.cpp 2013-04-08 03:56:31 UTC (rev 1019)
@@ -204,7 +204,7 @@
int i;
for (i = 0; i < BUFCOUNT; ++i)
{
- buffers[i] = new JZAudioBuffer(0);
+ mpBuffers[i] = new JZAudioBuffer(0);
}
adjust_audio_length = 1;
@@ -241,7 +241,7 @@
}
for (i = 0; i < BUFCOUNT; i++)
{
- delete buffers[i];
+ delete mpBuffers[i];
}
}
@@ -415,7 +415,7 @@
mDriverBuffers.Clear();
for (i = 0; i < BUFCOUNT; i++)
{
- mFreeBuffers.Put(buffers[i]);
+ mFreeBuffers.Put(mpBuffers[i]);
}
buffers_written = 0;
@@ -1072,15 +1072,15 @@
// Save part of first buffer.
os.write(
- (char*)&buf.buffers[start_buffer]->data[start_offs],
+ (char*)&buf.mBuffers[start_buffer]->data[start_offs],
2 * start_length);
// write some complete buffers
for (int i = start_buffer + 1; i < end_buffer; i++)
- os.write((char*)buf.buffers[i]->data, bufsize * 2);
+ os.write((char*)buf.mBuffers[i]->data, bufsize * 2);
// save part of last buffer
if (end_length > 0)
- os.write((char*)buf.buffers[end_buffer]->data, 2 * end_length);
+ os.write((char*)buf.mBuffers[end_buffer]->data, 2 * end_length);
#if 0
// very slow, but works!
ofstream slow("t2.wav", ios::out | ios::bin | ios::trunc);
@@ -1089,7 +1089,7 @@
{
int bi = i / bufsize;
int di = i % bufsize;
- slow.write((char*)&buf.buffers[bi]->mpData[di], sizeof(short));
+ slow.write((char*)&buf.mBuffers[bi]->mpData[di], sizeof(short));
}
#endif
}
@@ -1098,17 +1098,15 @@
// ------------------------------- record ------------------------
// -----------------------------------------------------------------
-DEFINE_ARRAY(JZAudioBufferArray, JZAudioBuffer*)
-
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void JZAudioRecordBuffer::Clear()
{
- int n = buffers.GetSize();
+ int n = mBuffers.GetSize();
for (int i = 0; i < n; i++)
{
- delete buffers[i];
- buffers[i] = 0;
+ delete mBuffers[i];
+ mBuffers[i] = 0;
}
num_buffers = 0;
}
@@ -1117,14 +1115,14 @@
//-----------------------------------------------------------------------------
JZAudioBuffer* JZAudioRecordBuffer::RequestBuffer()
{
- if (buffers[num_buffers] == 0)
- buffers[num_buffers] = new JZAudioBuffer(0);
- if (buffers[num_buffers] == 0)
+ if (mBuffers[num_buffers] == 0)
+ mBuffers[num_buffers] = new JZAudioBuffer(0);
+ if (mBuffers[num_buffers] == 0)
{
Clear();
fprintf(stderr, "memory exhausted!\n");
}
- return buffers[num_buffers++];
+ return mBuffers[num_buffers++];
}
// -----------------------------------------------------------------
Modified: trunk/jazz/src/Audio.h
===================================================================
--- trunk/jazz/src/Audio.h 2013-04-07 23:54:34 UTC (rev 1018)
+++ trunk/jazz/src/Audio.h 2013-04-08 03:56:31 UTC (rev 1019)
@@ -112,9 +112,6 @@
}
};
-
-DECLARE_ARRAY(JZAudioBufferArray, JZAudioBuffer*)
-
//*****************************************************************************
//*****************************************************************************
class JZAudioBufferQueue
@@ -207,12 +204,11 @@
private:
- JZAudioBufferArray buffers;
+ TTDynamicArray<JZAudioBuffer*> mBuffers;
int num_buffers;
int bufbytes;
};
-
//*****************************************************************************
// Description:
// This is the sample set class declaration. This class holds a collection
@@ -299,7 +295,7 @@
JZAudioBuffer* GetBuffer(int i) const
{
// 0 < i < BUFCOUNT
- return buffers[i];
+ return mpBuffers[i];
}
void AdjustAudioLength(JZTrack *t, long TicksPerMinute);
@@ -426,7 +422,7 @@
unsigned int bufbytes; // buffer size in byte
unsigned int bufshorts; // buffer size in short
- JZAudioBuffer *buffers[BUFCOUNT]; // all the audio buffers
+ JZAudioBuffer* mpBuffers[BUFCOUNT]; // all the audio buffers
JZAudioBufferQueue mFreeBuffers; // to be filled with data
JZAudioBufferQueue mFullBuffers; // to be played by driver
JZAudioBufferQueue mDriverBuffers; // actually played by driver
@@ -458,6 +454,8 @@
JZSample* listen_sample;
};
+//*****************************************************************************
+//*****************************************************************************
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
inline
Added: trunk/jazz/src/BitSet.h
===================================================================
--- trunk/jazz/src/BitSet.h (rev 0)
+++ trunk/jazz/src/BitSet.h 2013-04-08 03:56:31 UTC (rev 1019)
@@ -0,0 +1,59 @@
+//*****************************************************************************
+// The JAZZ++ Midi Sequencer
+//
+// Copyright (C) 2013 Peter J. Stieber
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//*****************************************************************************
+
+#pragma once
+
+#include "DynamicArray.h"
+
+//*****************************************************************************
+//*****************************************************************************
+class JZBitset
+{
+ public:
+ int operator()(int i)
+ {
+ return (mArray[index(i)] & mask(i)) != 0;
+ }
+ void set(int i, int b)
+ {
+ if (b)
+ {
+ mArray[index(i)] |= mask(i);
+ }
+ else
+ {
+ mArray[index(i)] &= ~mask(i);
+ }
+ }
+
+ private:
+
+ TTDynamicArray<int> mArray;
+
+ // this works for sizeof(int) >= 4
+ int index(int i)
+ {
+ return i >> 5;
+ }
+ int mask(int i)
+ {
+ return 1 << (i & 31);
+ }
+};
Property changes on: trunk/jazz/src/BitSet.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Deleted: trunk/jazz/src/DynamicArray.cpp
===================================================================
--- trunk/jazz/src/DynamicArray.cpp 2013-04-07 23:54:34 UTC (rev 1018)
+++ trunk/jazz/src/DynamicArray.cpp 2013-04-08 03:56:31 UTC (rev 1019)
@@ -1,23 +0,0 @@
-//*****************************************************************************
-// The JAZZ++ Midi Sequencer
-//
-// Copyright (C) 1994-2000 Andreas Voss and Per Sigmond, all rights reserved.
-// Modifications Copyright (C) 2004 Patrick Earl
-// Modifications Copyright (C) 2008-2013 Peter J. Stieber
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//*****************************************************************************
-
-#include "DynamicArray.h"
Modified: trunk/jazz/src/DynamicArray.h
===================================================================
--- trunk/jazz/src/DynamicArray.h 2013-04-07 23:54:34 UTC (rev 1018)
+++ trunk/jazz/src/DynamicArray.h 2013-04-08 03:56:31 UTC (rev 1019)
@@ -1,9 +1,7 @@
//*****************************************************************************
// The JAZZ++ Midi Sequencer
//
-// Copyright (C) 1994-2000 Andreas Voss and Per Sigmond, all rights reserved.
-// Modifications Copyright (C) 2004 Patrick Earl
-// Modifications Copyright (C) 2008-2013 Peter J. Stieber
+// Copyright (C) 2013 Peter J. Stieber
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -23,176 +21,195 @@
#pragma once
#include <cassert>
-#include <vector>
-#define DECLARE_ARRAY(CLASS, TYPE) \
- \
-class CLASS \
-{ \
- public: \
- CLASS(TYPE initVal, int initSize = 0); \
- CLASS(); \
- virtual ~CLASS(); \
- CLASS(const CLASS &); \
- CLASS & operator=(const CLASS &); \
- \
- TYPE & operator[](int i); \
- const TYPE operator[](int i) const; \
- int GetSize() const; \
- protected: \
- void Resize(int newSize); \
- int nArrays; /* Anzahl Arrays */ \
- int block_size; /* Anzahl Elemente je Array */ \
- void Clear(); /* Loescht alle Arrays */ \
- TYPE initVal; \
- TYPE** ppArray; \
+//*****************************************************************************
+// Description:
+// Template version of the macro code macro code listed above.
+//*****************************************************************************
+template <typename TAType>
+class TTDynamicArray
+{
+ public:
+
+ TTDynamicArray();
+
+ TTDynamicArray(TAType InitialValue, int InitialSize = 0);
+
+ TTDynamicArray(const TTDynamicArray& Other);
+
+ virtual ~TTDynamicArray();
+
+ TTDynamicArray& operator = (const TTDynamicArray& Rhs);
+
+ TAType& operator[](int i);
+
+ const TAType operator[](int i) const;
+
+ int GetSize() const;
+
+ protected:
+
+ void Resize(int NewSize);
+
+ // Delete all arrays.
+ void Clear();
+
+ protected:
+
+ // Number of arrays.
+ int mArrayCount;
+
+ // Number of elements per array.
+ int mBlockSize;
+
+ TAType mInitialValue;
+ TAType** mppArray;
};
+//*****************************************************************************
+//*****************************************************************************
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+TTDynamicArray<TAType>::TTDynamicArray()
+ : mArrayCount(0),
+ mBlockSize(16),
+ mInitialValue(0),
+ mppArray(0)
+{
+}
-#define DEFINE_ARRAY(CLASS, TYPE) \
- \
-CLASS::CLASS(TYPE val, int s) : initVal(val) \
-{ \
- nArrays = 0; \
- ppArray = 0; \
- block_size = 16; \
- if (s) Resize(s); \
-} \
- \
-CLASS::CLASS() : initVal(0) \
-{ \
- nArrays = 0; \
- ppArray = 0; \
- block_size = 16; \
-} \
- \
-CLASS::CLASS(const CLASS &X) : initVal(X.initVal) \
-{ \
- int i; \
- nArrays = 0; \
- ppArray = 0; \
- block_size = 16; \
- for (i = 0; i < X.nArrays * block_size; i++) \
- (*this)[i] = (TYPE)X[i]; \
-} \
- \
-void CLASS::Clear() \
-{ \
- int i; \
- for (i = 0; i < nArrays; i++) \
- { \
- delete [] ppArray[i]; \
- } \
- delete [] ppArray; \
- nArrays = 0; \
- ppArray = 0; \
-} \
- \
-CLASS::~CLASS() \
-{ \
- Clear(); \
-} \
- \
-CLASS& CLASS::operator=(const CLASS &X) \
-{ \
- int i; \
- if (&X == this) \
- return *this; \
- Clear(); \
- initVal = X.initVal; \
- block_size = X.block_size; \
- for (i = 0; i < X.nArrays * X.block_size; i++) \
- { \
- (*this)[i] = (TYPE)X[i]; \
- } \
- return *this; \
-} \
- \
-TYPE& CLASS::operator[](int i) \
-{ \
- assert(i >= 0); \
- Resize(i); \
- return ppArray[i / block_size][i % block_size]; \
-} \
- \
-const TYPE CLASS::operator[](int i) const \
-{ \
- assert(i >= 0); \
- int k = i / block_size; \
- if (k >= nArrays || ppArray[k] == 0) \
- { \
- return initVal; \
- } \
- return ppArray[k][i % block_size]; \
-} \
- \
-void CLASS::Resize(int newSize) \
-{ \
- int k = newSize / block_size; \
- if (k >= nArrays) \
- { \
- int i, n = k + 1; \
- TYPE **tmp = new TYPE * [n]; \
- for (i = 0; i < nArrays; i++) \
- { \
- tmp[i] = ppArray[i]; \
- } \
- for (; i < n; i++) \
- { \
- tmp[i] = 0; \
- } \
- delete [] ppArray; \
- ppArray = tmp; \
- nArrays = n; \
- } \
- \
- if (ppArray[k] == 0) \
- { \
- int i; \
- ppArray[k] = new TYPE [block_size]; \
- for (i = 0; i < block_size; i++) \
- { \
- ppArray[k][i] = initVal; \
- } \
- } \
-} \
- \
-int CLASS::GetSize() const \
-{ \
- return nArrays * block_size; \
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+TTDynamicArray<TAType>::TTDynamicArray(TAType InitialValue, int InitialSize)
+ : mArrayCount(0),
+ mBlockSize(16),
+ mInitialValue(InitialValue),
+ mppArray(0)
+{
+ if (InitialSize)
+ {
+ Resize(InitialSize);
+ }
}
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+TTDynamicArray<TAType>::TTDynamicArray(const TTDynamicArray<TAType>& Other)
+ : mArrayCount(0),
+ mBlockSize(16),
+ mInitialValue(Other.mInitialValue)
+ mppArray(0)
+{
+ for (int i = 0; i < Other.mArrayCount * mBlockSize; ++i)
+ {
+ (*this)[i] = Other[i];
+ }
+}
-class JZBitset
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+void TTDynamicArray<TAType>::Clear()
{
- public:
- int operator()(int i)
+ for (int i = 0; i < mArrayCount; ++i)
+ {
+ delete [] mppArray[i];
+ }
+ delete [] mppArray;
+ mArrayCount = 0;
+ mppArray = 0;
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+TTDynamicArray<TAType>::~TTDynamicArray()
+{
+ Clear();
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+TTDynamicArray<TAType>& TTDynamicArray<TAType>::operator = (
+ const TTDynamicArray<TAType>& Rhs)
+{
+ if (&Rhs != this)
+ {
+ Clear();
+ mInitialValue = Rhs.mInitialValue;
+ mBlockSize = Rhs.mBlockSize;
+ for (int i = 0; i < Rhs.mArrayCount * Rhs.mBlockSize; ++i)
{
- return (mArray[index(i)] & mask(i)) != 0;
+ (*this)[i] = Rhs[i];
}
- void set(int i, int b)
- {
- if (b)
- {
- mArray[index(i)] |= mask(i);
- }
- else
- {
- mArray[index(i)] &= ~mask(i);
- }
- }
+ }
+ return *this;
+}
- private:
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+TAType& TTDynamicArray<TAType>::operator[](int i)
+{
+ assert(i >= 0);
+ Resize(i);
+ return mppArray[i / mBlockSize][i % mBlockSize];
+}
- std::vector<int> mArray;
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+const TAType TTDynamicArray<TAType>::operator[](int i) const
+{
+ assert(i >= 0);
+ int k = i / mBlockSize;
+ if (k >= mArrayCount || mppArray[k] == 0)
+ {
+ return mInitialValue;
+ }
+ return mppArray[k][i % mBlockSize];
+}
- // this works for sizeof(int) >= 4
- int index(int i)
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+void TTDynamicArray<TAType>::Resize(int NewSize)
+{
+ int k = NewSize / mBlockSize;
+ if (k >= mArrayCount)
+ {
+ int i, n = k + 1;
+ TAType** ppTemp = new TAType * [n];
+ for (i = 0; i < mArrayCount; i++)
{
- return i >> 5;
+ ppTemp[i] = mppArray[i];
}
- int mask(int i)
+ for (; i < n; ++i)
{
- return 1 << (i & 31);
+ ppTemp[i] = 0;
}
-};
+ delete [] mppArray;
+ mppArray = ppTemp;
+ }
+
+ if (mppArray[k] == 0)
+ {
+ mppArray[k] = new TAType [mBlockSize];
+ for (int i = 0; i < mBlockSize; ++i)
+ {
+ mppArray[k][i] = mInitialValue;
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+template <typename TAType>
+int TTDynamicArray<TAType>::GetSize() const
+{
+ return mArrayCount * mBlockSize;
+}
Modified: trunk/jazz/src/Makefile.am
===================================================================
--- trunk/jazz/src/Makefile.am 2013-04-07 23:54:34 UTC (rev 1018)
+++ trunk/jazz/src/Makefile.am 2013-04-08 03:56:31 UTC (rev 1019)
@@ -49,7 +49,6 @@
Dialogs/VelocityDialog.cpp \
Dialogs.cpp \
DrumUtilities.cpp \
-DynamicArray.cpp \
ErrorMessage.cpp \
Events.cpp \
EventFrame.cpp \
@@ -151,7 +150,6 @@
Dialogs.cpp \
DrumEnums.h \
DrumUtilities.h \
-DynamicArray.cpp \
ErrorMessage.cpp \
Events.cpp \
EventFrame.cpp \
@@ -223,6 +221,7 @@
AsciiMidiFile.h \
Audio.h \
AudioDriver.h \
+BitSet.h \
Command.h \
Configuration.h \
ControlEdit.h \
Modified: trunk/jazz/src/Random.h
===================================================================
--- trunk/jazz/src/Random.h 2013-04-07 23:54:34 UTC (rev 1018)
+++ trunk/jazz/src/Random.h 2013-04-08 03:56:31 UTC (rev 1019)
@@ -24,11 +24,9 @@
#include <wx/window.h>
-#include <iostream>
+#include <iosfwd>
#include <vector>
-#include "DynamicArray.h"
-
//*****************************************************************************
//*****************************************************************************
class JZRandomGenerator
@@ -96,8 +94,8 @@
mArray.resize(nn);
}
- friend std::ostream & operator << (std::ostream &, JZRndArray const &);
- friend std::istream & operator >> (std::istream &, JZRndArray &);
+ friend std::ostream& operator << (std::ostream &, JZRndArray const &);
+ friend std::istream& operator >> (std::istream &, JZRndArray &);
// Returns index 0..n-1 (arrayvalues -> empiric distribution)
int Random();
Modified: trunk/jazz/src/Track.h
===================================================================
--- trunk/jazz/src/Track.h 2013-04-07 23:54:34 UTC (rev 1018)
+++ trunk/jazz/src/Track.h 2013-04-08 03:56:31 UTC (rev 1019)
@@ -22,8 +22,8 @@
#pragma once
+#include "BitSet.h"
#include "DrumEnums.h"
-#include "DynamicArray.h"
#include "Events.h"
#include "NamedValue.h"
Modified: trunk/jazz/src/mswin/WindowsAudioInterface.cpp
===================================================================
--- trunk/jazz/src/mswin/WindowsAudioInterface.cpp 2013-04-07 23:54:34 UTC (rev 1018)
+++ trunk/jazz/src/mswin/WindowsAudioInterface.cpp 2013-04-08 03:56:31 UTC (rev 1019)
@@ -425,10 +425,10 @@
hinp_open = 0;
waveInReset(hinp);
- int n = recbuffers.buffers.GetSize();
+ int n = recbuffers.mBuffers.GetSize();
for (i = 0; i < n; i++)
{
- JZAudioBuffer* buf = recbuffers.buffers[i];
+ JZAudioBuffer* buf = recbuffers.mBuffers[i];
if (buf == 0)
break;
res = waveInUnprepareHeader(hinp, (WAVEHDR *)buf->hdr, sizeof(WAVEHDR));
Modified: trunk/jazz/vc9/JazzPlusPlus-VC9.vcproj
===================================================================
--- trunk/jazz/vc9/JazzPlusPlus-VC9.vcproj 2013-04-07 23:54:34 UTC (rev 1018)
+++ trunk/jazz/vc9/JazzPlusPlus-VC9.vcproj 2013-04-08 03:56:31 UTC (rev 1019)
@@ -450,6 +450,10 @@
>
</File>
<File
+ RelativePath="..\src\BitSet.h"
+ >
+ </File>
+ <File
RelativePath="..\src\Command.cpp"
>
</File>
@@ -494,10 +498,6 @@
>
</File>
<File
- RelativePath="..\src\DynamicArray.cpp"
- >
- </File>
- <File
RelativePath="..\src\DynamicArray.h"
>
</File>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|