mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-30 16:33:01 +00:00
drop usage of std::deque, part 1
use FixedQueue instead
This commit is contained in:
parent
f9c67460ce
commit
8b565ed284
6 changed files with 84 additions and 19 deletions
|
@ -37,7 +37,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <deque>
|
#include "fixedQueue.h"
|
||||||
|
|
||||||
class DivWorkPool;
|
class DivWorkPool;
|
||||||
|
|
||||||
|
@ -176,14 +176,28 @@ struct DivChannelState {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DivNoteEvent {
|
struct DivNoteEvent {
|
||||||
int channel, ins, note, volume;
|
signed char channel;
|
||||||
bool on;
|
unsigned char ins;
|
||||||
|
signed char note, volume;
|
||||||
|
bool on, nop, pad1, pad2;
|
||||||
DivNoteEvent(int c, int i, int n, int v, bool o):
|
DivNoteEvent(int c, int i, int n, int v, bool o):
|
||||||
channel(c),
|
channel(c),
|
||||||
ins(i),
|
ins(i),
|
||||||
note(n),
|
note(n),
|
||||||
volume(v),
|
volume(v),
|
||||||
on(o) {}
|
on(o),
|
||||||
|
nop(false),
|
||||||
|
pad1(false),
|
||||||
|
pad2(false) {}
|
||||||
|
DivNoteEvent():
|
||||||
|
channel(-1),
|
||||||
|
ins(0),
|
||||||
|
note(0),
|
||||||
|
volume(0),
|
||||||
|
on(false),
|
||||||
|
nop(true),
|
||||||
|
pad1(false),
|
||||||
|
pad2(false) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DivDispatchContainer {
|
struct DivDispatchContainer {
|
||||||
|
@ -428,7 +442,7 @@ class DivEngine {
|
||||||
DivAudioExportModes exportMode;
|
DivAudioExportModes exportMode;
|
||||||
double exportFadeOut;
|
double exportFadeOut;
|
||||||
DivConfig conf;
|
DivConfig conf;
|
||||||
std::deque<DivNoteEvent> pendingNotes;
|
FixedQueue<DivNoteEvent,8192> pendingNotes;
|
||||||
// bitfield
|
// bitfield
|
||||||
unsigned char walked[8192];
|
unsigned char walked[8192];
|
||||||
bool isMuted[DIV_MAX_CHANS];
|
bool isMuted[DIV_MAX_CHANS];
|
||||||
|
|
|
@ -27,11 +27,14 @@ template<typename T, size_t items> struct FixedQueue {
|
||||||
size_t readPos, writePos;
|
size_t readPos, writePos;
|
||||||
T data[items];
|
T data[items];
|
||||||
|
|
||||||
|
T& operator[](size_t pos);
|
||||||
T& front();
|
T& front();
|
||||||
T& back();
|
T& back();
|
||||||
bool pop();
|
bool pop();
|
||||||
bool push(const T& item);
|
bool push(const T& item);
|
||||||
|
|
||||||
|
bool erase(size_t pos);
|
||||||
|
|
||||||
bool pop_front();
|
bool pop_front();
|
||||||
bool pop_back();
|
bool pop_back();
|
||||||
bool push_front(const T& item);
|
bool push_front(const T& item);
|
||||||
|
@ -44,6 +47,13 @@ template<typename T, size_t items> struct FixedQueue {
|
||||||
writePos(0) {}
|
writePos(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T, size_t items> T& FixedQueue<T,items>::operator[](size_t pos) {
|
||||||
|
if (pos>=size()) {
|
||||||
|
logW("accessing invalid position. bug!");
|
||||||
|
}
|
||||||
|
return data[(readPos+pos)%items];
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, size_t items> T& FixedQueue<T,items>::front() {
|
template <typename T, size_t items> T& FixedQueue<T,items>::front() {
|
||||||
return data[readPos];
|
return data[readPos];
|
||||||
}
|
}
|
||||||
|
@ -53,6 +63,36 @@ template <typename T, size_t items> T& FixedQueue<T,items>::back() {
|
||||||
return data[writePos-1];
|
return data[writePos-1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t items> bool FixedQueue<T,items>::erase(size_t pos) {
|
||||||
|
size_t curSize=size();
|
||||||
|
if (pos>=curSize) {
|
||||||
|
logW("accessing invalid position. bug!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (pos==0) {
|
||||||
|
return pop_front();
|
||||||
|
}
|
||||||
|
if (pos==curSize-1) {
|
||||||
|
return pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i=0, p=(readPos+pos)%items, p1=(readPos+pos+1)%items; i<=curSize; i++) {
|
||||||
|
if (p>=items) p-=items;
|
||||||
|
if (p1>=items) p1-=items;
|
||||||
|
data[p]=data[p1];
|
||||||
|
p++;
|
||||||
|
p1++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (writePos>0) {
|
||||||
|
writePos--;
|
||||||
|
} else {
|
||||||
|
writePos=items-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T, size_t items> bool FixedQueue<T,items>::pop() {
|
template <typename T, size_t items> bool FixedQueue<T,items>::pop() {
|
||||||
if (readPos==writePos) return false;
|
if (readPos==writePos) return false;
|
||||||
if (++readPos>=items) readPos=0;
|
if (++readPos>=items) readPos=0;
|
||||||
|
|
|
@ -1346,8 +1346,8 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
|
||||||
isOn[pendingNotes[i].channel]=true;
|
isOn[pendingNotes[i].channel]=true;
|
||||||
} else {
|
} else {
|
||||||
if (isOn[pendingNotes[i].channel]) {
|
if (isOn[pendingNotes[i].channel]) {
|
||||||
logV("erasing off -> on sequence in %d",pendingNotes[i].channel);
|
//logV("erasing off -> on sequence in %d",pendingNotes[i].channel);
|
||||||
pendingNotes.erase(pendingNotes.begin()+i);
|
pendingNotes[i].nop=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1355,7 +1355,7 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
|
||||||
|
|
||||||
while (!pendingNotes.empty()) {
|
while (!pendingNotes.empty()) {
|
||||||
DivNoteEvent& note=pendingNotes.front();
|
DivNoteEvent& note=pendingNotes.front();
|
||||||
if (note.channel<0 || note.channel>=chans) {
|
if (note.nop || note.channel<0 || note.channel>=chans) {
|
||||||
pendingNotes.pop_front();
|
pendingNotes.pop_front();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1847,7 +1847,7 @@ void DivEngine::nextBuf(float** in, float** out, int inChans, int outChans, unsi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logD("%.2x",msg.type);
|
//logD("%.2x",msg.type);
|
||||||
output->midiIn->queue.pop();
|
output->midiIn->queue.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "safeWriter.h"
|
#include "safeWriter.h"
|
||||||
#include "dataErrors.h"
|
#include "dataErrors.h"
|
||||||
#include <deque>
|
#include "fixedQueue.h"
|
||||||
|
|
||||||
enum DivSampleLoopMode: unsigned char {
|
enum DivSampleLoopMode: unsigned char {
|
||||||
DIV_SAMPLE_LOOP_FORWARD=0,
|
DIV_SAMPLE_LOOP_FORWARD=0,
|
||||||
|
@ -144,8 +144,8 @@ struct DivSample {
|
||||||
|
|
||||||
unsigned int samples;
|
unsigned int samples;
|
||||||
|
|
||||||
std::deque<DivSampleHistory*> undoHist;
|
FixedQueue<DivSampleHistory*,128> undoHist;
|
||||||
std::deque<DivSampleHistory*> redoHist;
|
FixedQueue<DivSampleHistory*,128> redoHist;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* put sample data.
|
* put sample data.
|
||||||
|
|
|
@ -2207,7 +2207,7 @@ void FurnaceGUI::pushRecentFile(String path) {
|
||||||
if (path.find(backupPath)==0) return;
|
if (path.find(backupPath)==0) return;
|
||||||
for (int i=0; i<(int)recentFile.size(); i++) {
|
for (int i=0; i<(int)recentFile.size(); i++) {
|
||||||
if (recentFile[i]==path) {
|
if (recentFile[i]==path) {
|
||||||
recentFile.erase(recentFile.begin()+i);
|
recentFile.erase(i);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3948,7 +3948,7 @@ bool FurnaceGUI::loop() {
|
||||||
nextFile=item;
|
nextFile=item;
|
||||||
showWarning("Unsaved changes! Save changes before opening file?",GUI_WARN_OPEN_DROP);
|
showWarning("Unsaved changes! Save changes before opening file?",GUI_WARN_OPEN_DROP);
|
||||||
} else {
|
} else {
|
||||||
recentFile.erase(recentFile.begin()+i);
|
recentFile.erase(i);
|
||||||
i--;
|
i--;
|
||||||
if (load(item)>0) {
|
if (load(item)>0) {
|
||||||
showError(fmt::sprintf("Error while loading file! (%s)",lastError));
|
showError(fmt::sprintf("Error while loading file! (%s)",lastError));
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include "imgui_impl_sdl2.h"
|
#include "imgui_impl_sdl2.h"
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <fftw3.h>
|
#include <fftw3.h>
|
||||||
#include <deque>
|
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <future>
|
#include <future>
|
||||||
|
@ -874,6 +873,18 @@ struct UndoStep {
|
||||||
std::vector<UndoOrderData> ord;
|
std::vector<UndoOrderData> ord;
|
||||||
std::vector<UndoPatternData> pat;
|
std::vector<UndoPatternData> pat;
|
||||||
std::vector<UndoOtherData> other;
|
std::vector<UndoOtherData> other;
|
||||||
|
|
||||||
|
UndoStep():
|
||||||
|
type(GUI_UNDO_CHANGE_ORDER),
|
||||||
|
cursor(),
|
||||||
|
selStart(),
|
||||||
|
selEnd(),
|
||||||
|
order(0),
|
||||||
|
nibble(false),
|
||||||
|
oldOrdersLen(0),
|
||||||
|
newOrdersLen(0),
|
||||||
|
oldPatLen(0),
|
||||||
|
newPatLen(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// -1 = any
|
// -1 = any
|
||||||
|
@ -1323,7 +1334,7 @@ class FurnaceGUI {
|
||||||
|
|
||||||
std::vector<DivSystem> sysSearchResults;
|
std::vector<DivSystem> sysSearchResults;
|
||||||
std::vector<FurnaceGUISysDef> newSongSearchResults;
|
std::vector<FurnaceGUISysDef> newSongSearchResults;
|
||||||
std::deque<String> recentFile;
|
FixedQueue<String,32> recentFile;
|
||||||
std::vector<DivInstrumentType> makeInsTypeList;
|
std::vector<DivInstrumentType> makeInsTypeList;
|
||||||
std::vector<String> availRenderDrivers;
|
std::vector<String> availRenderDrivers;
|
||||||
std::vector<String> availAudioDrivers;
|
std::vector<String> availAudioDrivers;
|
||||||
|
@ -1391,7 +1402,7 @@ class FurnaceGUI {
|
||||||
String backupPath;
|
String backupPath;
|
||||||
|
|
||||||
std::mutex midiLock;
|
std::mutex midiLock;
|
||||||
std::queue<TAMidiMessage> midiQueue;
|
FixedQueue<TAMidiMessage,4096> midiQueue;
|
||||||
MIDIMap midiMap;
|
MIDIMap midiMap;
|
||||||
int learning;
|
int learning;
|
||||||
|
|
||||||
|
@ -2005,8 +2016,8 @@ class FurnaceGUI {
|
||||||
int oldOrdersLen;
|
int oldOrdersLen;
|
||||||
DivOrders oldOrders;
|
DivOrders oldOrders;
|
||||||
DivPattern* oldPat[DIV_MAX_CHANS];
|
DivPattern* oldPat[DIV_MAX_CHANS];
|
||||||
std::deque<UndoStep> undoHist;
|
FixedQueue<UndoStep,256> undoHist;
|
||||||
std::deque<UndoStep> redoHist;
|
FixedQueue<UndoStep,256> redoHist;
|
||||||
|
|
||||||
// sample editor specific
|
// sample editor specific
|
||||||
double sampleZoom;
|
double sampleZoom;
|
||||||
|
|
Loading…
Reference in a new issue