Struct-ize sample map variable

This commit is contained in:
cam900 2022-07-20 23:01:06 +09:00
parent dff7c61b79
commit a5959ae7b9
4 changed files with 40 additions and 24 deletions

View file

@ -2445,8 +2445,8 @@ bool DivEngine::loadFTM(unsigned char* file, size_t len) {
const int dpcmNotes=(blockVersion>=2)?96:72;
for (int j=0; j<dpcmNotes; j++) {
ins->amiga.noteMap[j]=(short)((unsigned char)reader.readC())-1;
ins->amiga.noteFreq[j]=(unsigned char)reader.readC();
ins->amiga.noteMap[j].map=(short)((unsigned char)reader.readC())-1;
ins->amiga.noteMap[j].freq=(unsigned char)reader.readC();
if (blockVersion>=6) {
reader.readC(); // DMC value
}

View file

@ -387,8 +387,12 @@ void DivInstrument::putInsData(SafeWriter* w) {
// sample map
w->writeC(amiga.useNoteMap);
if (amiga.useNoteMap) {
w->write(amiga.noteFreq,120*sizeof(unsigned int));
w->write(amiga.noteMap,120*sizeof(short));
for (int note=0; note<120; note++) {
w->writeI(amiga.noteMap[note].freq);
}
for (int note=0; note<120; note++) {
w->writeS(amiga.noteMap[note].map);
}
}
// N163
@ -932,8 +936,12 @@ DivDataErrors DivInstrument::readInsData(SafeReader& reader, short version) {
if (version>=67) {
amiga.useNoteMap=reader.readC();
if (amiga.useNoteMap) {
reader.read(amiga.noteFreq,120*sizeof(unsigned int));
reader.read(amiga.noteMap,120*sizeof(short));
for (int note=0; note<120; note++) {
amiga.noteMap[note].freq=reader.readI();
}
for (int note=0; note<120; note++) {
amiga.noteMap[note].map=reader.readS();
}
}
}

View file

@ -306,12 +306,18 @@ struct DivInstrumentC64 {
};
struct DivInstrumentAmiga {
struct SampleMap {
int freq;
short map;
SampleMap(int f=0, short m=-1):
freq(f),
map(m) {}
};
short initSample;
bool useNoteMap;
bool useWave;
unsigned char waveLen;
int noteFreq[120];
short noteMap[120];
SampleMap noteMap[120];
/**
* get the sample at specified note.
@ -321,7 +327,7 @@ struct DivInstrumentAmiga {
if (useNoteMap) {
if (note<0) note=0;
if (note>119) note=119;
return noteMap[note];
return noteMap[note].map;
}
return initSample;
}
@ -334,7 +340,7 @@ struct DivInstrumentAmiga {
if (useNoteMap) {
if (note<0) note=0;
if (note>119) note=119;
return noteFreq[note];
return noteMap[note].freq;
}
return -1;
}
@ -344,8 +350,9 @@ struct DivInstrumentAmiga {
useNoteMap(false),
useWave(false),
waveLen(31) {
memset(noteMap,-1,120*sizeof(short));
memset(noteFreq,0,120*sizeof(int));
for (SampleMap& elem: noteMap) {
elem=SampleMap();
}
}
};

View file

@ -3011,7 +3011,7 @@ void FurnaceGUI::drawInsEdit() {
if (ImGui::BeginTable("NoteMap",2,ImGuiTableFlags_ScrollY|ImGuiTableFlags_Borders|ImGuiTableFlags_SizingStretchSame)) {
ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch);
//ImGui::TableSetupColumn("c2",ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupScrollFreeze(0,1);
@ -3022,37 +3022,38 @@ void FurnaceGUI::drawInsEdit() {
/*ImGui::TableNextColumn();
ImGui::Text("Frequency");*/
for (int i=0; i<120; i++) {
DivInstrumentAmiga::SampleMap sampleMap=ins->amiga.noteMap[i];
ImGui::TableNextRow();
ImGui::PushID(fmt::sprintf("NM_%d",i).c_str());
ImGui::TableNextColumn();
ImGui::Text("%s",noteNames[60+i]);
ImGui::TableNextColumn();
if (ins->amiga.noteMap[i]<0 || ins->amiga.noteMap[i]>=e->song.sampleLen) {
if (sampleMap.map<0 || sampleMap.map>=e->song.sampleLen) {
sName="-- empty --";
ins->amiga.noteMap[i]=-1;
sampleMap.map=-1;
} else {
sName=e->song.sample[ins->amiga.noteMap[i]]->name;
sName=e->song.sample[sampleMap.map]->name;
}
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (ImGui::BeginCombo("##SM",sName.c_str())) {
String id;
if (ImGui::Selectable("-- empty --",ins->amiga.noteMap[i]==-1)) { PARAMETER
ins->amiga.noteMap[i]=-1;
if (ImGui::Selectable("-- empty --",sampleMap.map==-1)) { PARAMETER
sampleMap.map=-1;
}
for (int j=0; j<e->song.sampleLen; j++) {
id=fmt::sprintf("%d: %s",j,e->song.sample[j]->name);
if (ImGui::Selectable(id.c_str(),ins->amiga.noteMap[i]==j)) { PARAMETER
ins->amiga.noteMap[i]=j;
if (ins->amiga.noteFreq[i]<=0) ins->amiga.noteFreq[i]=(int)((double)e->song.sample[j]->centerRate*pow(2.0,((double)i-48.0)/12.0));
if (ImGui::Selectable(id.c_str(),sampleMap.map==j)) { PARAMETER
sampleMap.map=j;
if (sampleMap.freq<=0) sampleMap.freq=(int)((double)e->song.sample[j]->centerRate*pow(2.0,((double)i-48.0)/12.0));
}
}
ImGui::EndCombo();
}
/*ImGui::TableNextColumn();
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
if (ImGui::InputInt("##SF",&ins->amiga.noteFreq[i],50,500)) { PARAMETER
if (ins->amiga.noteFreq[i]<0) ins->amiga.noteFreq[i]=0;
if (ins->amiga.noteFreq[i]>262144) ins->amiga.noteFreq[i]=262144;
if (ImGui::InputInt("##SF",&sampleMap.freq,50,500)) { PARAMETER
if (sampleMap.freq<0) sampleMap.freq=0;
if (sampleMap.freq>262144) sampleMap.freq=262144;
}*/
ImGui::PopID();
}