GUi: add save sample as raw data
This commit is contained in:
parent
27935cec11
commit
ffdff26792
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "sample.h"
|
#include "sample.h"
|
||||||
#include "../ta-log.h"
|
#include "../ta-log.h"
|
||||||
|
#include "../fileutils.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef HAVE_SNDFILE
|
#ifdef HAVE_SNDFILE
|
||||||
|
@ -444,6 +445,28 @@ bool DivSample::save(const char* path) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool DivSample::saveRaw(const char* path) {
|
||||||
|
if (samples<1) {
|
||||||
|
logE("sample is empty though!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE* f=ps_fopen(path,"wb");
|
||||||
|
if (f==NULL) {
|
||||||
|
logE("could not save sample: %s!",strerror(errno));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (depth==DIV_SAMPLE_DEPTH_BRR && getLoopStartPosition(DIV_SAMPLE_DEPTH_BRR)) {\
|
||||||
|
// TODO: BRR loop pos?
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fwrite(getCurBuf(),1,getCurBufLen(),f)!=getCurBufLen()) {
|
||||||
|
logW("did not write entire instrument!");
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// 16-bit memory is padded to 512, to make things easier for ADPCM-A/B.
|
// 16-bit memory is padded to 512, to make things easier for ADPCM-A/B.
|
||||||
bool DivSample::initInternal(DivSampleDepth d, int count) {
|
bool DivSample::initInternal(DivSampleDepth d, int count) {
|
||||||
switch (d) {
|
switch (d) {
|
||||||
|
|
|
@ -201,6 +201,13 @@ struct DivSample {
|
||||||
*/
|
*/
|
||||||
bool save(const char* path);
|
bool save(const char* path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save this sample to a file (raw).
|
||||||
|
* @param path a path.
|
||||||
|
* @return whether saving succeeded or not.
|
||||||
|
*/
|
||||||
|
bool saveRaw(const char* path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @warning DO NOT USE - internal function
|
* @warning DO NOT USE - internal function
|
||||||
* initialize sample data.
|
* initialize sample data.
|
||||||
|
|
|
@ -700,6 +700,11 @@ void FurnaceGUI::drawSampleList(bool asChild) {
|
||||||
if (ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered()) {
|
||||||
ImGui::SetTooltip("Save");
|
ImGui::SetTooltip("Save");
|
||||||
}
|
}
|
||||||
|
if (ImGui::BeginPopupContextItem("SampleSaveOpt")) {
|
||||||
|
if (ImGui::MenuItem("save raw...")) {
|
||||||
|
doAction(GUI_ACTION_SAMPLE_LIST_SAVE_RAW);
|
||||||
|
}
|
||||||
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::ArrowButton("SampleUp",ImGuiDir_Up)) {
|
if (ImGui::ArrowButton("SampleUp",ImGuiDir_Up)) {
|
||||||
doAction(GUI_ACTION_SAMPLE_LIST_MOVE_UP);
|
doAction(GUI_ACTION_SAMPLE_LIST_MOVE_UP);
|
||||||
|
|
|
@ -815,6 +815,9 @@ void FurnaceGUI::doAction(int what) {
|
||||||
case GUI_ACTION_SAMPLE_LIST_SAVE:
|
case GUI_ACTION_SAMPLE_LIST_SAVE:
|
||||||
if (curSample>=0 && curSample<(int)e->song.sample.size()) openFileDialog(GUI_FILE_SAMPLE_SAVE);
|
if (curSample>=0 && curSample<(int)e->song.sample.size()) openFileDialog(GUI_FILE_SAMPLE_SAVE);
|
||||||
break;
|
break;
|
||||||
|
case GUI_ACTION_SAMPLE_LIST_SAVE_RAW:
|
||||||
|
if (curSample>=0 && curSample<(int)e->song.sample.size()) openFileDialog(GUI_FILE_SAMPLE_SAVE_RAW);
|
||||||
|
break;
|
||||||
case GUI_ACTION_SAMPLE_LIST_MOVE_UP:
|
case GUI_ACTION_SAMPLE_LIST_MOVE_UP:
|
||||||
if (e->moveSampleUp(curSample)) {
|
if (e->moveSampleUp(curSample)) {
|
||||||
curSample--;
|
curSample--;
|
||||||
|
|
|
@ -1726,6 +1726,16 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
|
||||||
dpiScale
|
dpiScale
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
case GUI_FILE_SAMPLE_SAVE_RAW:
|
||||||
|
if (!dirExists(workingDirSample)) workingDirSample=getHomeDir();
|
||||||
|
hasOpened=fileDialog->openSave(
|
||||||
|
"Load Raw Sample",
|
||||||
|
{"all files", "*"},
|
||||||
|
".*",
|
||||||
|
workingDirSample,
|
||||||
|
dpiScale
|
||||||
|
);
|
||||||
|
break;
|
||||||
case GUI_FILE_EXPORT_AUDIO_ONE:
|
case GUI_FILE_EXPORT_AUDIO_ONE:
|
||||||
if (!dirExists(workingDirAudioExport)) workingDirAudioExport=getHomeDir();
|
if (!dirExists(workingDirAudioExport)) workingDirAudioExport=getHomeDir();
|
||||||
hasOpened=fileDialog->openSave(
|
hasOpened=fileDialog->openSave(
|
||||||
|
@ -4447,6 +4457,7 @@ bool FurnaceGUI::loop() {
|
||||||
case GUI_FILE_SAMPLE_OPEN_REPLACE:
|
case GUI_FILE_SAMPLE_OPEN_REPLACE:
|
||||||
case GUI_FILE_SAMPLE_OPEN_REPLACE_RAW:
|
case GUI_FILE_SAMPLE_OPEN_REPLACE_RAW:
|
||||||
case GUI_FILE_SAMPLE_SAVE:
|
case GUI_FILE_SAMPLE_SAVE:
|
||||||
|
case GUI_FILE_SAMPLE_SAVE_RAW:
|
||||||
workingDirSample=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
workingDirSample=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
||||||
break;
|
break;
|
||||||
case GUI_FILE_EXPORT_AUDIO_ONE:
|
case GUI_FILE_EXPORT_AUDIO_ONE:
|
||||||
|
@ -4714,7 +4725,16 @@ bool FurnaceGUI::loop() {
|
||||||
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()) {
|
||||||
e->song.sample[curSample]->save(copyOfName.c_str());
|
if (!e->song.sample[curSample]->save(copyOfName.c_str())) {
|
||||||
|
showError("could not save sample! open Log Viewer for more information.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case GUI_FILE_SAMPLE_SAVE_RAW:
|
||||||
|
if (curSample>=0 && curSample<(int)e->song.sample.size()) {
|
||||||
|
if (!e->song.sample[curSample]->saveRaw(copyOfName.c_str())) {
|
||||||
|
showError("could not save sample! open Log Viewer for more information.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GUI_FILE_EXPORT_AUDIO_ONE:
|
case GUI_FILE_EXPORT_AUDIO_ONE:
|
||||||
|
|
|
@ -365,6 +365,7 @@ enum FurnaceGUIFileDialogs {
|
||||||
GUI_FILE_SAMPLE_OPEN_REPLACE,
|
GUI_FILE_SAMPLE_OPEN_REPLACE,
|
||||||
GUI_FILE_SAMPLE_OPEN_REPLACE_RAW,
|
GUI_FILE_SAMPLE_OPEN_REPLACE_RAW,
|
||||||
GUI_FILE_SAMPLE_SAVE,
|
GUI_FILE_SAMPLE_SAVE,
|
||||||
|
GUI_FILE_SAMPLE_SAVE_RAW,
|
||||||
GUI_FILE_EXPORT_AUDIO_ONE,
|
GUI_FILE_EXPORT_AUDIO_ONE,
|
||||||
GUI_FILE_EXPORT_AUDIO_PER_SYS,
|
GUI_FILE_EXPORT_AUDIO_PER_SYS,
|
||||||
GUI_FILE_EXPORT_AUDIO_PER_CHANNEL,
|
GUI_FILE_EXPORT_AUDIO_PER_CHANNEL,
|
||||||
|
@ -591,6 +592,7 @@ enum FurnaceGUIActions {
|
||||||
GUI_ACTION_SAMPLE_LIST_OPEN_RAW,
|
GUI_ACTION_SAMPLE_LIST_OPEN_RAW,
|
||||||
GUI_ACTION_SAMPLE_LIST_OPEN_REPLACE_RAW,
|
GUI_ACTION_SAMPLE_LIST_OPEN_REPLACE_RAW,
|
||||||
GUI_ACTION_SAMPLE_LIST_SAVE,
|
GUI_ACTION_SAMPLE_LIST_SAVE,
|
||||||
|
GUI_ACTION_SAMPLE_LIST_SAVE_RAW,
|
||||||
GUI_ACTION_SAMPLE_LIST_MOVE_UP,
|
GUI_ACTION_SAMPLE_LIST_MOVE_UP,
|
||||||
GUI_ACTION_SAMPLE_LIST_MOVE_DOWN,
|
GUI_ACTION_SAMPLE_LIST_MOVE_DOWN,
|
||||||
GUI_ACTION_SAMPLE_LIST_DELETE,
|
GUI_ACTION_SAMPLE_LIST_DELETE,
|
||||||
|
|
|
@ -636,6 +636,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={
|
||||||
D("SAMPLE_LIST_OPEN_RAW", "Import raw data", 0),
|
D("SAMPLE_LIST_OPEN_RAW", "Import raw data", 0),
|
||||||
D("SAMPLE_LIST_OPEN_REPLACE_RAW", "Import raw data (replace current)", 0),
|
D("SAMPLE_LIST_OPEN_REPLACE_RAW", "Import raw data (replace current)", 0),
|
||||||
D("SAMPLE_LIST_SAVE", "Save", 0),
|
D("SAMPLE_LIST_SAVE", "Save", 0),
|
||||||
|
D("SAMPLE_LIST_SAVE_RAW", "Save (raw)", 0),
|
||||||
D("SAMPLE_LIST_MOVE_UP", "Move up", FURKMOD_SHIFT|SDLK_UP),
|
D("SAMPLE_LIST_MOVE_UP", "Move up", FURKMOD_SHIFT|SDLK_UP),
|
||||||
D("SAMPLE_LIST_MOVE_DOWN", "Move down", FURKMOD_SHIFT|SDLK_DOWN),
|
D("SAMPLE_LIST_MOVE_DOWN", "Move down", FURKMOD_SHIFT|SDLK_DOWN),
|
||||||
D("SAMPLE_LIST_DELETE", "Delete", 0),
|
D("SAMPLE_LIST_DELETE", "Delete", 0),
|
||||||
|
|
|
@ -133,6 +133,12 @@ void FurnaceGUI::drawSampleEdit() {
|
||||||
if (ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered()) {
|
||||||
ImGui::SetTooltip("Open");
|
ImGui::SetTooltip("Open");
|
||||||
}
|
}
|
||||||
|
if (ImGui::BeginPopupContextItem("SampleEOpenOpt")) {
|
||||||
|
if (ImGui::MenuItem("import raw...")) {
|
||||||
|
doAction((curSample>=0 && curSample<(int)e->song.sample.size())?GUI_ACTION_SAMPLE_LIST_OPEN_REPLACE_RAW:GUI_ACTION_SAMPLE_LIST_OPEN_RAW);
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
if (ImGui::Button(ICON_FA_FLOPPY_O "##SESave")) {
|
if (ImGui::Button(ICON_FA_FLOPPY_O "##SESave")) {
|
||||||
doAction(GUI_ACTION_SAMPLE_LIST_SAVE);
|
doAction(GUI_ACTION_SAMPLE_LIST_SAVE);
|
||||||
|
@ -140,6 +146,11 @@ void FurnaceGUI::drawSampleEdit() {
|
||||||
if (ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered()) {
|
||||||
ImGui::SetTooltip("Save");
|
ImGui::SetTooltip("Save");
|
||||||
}
|
}
|
||||||
|
if (ImGui::BeginPopupContextItem("SampleESaveOpt")) {
|
||||||
|
if (ImGui::MenuItem("save raw...")) {
|
||||||
|
doAction(GUI_ACTION_SAMPLE_LIST_SAVE_RAW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue