mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-27 15:03:01 +00:00
GUI: drag-and-drop ins/wave/sample loading
This commit is contained in:
parent
5de31f510c
commit
08543a2dc9
4 changed files with 43 additions and 16 deletions
1
TODO.md
1
TODO.md
|
@ -6,7 +6,6 @@
|
||||||
- the last three compat flags
|
- the last three compat flags
|
||||||
- add OPL drum instrument type
|
- add OPL drum instrument type
|
||||||
- Game Boy envelope macro/sequence
|
- Game Boy envelope macro/sequence
|
||||||
- drag-and-drop ins/wave/sample loading
|
|
||||||
- sample editor preview in selection
|
- sample editor preview in selection
|
||||||
- rewrite the system name detection function anyway
|
- rewrite the system name detection function anyway
|
||||||
- unified data view
|
- unified data view
|
||||||
|
|
|
@ -1760,7 +1760,7 @@ int DivEngine::addWave() {
|
||||||
return waveCount;
|
return waveCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DivEngine::addWaveFromFile(const char* path) {
|
bool DivEngine::addWaveFromFile(const char* path, bool addRaw) {
|
||||||
if (song.wave.size()>=256) {
|
if (song.wave.size()>=256) {
|
||||||
lastError="too many wavetables!";
|
lastError="too many wavetables!";
|
||||||
return false;
|
return false;
|
||||||
|
@ -1856,8 +1856,27 @@ bool DivEngine::addWaveFromFile(const char* path) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// read as binary
|
// read as binary
|
||||||
logI("reading binary...");
|
if (addRaw) {
|
||||||
|
logI("reading binary...");
|
||||||
|
len=reader.size();
|
||||||
|
if (len>256) len=256;
|
||||||
|
reader.seek(0,SEEK_SET);
|
||||||
|
for (int i=0; i<len; i++) {
|
||||||
|
wave->data[i]=(unsigned char)reader.readC();
|
||||||
|
if (wave->max<wave->data[i]) wave->max=wave->data[i];
|
||||||
|
}
|
||||||
|
wave->len=len;
|
||||||
|
} else {
|
||||||
|
delete wave;
|
||||||
|
delete[] buf;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (EndOfFileException& e) {
|
||||||
|
// read as binary
|
||||||
|
if (addRaw) {
|
||||||
len=reader.size();
|
len=reader.size();
|
||||||
|
logI("reading binary for being too small...");
|
||||||
if (len>256) len=256;
|
if (len>256) len=256;
|
||||||
reader.seek(0,SEEK_SET);
|
reader.seek(0,SEEK_SET);
|
||||||
for (int i=0; i<len; i++) {
|
for (int i=0; i<len; i++) {
|
||||||
|
@ -1865,18 +1884,11 @@ bool DivEngine::addWaveFromFile(const char* path) {
|
||||||
if (wave->max<wave->data[i]) wave->max=wave->data[i];
|
if (wave->max<wave->data[i]) wave->max=wave->data[i];
|
||||||
}
|
}
|
||||||
wave->len=len;
|
wave->len=len;
|
||||||
|
} else {
|
||||||
|
delete wave;
|
||||||
|
delete[] buf;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} catch (EndOfFileException& e) {
|
|
||||||
// read as binary
|
|
||||||
len=reader.size();
|
|
||||||
logI("reading binary for being too small...");
|
|
||||||
if (len>256) len=256;
|
|
||||||
reader.seek(0,SEEK_SET);
|
|
||||||
for (int i=0; i<len; i++) {
|
|
||||||
wave->data[i]=(unsigned char)reader.readC();
|
|
||||||
if (wave->max<wave->data[i]) wave->max=wave->data[i];
|
|
||||||
}
|
|
||||||
wave->len=len;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (EndOfFileException& e) {
|
} catch (EndOfFileException& e) {
|
||||||
|
|
|
@ -674,7 +674,7 @@ class DivEngine {
|
||||||
int addWave();
|
int addWave();
|
||||||
|
|
||||||
// add wavetable from file
|
// add wavetable from file
|
||||||
bool addWaveFromFile(const char* path);
|
bool addWaveFromFile(const char* path, bool loadRaw=true);
|
||||||
|
|
||||||
// delete wavetable
|
// delete wavetable
|
||||||
void delWave(int index);
|
void delWave(int index);
|
||||||
|
|
|
@ -2544,7 +2544,23 @@ bool FurnaceGUI::loop() {
|
||||||
break;
|
break;
|
||||||
case SDL_DROPFILE:
|
case SDL_DROPFILE:
|
||||||
if (ev.drop.file!=NULL) {
|
if (ev.drop.file!=NULL) {
|
||||||
if (modified) {
|
std::vector<DivInstrument*> instruments=e->instrumentFromFile(ev.drop.file);
|
||||||
|
if (!instruments.empty()) {
|
||||||
|
if (!e->getWarnings().empty()) {
|
||||||
|
showWarning(e->getWarnings(),GUI_WARN_GENERIC);
|
||||||
|
}
|
||||||
|
for (DivInstrument* i: instruments) {
|
||||||
|
e->addInstrumentPtr(i);
|
||||||
|
}
|
||||||
|
nextWindow=GUI_WINDOW_INS_LIST;
|
||||||
|
MARK_MODIFIED;
|
||||||
|
} else if (e->addWaveFromFile(ev.drop.file,false)) {
|
||||||
|
nextWindow=GUI_WINDOW_WAVE_LIST;
|
||||||
|
MARK_MODIFIED;
|
||||||
|
} else if (e->addSampleFromFile(ev.drop.file)!=-1) {
|
||||||
|
nextWindow=GUI_WINDOW_SAMPLE_LIST;
|
||||||
|
MARK_MODIFIED;
|
||||||
|
} else if (modified) {
|
||||||
nextFile=ev.drop.file;
|
nextFile=ev.drop.file;
|
||||||
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 {
|
||||||
|
|
Loading…
Reference in a new issue