implement .dmc loading
This commit is contained in:
parent
dae7a9a099
commit
a20861559b
|
@ -1469,6 +1469,97 @@ int DivEngine::addSample() {
|
||||||
|
|
||||||
int DivEngine::addSampleFromFile(const char* path) {
|
int DivEngine::addSampleFromFile(const char* path) {
|
||||||
BUSY_BEGIN;
|
BUSY_BEGIN;
|
||||||
|
warnings="";
|
||||||
|
|
||||||
|
const char* pathRedux=strrchr(path,DIR_SEPARATOR);
|
||||||
|
if (pathRedux==NULL) {
|
||||||
|
pathRedux=path;
|
||||||
|
} else {
|
||||||
|
pathRedux++;
|
||||||
|
}
|
||||||
|
String stripPath;
|
||||||
|
const char* pathReduxEnd=strrchr(pathRedux,'.');
|
||||||
|
if (pathReduxEnd==NULL) {
|
||||||
|
stripPath=pathRedux;
|
||||||
|
} else {
|
||||||
|
for (const char* i=pathRedux; i!=pathReduxEnd && (*i); i++) {
|
||||||
|
stripPath+=*i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* ext=strrchr(path,'.');
|
||||||
|
if (ext!=NULL) {
|
||||||
|
String extS;
|
||||||
|
for (; *ext; ext++) {
|
||||||
|
char i=*ext;
|
||||||
|
if (i>='A' && i<='Z') {
|
||||||
|
i+='a'-'A';
|
||||||
|
}
|
||||||
|
extS+=i;
|
||||||
|
}
|
||||||
|
if (extS==String(".dmc")) { // read as .dmc
|
||||||
|
size_t len=0;
|
||||||
|
DivSample* sample=new DivSample;
|
||||||
|
int sampleCount=(int)song.sample.size();
|
||||||
|
sample->name=stripPath;
|
||||||
|
|
||||||
|
FILE* f=fopen(path,"rb");
|
||||||
|
if (f==NULL) {
|
||||||
|
BUSY_END;
|
||||||
|
lastError=fmt::sprintf("could not open file! (%s)",strerror(errno));
|
||||||
|
delete sample;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fseek(f,0,SEEK_END)<0) {
|
||||||
|
fclose(f);
|
||||||
|
BUSY_END;
|
||||||
|
lastError=fmt::sprintf("could not get file length! (%s)",strerror(errno));
|
||||||
|
delete sample;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
len=ftell(f);
|
||||||
|
|
||||||
|
if (len==0) {
|
||||||
|
fclose(f);
|
||||||
|
BUSY_END;
|
||||||
|
lastError="file is empty!";
|
||||||
|
delete sample;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fseek(f,0,SEEK_SET)<0) {
|
||||||
|
fclose(f);
|
||||||
|
BUSY_END;
|
||||||
|
lastError=fmt::sprintf("could not seek to beginning of file! (%s)",strerror(errno));
|
||||||
|
delete sample;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sample->rate=33144;
|
||||||
|
sample->centerRate=33144;
|
||||||
|
sample->depth=1;
|
||||||
|
sample->init(len*8);
|
||||||
|
|
||||||
|
if (fread(sample->dataDPCM,1,len,f)==0) {
|
||||||
|
fclose(f);
|
||||||
|
BUSY_END;
|
||||||
|
lastError=fmt::sprintf("could not read file! (%s)",strerror(errno));
|
||||||
|
delete sample;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
saveLock.lock();
|
||||||
|
song.sample.push_back(sample);
|
||||||
|
song.sampleLen=sampleCount+1;
|
||||||
|
saveLock.unlock();
|
||||||
|
renderSamples();
|
||||||
|
BUSY_END;
|
||||||
|
return sampleCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SF_INFO si;
|
SF_INFO si;
|
||||||
SNDFILE* f=sf_open(path,SFM_READ,&si);
|
SNDFILE* f=sf_open(path,SFM_READ,&si);
|
||||||
if (f==NULL) {
|
if (f==NULL) {
|
||||||
|
@ -1493,13 +1584,7 @@ int DivEngine::addSampleFromFile(const char* path) {
|
||||||
}
|
}
|
||||||
DivSample* sample=new DivSample;
|
DivSample* sample=new DivSample;
|
||||||
int sampleCount=(int)song.sample.size();
|
int sampleCount=(int)song.sample.size();
|
||||||
const char* sName=strrchr(path,DIR_SEPARATOR);
|
sample->name=stripPath;
|
||||||
if (sName==NULL) {
|
|
||||||
sName=path;
|
|
||||||
} else {
|
|
||||||
sName++;
|
|
||||||
}
|
|
||||||
sample->name=sName;
|
|
||||||
|
|
||||||
int index=0;
|
int index=0;
|
||||||
if ((si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM_U8) {
|
if ((si.format&SF_FORMAT_SUBMASK)==SF_FORMAT_PCM_U8) {
|
||||||
|
|
|
@ -1368,9 +1368,9 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
|
||||||
if (!dirExists(workingDirSample)) workingDirSample=getHomeDir();
|
if (!dirExists(workingDirSample)) workingDirSample=getHomeDir();
|
||||||
hasOpened=fileDialog->openLoad(
|
hasOpened=fileDialog->openLoad(
|
||||||
"Load Sample",
|
"Load Sample",
|
||||||
{"Wave file", "*.wav",
|
{"compatible files", "*.wav *.dmc",
|
||||||
"all files", ".*"},
|
"all files", ".*"},
|
||||||
"Wave file{.wav},.*",
|
"compatible files{.wav,.dmc},.*",
|
||||||
workingDirSample,
|
workingDirSample,
|
||||||
dpiScale
|
dpiScale
|
||||||
);
|
);
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
#include "sampleUtil.h"
|
#include "sampleUtil.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// - .dmc loading
|
|
||||||
void FurnaceGUI::drawSampleEdit() {
|
void FurnaceGUI::drawSampleEdit() {
|
||||||
if (nextWindow==GUI_WINDOW_SAMPLE_EDIT) {
|
if (nextWindow==GUI_WINDOW_SAMPLE_EDIT) {
|
||||||
sampleEditOpen=true;
|
sampleEditOpen=true;
|
||||||
|
|
|
@ -2257,6 +2257,7 @@ void FurnaceGUI::applyUISettings(bool updateFonts) {
|
||||||
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".dmp",uiColors[GUI_COLOR_FILE_INSTR],ICON_FA_FILE);
|
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".dmp",uiColors[GUI_COLOR_FILE_INSTR],ICON_FA_FILE);
|
||||||
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".dmw",uiColors[GUI_COLOR_FILE_WAVE],ICON_FA_FILE);
|
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".dmw",uiColors[GUI_COLOR_FILE_WAVE],ICON_FA_FILE);
|
||||||
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".wav",uiColors[GUI_COLOR_FILE_AUDIO],ICON_FA_FILE_AUDIO_O);
|
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".wav",uiColors[GUI_COLOR_FILE_AUDIO],ICON_FA_FILE_AUDIO_O);
|
||||||
|
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".dmc",uiColors[GUI_COLOR_FILE_AUDIO],ICON_FA_FILE_AUDIO_O);
|
||||||
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".vgm",uiColors[GUI_COLOR_FILE_VGM],ICON_FA_FILE_AUDIO_O);
|
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".vgm",uiColors[GUI_COLOR_FILE_VGM],ICON_FA_FILE_AUDIO_O);
|
||||||
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".ttf",uiColors[GUI_COLOR_FILE_FONT],ICON_FA_FONT);
|
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".ttf",uiColors[GUI_COLOR_FILE_FONT],ICON_FA_FONT);
|
||||||
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".otf",uiColors[GUI_COLOR_FILE_FONT],ICON_FA_FONT);
|
ImGuiFileDialog::Instance()->SetFileStyle(IGFD_FileStyleByExtension,".otf",uiColors[GUI_COLOR_FILE_FONT],ICON_FA_FONT);
|
||||||
|
|
Loading…
Reference in a new issue