Add action for creating new SFZ
This commit is contained in:
parent
8de978df91
commit
36279561a4
1 changed files with 49 additions and 0 deletions
|
|
@ -22,6 +22,7 @@
|
|||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <system_error>
|
||||
#include <fstream>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
|
@ -58,6 +59,7 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
|
|||
enum {
|
||||
kTagLoadSfzFile,
|
||||
kTagEditSfzFile,
|
||||
kTagCreateNewSfzFile,
|
||||
kTagOpenSfzFolder,
|
||||
kTagPreviousSfzFile,
|
||||
kTagNextSfzFile,
|
||||
|
|
@ -135,6 +137,7 @@ struct Editor::Impl : EditorController::Receiver, IControlListener {
|
|||
}
|
||||
|
||||
void chooseSfzFile();
|
||||
void createNewSfzFile();
|
||||
void changeSfzFile(const std::string& filePath);
|
||||
void changeToNextSfzFile(long offset);
|
||||
void chooseScalaFile();
|
||||
|
|
@ -849,6 +852,7 @@ void Editor::Impl::createFrameContents()
|
|||
if (SActionMenu* menu = fileOperationsMenu_) {
|
||||
menu->addEntry("Load file", kTagLoadSfzFile);
|
||||
menu->addEntry("Edit file", kTagEditSfzFile);
|
||||
menu->addEntry("Create new file", kTagCreateNewSfzFile);
|
||||
menu->addEntry("Open SFZ folder", kTagOpenSfzFolder);
|
||||
}
|
||||
|
||||
|
|
@ -914,6 +918,44 @@ void Editor::Impl::chooseSfzFile()
|
|||
}
|
||||
}
|
||||
|
||||
///
|
||||
static const char defaultSfzText[] =
|
||||
"<region>sample=*sine" "\n"
|
||||
"ampeg_attack=0.02 ampeg_release=0.1" "\n";
|
||||
|
||||
static void createDefaultSfzFileIfNotExisting(const fs::path& path)
|
||||
{
|
||||
if (!fs::exists(path))
|
||||
fs::ofstream { path } << defaultSfzText;
|
||||
}
|
||||
|
||||
///
|
||||
void Editor::Impl::createNewSfzFile()
|
||||
{
|
||||
SharedPointer<CNewFileSelector> fs = owned(CNewFileSelector::create(frame_, CNewFileSelector::kSelectSaveFile));
|
||||
|
||||
fs->setTitle("Create SFZ file");
|
||||
fs->setDefaultExtension(CFileExtension("SFZ", "sfz"));
|
||||
|
||||
std::string initialDir = getFileChooserInitialDir(currentSfzFile_);
|
||||
if (!initialDir.empty())
|
||||
fs->setInitialDirectory(initialDir.c_str());
|
||||
|
||||
if (fs->runModal()) {
|
||||
UTF8StringPtr file = fs->getSelectedFile(0);
|
||||
std::string fileStr;
|
||||
if (file && !absl::EndsWithIgnoreCase(file, ".sfz")) {
|
||||
fileStr = std::string(file) + ".sfz";
|
||||
file = fileStr.c_str();
|
||||
}
|
||||
if (file) {
|
||||
createDefaultSfzFileIfNotExisting(fs::u8path(file));
|
||||
changeSfzFile(file);
|
||||
openFileInExternalEditor(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::Impl::changeSfzFile(const std::string& filePath)
|
||||
{
|
||||
ctrl_->uiSendValue(EditId::SfzFile, filePath);
|
||||
|
|
@ -1322,6 +1364,13 @@ void Editor::Impl::valueChanged(CControl* ctl)
|
|||
openFileInExternalEditor(currentSfzFile_.c_str());
|
||||
break;
|
||||
|
||||
case kTagCreateNewSfzFile:
|
||||
if (value != 1)
|
||||
break;
|
||||
|
||||
createNewSfzFile();
|
||||
break;
|
||||
|
||||
case kTagOpenSfzFolder:
|
||||
if (value != 1)
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue