Skip to content

Commit

Permalink
Add PrintCUI.h example file, use it in llvm-test.c example.
Browse files Browse the repository at this point in the history
  • Loading branch information
sletz committed Jan 9, 2020
1 parent 39bd4d6 commit 5d89a9c
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 105 deletions.
2 changes: 1 addition & 1 deletion architecture/faust/dsp/llvm-c-dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ extern "C"
void computeCDSPInstance(llvm_dsp* dsp, int count, FAUSTFLOAT** input, FAUSTFLOAT** output);

/* Set custom memory manager to be used when creating instances */
void setCMemoryManager(llvm_dsp_factory* factory, ManagerGlue* manager);
void setCMemoryManager(llvm_dsp_factory* factory, MemoryManagerGlue* manager);

/**
* Create a Faust DSP instance.
Expand Down
151 changes: 151 additions & 0 deletions architecture/faust/gui/PrintCUI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/************************** BEGIN PrintCUI.h **************************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2020 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/

#ifndef FAUST_PRINTCUI_H
#define FAUST_PRINTCUI_H

#include <stdio.h>
#include "faust/gui/CInterface.h"

/*******************************************************************************
* PrintCUI : Faust User Interface
* This class print arguments given to calls to UI methods and shows how
* a struct can be used inside functions.
******************************************************************************/

// Example of UI with a state
typedef struct PRINTCUI {
int fVar1;
float fVar2;
// Some structure to keep [zone, init, min, max, step] parameters...
} PRINTCUI;

static void ui_open_tab_box(void* iface, const char* label)
{
printf("ui_open_tab_box %s \n", label);
}

static void ui_open_horizontal_box(void* iface, const char* label)
{
printf("ui_open_horizontal_box %s \n", label);
}

static void ui_open_vertical_box(void* iface, const char* label)
{
// Using the 'iface' state
PRINTCUI* cui = (PRINTCUI*)iface;
printf("ui_open_horizontal_box %s %d %f\n", label, cui->fVar1, cui->fVar2);
}

static void ui_close_box(void* iface)
{
printf("ui_close_box\n");
}

static void ui_add_button(void* iface, const char* label, FAUSTFLOAT* zone)
{
printf("ui_add_button %s \n", label);
}

static void ui_add_check_button(void* iface, const char* label, FAUSTFLOAT* zone)
{
printf("ui_add_check_button %s \n", label);
}

static void ui_add_vertical_slider(void* iface, const char* label,
FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
FAUSTFLOAT max, FAUSTFLOAT step)
{
printf("ui_add_vertical_slider %s %f %f %f %f\n", label, init, min, max, step);
}

static void ui_add_horizontal_slider(void *iface, const char *label,
FAUSTFLOAT *zone, FAUSTFLOAT init, FAUSTFLOAT min,
FAUSTFLOAT max, FAUSTFLOAT step)
{
printf("ui_add_vertical_slider %s %f %f %f %f\n", label, init, min, max, step);
}

static void ui_add_num_entry(void* iface, const char* label,
FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
FAUSTFLOAT max, FAUSTFLOAT step)
{
printf("ui_add_num_entry %s %f %f %f %f\n", label, init, min, max, step);
}

static void ui_add_horizontal_bargraph(void* iface, const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{
printf("ui_add_horizontal_bargraph %s %f %f\n", label, min, max);
}

static void ui_add_vertical_bargraph(void* iface, const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{
printf("ui_add_horizontal_bargraph %s %f %f\n", label, min, max);
}

static void ui_add_sound_file(void* iface, const char* label, const char* filename, struct Soundfile** sf_zone)
{
printf("ui_add_sound_file %s %s\n", label, filename);
}

static void ui_declare(void* iface, FAUSTFLOAT *zone, const char *key, const char *val)
{
printf("ui_declare %s, %s\n", key, val);
}

// Example of a structure to be given as 'iface' in functions
PRINTCUI cui = {
.fVar1 = 1,
.fVar2 = 0.5
};

UIGlue uglue = {
.uiInterface = &cui,
.openTabBox = ui_open_tab_box,
.openHorizontalBox = ui_open_horizontal_box,
.openVerticalBox = ui_open_vertical_box,
.closeBox = ui_close_box,
.addButton = ui_add_button,
.addCheckButton = ui_add_check_button,
.addVerticalSlider = ui_add_vertical_slider,
.addHorizontalSlider = ui_add_horizontal_slider,
.addNumEntry = ui_add_num_entry,
.addHorizontalBargraph = ui_add_horizontal_bargraph,
.addVerticalBargraph = ui_add_vertical_bargraph,
.addSoundfile = ui_add_sound_file,
.declare = ui_declare
};

static void meta_declare(void* iface, const char *key, const char *val)
{
printf("meta_declare %s, %s\n", key, val);
}

MetaGlue mglue = {
.metaInterface = NULL,
.declare = meta_declare
};

#endif // FAUST_PRINTCUI_H
/************************** END PrintCUI.h **************************/
4 changes: 2 additions & 2 deletions embedded/faustjava/Faust_wrap.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1435,13 +1435,13 @@ SWIGEXPORT void JNICALL Java_com_grame_faust_FaustJNI_computeCDSPInstance(JNIEnv

SWIGEXPORT void JNICALL Java_com_grame_faust_FaustJNI_setCMemoryManager(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
llvm_dsp_factory *arg1 = (llvm_dsp_factory *) 0 ;
ManagerGlue *arg2 = (ManagerGlue *) 0 ;
MemoryManagerGlue *arg2 = (MemoryManagerGlue *) 0 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(llvm_dsp_factory **)&jarg1;
arg2 = *(ManagerGlue **)&jarg2;
arg2 = *(MemoryManagerGlue **)&jarg2;
setCMemoryManager(arg1,arg2);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/llvm-tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ llvm-test: llvm-test.cpp $(LIB)/libfaust.a
$(CXX) -std=c++11 -O3 llvm-test.cpp -I $(INC) $(LIB)/libfaust.a -lpthread `llvm-config --ldflags --libs all --system-libs` -o llvm-test

llvm-test-c: llvm-test.c $(LIB)/libfaust.a
$(CXX) -std=c++11 -g llvm-test.c -I $(INC) $(LIB)/libfaust.a -lpthread `llvm-config --ldflags --libs all --system-libs` -o llvm-test-c
$(CXX) llvm-test.c -I $(INC) $(LIB)/libfaust.a -lpthread `llvm-config --ldflags --libs all --system-libs` -o llvm-test-c

llvm-algebra-test: llvm-algebra-test.cpp $(LIB)/libfaust.a
$(CXX) -std=c++11 -O3 llvm-algebra-test.cpp -I $(INC) $(LIB)/libfaust.a -lpthread `llvm-config --ldflags --libs all --system-libs` -o llvm-algebra-test
Expand Down
103 changes: 2 additions & 101 deletions tests/llvm-tests/llvm-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,92 +26,14 @@
#include <string.h>

#include "faust/dsp/llvm-c-dsp.h"
#include "faust/gui/PrintCUI.h"

static bool isopt(char* argv[], const char* name)
{
for (int i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return true;
return false;
}

static void meta_declare(void *iface __unused, const char *key, const char *val)
{
printf("meta_declare %s, %s\n", key, val);
}

static void ui_open_tab_box(void* iface __unused, const char* label)
{
printf("ui_open_tab_box %s \n", label);
}

static void ui_open_horizontal_box(void* iface __unused, const char* label)
{
printf("ui_open_horizontal_box %s \n", label);
}

static void ui_open_vertical_box(void* iface __unused, const char* label)
{
printf("ui_open_vertical_box %s \n", label);
}

static void ui_close_box(void* iface __unused)
{
printf("ui_close_box\n");
}

static void ui_add_button(void* iface __unused, const char* label, FAUSTFLOAT* zone)
{
printf("ui_add_button %s \n", label);
}

static void ui_add_check_button(void* iface __unused, const char* label, FAUSTFLOAT* zone)
{
printf("ui_add_check_button %s \n", label);
}

static void ui_add_vertical_slider(void* iface __unused, const char* label,
FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
FAUSTFLOAT max, FAUSTFLOAT step)
{
printf("ui_add_vertical_slider %s %f %f %f %f\n", label, init, min, max, step);
}

static void ui_add_horizontal_slider(void *iface __unused, const char *label,
FAUSTFLOAT *zone, FAUSTFLOAT init, FAUSTFLOAT min,
FAUSTFLOAT max, FAUSTFLOAT step)
{
printf("ui_add_vertical_slider %s %f %f %f %f\n", label, init, min, max, step);
}

static void ui_add_num_entry(void* iface __unused, const char* label,
FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min,
FAUSTFLOAT max, FAUSTFLOAT step)
{
printf("ui_add_num_entry %s %f %f %f %f\n", label, init, min, max, step);
}

static void ui_add_horizontal_bargraph(void* iface __unused, const char* label,
FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{
printf("ui_add_horizontal_bargraph %s %f %f\n", label, min, max);
}

static void ui_add_vertical_bargraph(void* iface __unused, const char* label,
FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{
printf("ui_add_horizontal_bargraph %s %f %f\n", label, min, max);
}

static void ui_add_sound_file(void* iface __unused, const char* label __unused,
const char* filename __unused, struct Soundfile** sf_zone __unused)
{
}

static void ui_declare(void *iface, FAUSTFLOAT *zone __unused,
const char *key, const char *val)
{
printf("ui_declare %s, %s\n", key, val);
}

int main(int argc, const char** argv)
{
if (isopt((char**)argv, "-h") || isopt((char**)argv, "-help")) {
Expand Down Expand Up @@ -149,30 +71,9 @@ int main(int argc, const char** argv)
printf("getNumInputs : %d\n", getNumInputsCDSPInstance(dsp));
printf("getNumOutputs : %d\n", getNumOutputsCDSPInstance(dsp));

MetaGlue mglue = {
.metaInterface = NULL,
.declare = meta_declare
};

// Defined in PrintCUI.h
metadataCDSPInstance(dsp, &mglue);

UIGlue uglue = {
.uiInterface = NULL,
.openTabBox = ui_open_tab_box,
.openHorizontalBox = ui_open_horizontal_box,
.openVerticalBox = ui_open_vertical_box,
.closeBox = ui_close_box,
.addButton = ui_add_button,
.addCheckButton = ui_add_check_button,
.addVerticalSlider = ui_add_vertical_slider,
.addHorizontalSlider = ui_add_horizontal_slider,
.addNumEntry = ui_add_num_entry,
.addHorizontalBargraph = ui_add_horizontal_bargraph,
.addVerticalBargraph = ui_add_vertical_bargraph,
.addSoundfile = ui_add_sound_file,
.declare = ui_declare
};

buildUserInterfaceCDSPInstance(dsp, &uglue);

// Cleanup
Expand Down

0 comments on commit 5d89a9c

Please sign in to comment.