Browse Source

Add ui_open/save_file to native plugin API, use it in audiofile

tags/1.9.4
falkTX 11 years ago
parent
commit
b63e28528e
4 changed files with 62 additions and 29 deletions
  1. +3
    -0
      source/backend/CarlaNative.h
  2. +2
    -2
      source/backend/native/Makefile
  3. +13
    -1
      source/backend/native/audiofile.c
  4. +44
    -26
      source/backend/plugin/NativePlugin.cpp

+ 3
- 0
source/backend/CarlaNative.h View File

@@ -144,6 +144,9 @@ typedef struct _HostDescriptor {
void (*ui_custom_data_changed)(HostHandle handle, const char* key, const char* value);
void (*ui_closed)(HostHandle handle);

const char* (*ui_open_file)(HostHandle handle, bool isDir, const char* title, const char* filter);
const char* (*ui_save_file)(HostHandle handle, bool isDir, const char* title, const char* filter);

} HostDescriptor;

typedef struct _PluginDescriptor {


+ 2
- 2
source/backend/native/Makefile View File

@@ -72,10 +72,10 @@ debug:

# --------------------------------------------------------------

%.c.o: %.c
%.c.o: %.c ../CarlaNative.h
$(CC) $< $(BUILD_C_FLAGS) -c -o $@

%.cpp.o: %.cpp
%.cpp.o: %.cpp ../CarlaNative.h ../CarlaNative.hpp
$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@

$(SHARED): $(OBJS) $(LIBS)


+ 13
- 1
source/backend/native/audiofile.c View File

@@ -288,6 +288,18 @@ static void audiofile_set_custom_data(PluginHandle handle, const char* key, cons
audiofile_load_filename(handlePtr, value);
}

static void audiofile_ui_show(PluginHandle handle, bool show)
{
AudioFileInstance* const handlePtr = (AudioFileInstance*)handle;

const char* const filename = handlePtr->host->ui_open_file(handlePtr->host->handle, false, "Open Audio File", "");

if (filename != NULL)
handlePtr->host->ui_custom_data_changed(handlePtr->host->handle, "file", filename);

handlePtr->host->ui_closed(handlePtr->host->handle);
}

static void audiofile_process(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, uint32_t midiEventCount, const MidiEvent* midiEvents)
{
AudioFileInstance* const handlePtr = (AudioFileInstance*)handle;
@@ -394,7 +406,7 @@ static const PluginDescriptor audiofileDesc = {
.set_midi_program = NULL,
.set_custom_data = audiofile_set_custom_data,

.ui_show = NULL,
.ui_show = audiofile_ui_show,
.ui_idle = NULL,

.ui_set_parameter_value = NULL,


+ 44
- 26
source/backend/plugin/NativePlugin.cpp View File

@@ -121,6 +121,8 @@ public:
fHost.ui_parameter_changed = carla_host_ui_parameter_changed;
fHost.ui_custom_data_changed = carla_host_ui_custom_data_changed;
fHost.ui_closed = carla_host_ui_closed;
fHost.ui_open_file = carla_host_ui_open_file;
fHost.ui_save_file = carla_host_ui_save_file;

carla_zeroMem(fMidiEvents, sizeof(::MidiEvent)*MAX_MIDI_EVENTS*2);
}
@@ -490,38 +492,22 @@ public:
CARLA_ASSERT(fDescriptor != nullptr);
CARLA_ASSERT(fHandle != nullptr);

if (fDescriptor != nullptr && fHandle != nullptr)
if (fDescriptor != nullptr && fHandle != nullptr && fDescriptor->ui_show != nullptr)
{
// FIXME - this be as a host-side call to request files
if (fDescriptor->name != nullptr && std::strcmp(fDescriptor->label, "audiofile") == 0)
{
QString filenameTry = QFileDialog::getOpenFileName(nullptr, "Open Audio File");
fDescriptor->ui_show(fHandle, yesNo);

if (! filenameTry.isEmpty())
if (yesNo)
{
// Update UI values, FIXME
if (kData->midiprog.current >= 0)
{
const char* const filename = filenameTry.toUtf8().constData();
setCustomData(CUSTOM_DATA_STRING, "file", filename, false);
const MidiProgramData& mpData = kData->midiprog.getCurrent();
fDescriptor->ui_set_midi_program(fHandle, mpData.bank, mpData.program);
}

kData->engine->callback(CALLBACK_SHOW_GUI, fId, 0, 0, 0.0f, nullptr);
}
else if (fDescriptor->ui_show != nullptr)
{
fDescriptor->ui_show(fHandle, yesNo);

if (yesNo)
for (uint32_t i=0; i < kData->param.count; i++)
{
// Update UI values
if (kData->midiprog.current >= 0)
{
const MidiProgramData& mpData = kData->midiprog.getCurrent();
fDescriptor->ui_set_midi_program(fHandle, mpData.bank, mpData.program);
}

for (uint32_t i=0; i < kData->param.count; i++)
{
fDescriptor->ui_set_parameter_value(fHandle, i, fDescriptor->get_parameter_value(fHandle, i));
}
fDescriptor->ui_set_parameter_value(fHandle, i, fDescriptor->get_parameter_value(fHandle, i));
}
}
}
@@ -1797,6 +1783,28 @@ protected:
fIsUiVisible = false;
}

const char* handleUiOpenFile(const bool isDir, const char* const title, const char* const filter)
{
static CarlaString retStr;

retStr = QFileDialog::getOpenFileName(nullptr, title, "", filter).toUtf8().constData();

return retStr.isNotEmpty() ? (const char*)retStr : nullptr;

// TODO - isDir
}

const char* handleUiSaveFile(const bool isDir, const char* const title, const char* const filter)
{
static CarlaString retStr;

retStr = QFileDialog::getSaveFileName(nullptr, title, "", filter).toUtf8().constData();

return (const char*)retStr;

// TODO - isDir
}

public:
static size_t getPluginCount()
{
@@ -1988,6 +1996,16 @@ private:
handlePtr->handleUiClosed();
}

static const char* carla_host_ui_open_file(HostHandle handle, bool isDir, const char* title, const char* filter)
{
return handlePtr->handleUiOpenFile(isDir, title, filter);
}

static const char* carla_host_ui_save_file(HostHandle handle, bool isDir, const char* title, const char* filter)
{
return handlePtr->handleUiSaveFile(isDir, title, filter);
}

#undef handlePtr
};



Loading…
Cancel
Save