mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-24 05:25:12 +00:00
GUI: proper sample errors
This commit is contained in:
parent
5a08e0d230
commit
6492eeff56
3 changed files with 12 additions and 7 deletions
|
@ -2142,18 +2142,20 @@ int DivEngine::addSample() {
|
||||||
return sampleCount;
|
return sampleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DivEngine::addSampleFromFile(const char* path) {
|
int DivEngine::addSampleFromFile(const char* path) {
|
||||||
isBusy.lock();
|
isBusy.lock();
|
||||||
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) {
|
||||||
isBusy.unlock();
|
isBusy.unlock();
|
||||||
return false;
|
lastError=fmt::sprintf("could not open file! (%s)",sf_error_number(sf_error(NULL)));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (si.frames>1000000) {
|
if (si.frames>16777215) {
|
||||||
|
lastError="this sample is too big! max sample size is 16777215.";
|
||||||
sf_close(f);
|
sf_close(f);
|
||||||
isBusy.unlock();
|
isBusy.unlock();
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
short* buf=new short[si.channels*si.frames];
|
short* buf=new short[si.channels*si.frames];
|
||||||
if (sf_readf_short(f,buf,si.frames)!=si.frames) {
|
if (sf_readf_short(f,buf,si.frames)!=si.frames) {
|
||||||
|
|
|
@ -489,7 +489,7 @@ class DivEngine {
|
||||||
int addSample();
|
int addSample();
|
||||||
|
|
||||||
// add sample from file
|
// add sample from file
|
||||||
bool addSampleFromFile(const char* path);
|
int addSampleFromFile(const char* path);
|
||||||
|
|
||||||
// delete sample
|
// delete sample
|
||||||
void delSample(int index);
|
void delSample(int index);
|
||||||
|
|
|
@ -2269,8 +2269,11 @@ bool FurnaceGUI::loop() {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GUI_FILE_SAMPLE_OPEN:
|
case GUI_FILE_SAMPLE_OPEN:
|
||||||
e->addSampleFromFile(copyOfName.c_str());
|
if (e->addSampleFromFile(copyOfName.c_str())==-1) {
|
||||||
MARK_MODIFIED;
|
showError(e->getLastError());
|
||||||
|
} else {
|
||||||
|
MARK_MODIFIED;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case GUI_FILE_SAMPLE_SAVE:
|
case GUI_FILE_SAMPLE_SAVE:
|
||||||
if (curSample>=0 && curSample<(int)e->song.sample.size()) {
|
if (curSample>=0 && curSample<(int)e->song.sample.size()) {
|
||||||
|
|
Loading…
Reference in a new issue