From 68336ef3b6b44285ed4edcce624013e8714af5c6 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Fri, 28 Jul 2023 01:14:53 +0200 Subject: [PATCH] - Move URL from github to rx3 - Start UI / GTK implementation - Minor code refactoring --- drummer-mkttl | 4 +- drummer.h | 3 + go.sh | 28 +- lv2_plugin.c | 183 +++++++----- lv2_plugin.h | 108 ++++--- lv2_ui.c | 811 ++++++++++++++++++++++++++++++++++++++++++++++++++ lv2_ui.h | 320 ++++++++++++++++++++ 7 files changed, 1311 insertions(+), 146 deletions(-) create mode 100644 lv2_ui.c create mode 100644 lv2_ui.h diff --git a/drummer-mkttl b/drummer-mkttl index b6af879..c6a1f9b 100755 --- a/drummer-mkttl +++ b/drummer-mkttl @@ -278,6 +278,6 @@ done echo >>${out_file} ' - + a ui:GtkUI ; - ui:binary .' + ui:binary .' diff --git a/drummer.h b/drummer.h index 2553033..6367087 100644 --- a/drummer.h +++ b/drummer.h @@ -20,6 +20,8 @@ #include #include #include +#include + #include @@ -91,6 +93,7 @@ typedef short DRT_Status; #include #include +#include diff --git a/go.sh b/go.sh index bb26f27..913c08c 100755 --- a/go.sh +++ b/go.sh @@ -1,24 +1,36 @@ #!/bin/bash -module_list="libnode.c datastruct.c" -main_list="drummer.c lv2_plugin.c" - -for module in ${module_list} ${main_list} +common_src_list="libnode.c datastruct.c" + main_src_list="drummer.c" + lv2_src_list="lv2_plugin.c lv2_ui.c" +# gtk_includes="-I/usr/include/gtk-3.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0" + gtk_includes="-I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include/ -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0" + includes="-I/usr/include/libxml2 ${gtk_includes}" + cflags="-DGTK_DISABLE_DEPRECATED" + +for module in ${common_src_list} ${main_src_list} ${lv2_src_list} do - cmd="gcc -g -c -I. -I/usr/include/libxml2 -o ${module//.c/.o} -fPIC ${module}" + cmd="gcc -g -c ${cflags} -I. ${includes} -o ${module//.c/.o} -fPIC ${module}" echo ${cmd} eval ${cmd} done +common_libs="-ldl -lpthread -lxml2 -lz -llzma -lm -lsndfile -lsamplerate" +main_libs="" +lv2_libs="" - -cmd="gcc -g -o drummer ${module_list//.c/.o} drummer.o -fPIC -ldl -lpthread -lxml2 -lz -llzma -lm -lsndfile -lsamplerate" +cmd="gcc -g -o drummer ${common_src_list//.c/.o} ${main_src_list//.c/.o} -fPIC ${common_libs} ${main_libs}" echo ${cmd} eval ${cmd} -cmd="gcc -g -o drummer.so ${module_list//.c/.o} lv2_plugin.o -shared -fPIC -ldl -lxml2 -lz -llzma -lm -lsndfile -lsamplerate" +cmd="gcc -g -o drummer.so ${common_src_list//.c/.o} lv2_plugin.o -shared -fPIC ${common_libs} ${lv2_libs}" + +echo ${cmd} +eval ${cmd} + +cmd="gcc -g -o drummer_ui.so ${common_src_list//.c/.o} lv2_ui.o -shared -fPIC ${common_libs} ${lv2_libs}" echo ${cmd} eval ${cmd} diff --git a/lv2_plugin.c b/lv2_plugin.c index 0ef618b..7e06d26 100644 --- a/lv2_plugin.c +++ b/lv2_plugin.c @@ -18,45 +18,50 @@ static int current_kit_changed = 0; /*----------------------------------------------------------------------------*/ -/* */ +/* DR_LV2_Log_Write */ /*----------------------------------------------------------------------------*/ DRT_Status DR_LV2_Log_Write( DRT_Log_Type_Id Log_Type_Id, char *Out_Fmt, va_list Args) { + LV2_URID type; + + switch( Log_Type_Id) { - case DRD_LOG_TYPE_ID_UNKNOWN: - { - break; - } - case DRD_LOG_TYPE_ID_TRACE: { + type = DRG_LV2_Base.Logger.Trace; break; } case DRD_LOG_TYPE_ID_INFO: { - lv2_log_vprintf( &(DRG_LV2_Base.Logger), DRG_LV2_Base.Logger.Note, Out_Fmt, Args); -// lv2_log_note( &(DRG_LV2_Base.Logger), "\n"); - + type = DRG_LV2_Base.Logger.Note; break; } case DRD_LOG_TYPE_ID_WARNING: { + type = DRG_LV2_Base.Logger.Warning; break; } case DRD_LOG_TYPE_ID_ERROR: + case DRD_LOG_TYPE_ID_UNKNOWN: + default: { - lv2_log_vprintf( &(DRG_LV2_Base.Logger), DRG_LV2_Base.Logger.Error, Out_Fmt, Args); -// lv2_log_error( &(DRG_LV2_Base.Logger), "\n"); - + type = DRG_LV2_Base.Logger.Error; break; } + + } + if( lv2_log_vprintf( &(DRG_LV2_Base.Logger), type, Out_Fmt, Args) == 0) + { + fprintf( stderr, "LV2 logger error...\n"); + } + return( DRS_OK); } @@ -64,6 +69,45 @@ DRT_Status DR_LV2_Log_Write( DRT_Log_Type_Id Log_Type_Id, char *Out_Fmt, va_l +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static inline void DR_LV2_Map_URIS( LV2_URID_Map *Map_Ptr, DRT_Drummer_URIS *URIS) +{ + URIS->Atom_Object = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Object); + + URIS->String_URId = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__String); + URIS->Bool_URId = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Bool); + URIS->Int_URId = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Int); + + URIS->Midi_Event = Map_Ptr->map( Map_Ptr->handle, "http://lv2plug.in/ns/ext/midi#MidiEvent"); + + URIS->UI_Msg = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#uimsg"); + + URIS->Atom_EventTransfer = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__eventTransfer); + + URIS->Velocity_Ignore_Flag_Toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#velocitytoggle"); + URIS->Note_Off_Ignore_Flag_Toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#noteofftoggle"); + +/* + URIS->kit_path = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#kitpath"); + URIS->get_state = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#getstate"); + URIS->midi_info = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#midiinfo"); + URIS->sample_trigger = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampletrigger"); + URIS->velocity_toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#velocitytoggle"); + URIS->note_off_toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#noteofftoggle"); + URIS->channel_id = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#channelid"); + URIS->zero_position = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#zeroposition"); + URIS->sample_add = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampleadd"); + URIS->sample_remove = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampleremove"); +*/ +} + + + + + /*----------------------------------------------------------------------------*/ /* */ /*----------------------------------------------------------------------------*/ @@ -202,7 +246,7 @@ static void *DR_LV2_Load_Thread() pthread_mutex_lock( &( DRG_LV2_Base.Load_Mutex)); pthread_cond_wait( &( DRG_LV2_Base.Load_Cond), &( DRG_LV2_Base.Load_Mutex)); - fprintf( stderr, "Load_Thread: New load!\n"); + DR_LOG_INFO_0( "Load_Thread: New load!\n"); pthread_mutex_unlock( &(DRG_LV2_Base.Load_Mutex)); if( ( status = DR_LV2_CurKit_Sample_Load()) != DRS_OK) @@ -210,8 +254,8 @@ static void *DR_LV2_Load_Thread() fprintf( stderr, "Can't load kit sample (%d) !", status); } - pthread_mutex_lock( &(DRG_LV2_Base.Load_Mutex)); - pthread_mutex_unlock( &(DRG_LV2_Base.Load_Mutex)); + pthread_mutex_lock( &(DRG_LV2_Base.Load_Mutex)); + pthread_mutex_unlock( &(DRG_LV2_Base.Load_Mutex)); @@ -266,31 +310,6 @@ static void *DR_LV2_Load_Thread() -/*----------------------------------------------------------------------------*/ -/* */ -/*----------------------------------------------------------------------------*/ -/* -static inline LV2_Atom *build_update_message(DrMr *drmr) -{ - LV2_Atom_Forge_Frame set_frame; - LV2_Atom *msg = (LV2_Atom *)lv2_atom_forge_object( &drmr->forge, &set_frame, 1, drmr->uris.ui_msg); - - - if (drmr->current_path) - { - lv2_atom_forge_property_head( &drmr->forge, drmr->uris.kit_path, 0); - lv2_atom_forge_string( &drmr->forge, drmr->current_path, strlen(drmr->current_path)); - } - - lv2_atom_forge_pop( &drmr->forge,&set_frame); - - return msg; -} -*/ - - - - /*----------------------------------------------------------------------------*/ /* */ /*----------------------------------------------------------------------------*/ @@ -346,6 +365,32 @@ static inline LV2_Atom *DR_LV2_Message_Midi_Info_Build( DRT_LV2_Base *LV2_Base +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_UI_Port_Notify( LV2_URID URId, float Value) +{ + LV2_Atom_Forge_Frame set_frame; + + + lv2_atom_forge_frame_time( &( DRG_LV2_Base.Forge), 0); + + lv2_atom_forge_object( &( DRG_LV2_Base.Forge), &set_frame, 1, DRG_LV2_Base.URIS.UI_Msg); + lv2_atom_forge_property_head( &( DRG_LV2_Base.Forge), URId, 0); + lv2_atom_forge_float( &( DRG_LV2_Base.Forge), Value); + + lv2_atom_forge_pop( &( DRG_LV2_Base.Forge), &set_frame); + + DR_LOG_INFO_2( "Notify: URId: (%d) Value: (%d)!", URId, (int)Value); + + return( DRS_OK); +} + + + + + /*----------------------------------------------------------------------------*/ /* */ /*----------------------------------------------------------------------------*/ @@ -554,10 +599,10 @@ static inline void DR_Sample_UnSustain( uint32_t Offset) /* */ /*----------------------------------------------------------------------------*/ -static LV2_Handle DR_LV2_Instantiate( const LV2_Descriptor *LV2_Descriptor_Ptr, - double SampleRate, - const char *Bundle_Path, - const LV2_Feature* const *LV2_Features_Ptr) +static LV2_Handle DR_LV2_Instantiate( const LV2_Descriptor *LV2_Descriptor_Ptr, + double SampleRate, + const char *Bundle_Path, + const LV2_Feature * const *LV2_Features_Ptr) { DRT_Status status; int i; @@ -627,7 +672,11 @@ static LV2_Handle DR_LV2_Instantiate( const LV2_Descriptor *LV2_Descriptor } else { - if( ( status = DR_DataStruct_Init( DR_LV2_Log_Write, (DRT_SampleRate)SampleRate, DRD_THREAD_NUMBER_DEFAULT)) != DRS_OK) +// lv2_log_logger_init( &(DRG_LV2_Base.Logger), DRG_LV2_Base.Map_Ptr, DRG_LV2_Base.Logger.log); + lv2_log_logger_set_map( &(DRG_LV2_Base.Logger), DRG_LV2_Base.Map_Ptr); + +// if( ( status = DR_DataStruct_Init( DR_LV2_Log_Write, (DRT_SampleRate)SampleRate, DRD_THREAD_NUMBER_DEFAULT)) != DRS_OK) + if( ( status = DR_DataStruct_Init( DRD_LOG_WRITER_DEFAULT, (DRT_SampleRate)SampleRate, DRD_THREAD_NUMBER_DEFAULT)) != DRS_OK) { fprintf( stderr, "Can't init data structures (%d)!\n", status); } @@ -646,7 +695,7 @@ static LV2_Handle DR_LV2_Instantiate( const LV2_Descriptor *LV2_Descriptor } else { - DR_Map_Drummer_URIS( DRG_LV2_Base.Map_Ptr, &(DRG_LV2_Base.URIS)); + DR_LV2_Map_URIS( DRG_LV2_Base.Map_Ptr, &(DRG_LV2_Base.URIS)); lv2_atom_forge_init( &(DRG_LV2_Base.Forge), DRG_LV2_Base.Map_Ptr); @@ -888,7 +937,7 @@ static void DR_LV2_Run( LV2_Handle Instance_Ptr, uint32_t N_Samples) { DR_LOG_INFO_0( "LV2 Event!"); - if( ev_ptr->body.type == lv2_base_ptr->URIS.midi_event) + if( ev_ptr->body.type == lv2_base_ptr->URIS.Midi_Event) { uint8_t nn; uint8_t *const data = (uint8_t *const)(ev_ptr + 1); @@ -923,25 +972,19 @@ static void DR_LV2_Run( LV2_Handle Instance_Ptr, uint32_t N_Samples) if( nn == *( DRG_Base.Velocity_Ignore_Note_Ptr)) { -// *( DRG_Base.Velocity_Ignore_Flag) ^= true; *( DRG_Base.Velocity_Ignore_Flag_Ptr) = (float)( (int)*( DRG_Base.Velocity_Ignore_Flag_Ptr) ^ true); DR_LOG_INFO_2( "Velocity Ignore: [%f] - [%f]", *( DRG_Base.Velocity_Ignore_Flag_Ptr), *( DRG_Base.Velocity_Ignore_Note_Ptr)); + + DR_UI_Port_Notify( DRG_LV2_Base.URIS.Velocity_Ignore_Flag_Toggle, *( DRG_Base.Velocity_Ignore_Flag_Ptr)); } else { if( nn == *( DRG_Base.Note_Off_Ignore_Note_Ptr)) { -// *( DRG_Base.Note_Off_Ignore_Flag) ^= true; *( DRG_Base.Note_Off_Ignore_Flag_Ptr) = (float)( (int)*( DRG_Base.Note_Off_Ignore_Flag_Ptr) ^ true); DR_LOG_INFO_2( "Note Off Ignore: [%f] - [%f]", *( DRG_Base.Note_Off_Ignore_Flag_Ptr), *( DRG_Base.Note_Off_Ignore_Note_Ptr)); -/* - LV2_Atom_Forge_Frame set_frame; - LV2_Atom *msg = (LV2_Atom *)lv2_atom_forge_object( &( lv2_base_ptr->forge), &set_frame, 1, drmr->uris.ui_msg); - lv2_atom_forge_property_head( &( lv2_base_ptr->forge), lv2_base_ptr->URIS.velocity_toggle, 0); - lv2_atom_forge_bool( &( lv2_base_ptr->forge), DRG_Base.Note_Off_Ignore_Flag ? true : false); - lv2_atom_forge_pop( &( lv2_base_ptr->forge), &set_frame); -*/ + DR_UI_Port_Notify( DRG_LV2_Base.URIS.Note_Off_Ignore_Flag_Toggle, *( DRG_Base.Note_Off_Ignore_Flag_Ptr)); } else { @@ -1029,7 +1072,7 @@ static void DR_LV2_Run( LV2_Handle Instance_Ptr, uint32_t N_Samples) } } } - else if( ev_ptr->body.type == lv2_base_ptr->URIS.atom_object) + else if( ev_ptr->body.type == lv2_base_ptr->URIS.Atom_Object) { DR_LOG_INFO_0( "LV2 AO..."); @@ -1134,7 +1177,7 @@ static void DR_LV2_Run( LV2_Handle Instance_Ptr, uint32_t N_Samples) } else { - DR_LOG_WARNING_2( "Unrecognized event (%d) != (%d)", ev_ptr->body.type, lv2_base_ptr->URIS.atom_object); + DR_LOG_WARNING_2( "Unrecognized event (%d) != (%d)", ev_ptr->body.type, lv2_base_ptr->URIS.Atom_Object); } } /* @@ -1356,7 +1399,7 @@ static const LV2_State_Interface DRG_LV2_State_Interface = /*----------------------------------------------------------------------------*/ -/* */ +/* LV2_Extension_Data */ /*----------------------------------------------------------------------------*/ static const void *DR_LV2_Extension_Data( const char *uri) @@ -1375,31 +1418,13 @@ static const void *DR_LV2_Extension_Data( const char *uri) -/*----------------------------------------------------------------------------*/ -/* LV2_Descritor */ -/*----------------------------------------------------------------------------*/ - -static const LV2_Descriptor DRG_LV2_Descriptor = -{ - DRD_DRUMMER_URI, - DR_LV2_Instantiate, - DR_LV2_Connect_Port, - DR_LV2_Activate, - DR_LV2_Run, - DR_LV2_DeActivate, - DR_LV2_Cleanup, - DR_LV2_Extension_Data -}; - - - /*----------------------------------------------------------------------------*/ /* */ /*----------------------------------------------------------------------------*/ -LV2_SYMBOL_EXPORT const LV2_Descriptor *lv2_descriptor( uint32_t index) +LV2_SYMBOL_EXPORT const LV2_Descriptor *lv2_descriptor( uint32_t Index) { - switch (index) + switch( Index) { case 0: { diff --git a/lv2_plugin.h b/lv2_plugin.h index 1bf6011..52f226b 100644 --- a/lv2_plugin.h +++ b/lv2_plugin.h @@ -5,8 +5,6 @@ #ifndef _LV2_PLUGIN_H_ #define _LV2_PLUGIN_H_ -#include - #include "lv2/atom/atom.h" #include "lv2/atom/forge.h" #include "lv2/atom/util.h" @@ -38,6 +36,7 @@ // lv2 stuff #define DRD_DRUMMER_URI "http://rx3.net/AlkorZ3/drummer" + #define DRD_GAIN_MIN -60.0f #define DRD_GAIN_MAX 6.0f #define DRD_VELOCITY_MIN 0 @@ -202,18 +201,25 @@ typedef enum -typedef struct +typedef struct DRT_Drummer_URIS { - LV2_URID atom_object; + LV2_URID Atom_Object; - LV2_URID midi_event; + LV2_URID String_URId; + LV2_URID Bool_URId; + LV2_URID Int_URId; -// LV2_URID ui_msg; + LV2_URID Midi_Event; + + LV2_URID UI_Msg; + + LV2_URID Atom_EventTransfer; + + LV2_URID Velocity_Ignore_Flag_Toggle; + LV2_URID Note_Off_Ignore_Flag_Toggle; + + // LV2_URID kit_path; -// LV2_URID atom_eventTransfer; -// LV2_URID string_urid; -// LV2_URID bool_urid; -// LV2_URID int_urid; // LV2_URID get_state; // LV2_URID midi_info; // LV2_URID sample_trigger; @@ -226,24 +232,7 @@ typedef struct } DRT_Drummer_URIS; -/* -typedef struct -{ - SF_INFO *Info; - char Active; - uint32_t Offset; - uint32_t Limit; - uint32_t Layer_Count; - float Velocity; -// drmr_layer *layers; - float *Data; - int Data_Offset; -} DRT_Sample; -*/ - - - -typedef struct +typedef struct DRT_Sample { DRT_Instrument *Instrument_Ptr; DRT_Layer *Layer_Ptr; @@ -358,33 +347,6 @@ typedef struct -static inline void DR_Map_Drummer_URIS( LV2_URID_Map *Map_Ptr, DRT_Drummer_URIS *URIS) -{ - URIS->atom_object = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Object); - URIS->midi_event = Map_Ptr->map( Map_Ptr->handle, "http://lv2plug.in/ns/ext/midi#MidiEvent"); - - -/* - URIS->string_urid = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__String); - URIS->bool_urid = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Bool); - URIS->int_urid = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Int); - URIS->ui_msg = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#uimsg"); - URIS->kit_path = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#kitpath"); - URIS->get_state = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#getstate"); - URIS->midi_info = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#midiinfo"); - URIS->sample_trigger = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampletrigger"); - URIS->velocity_toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#velocitytoggle"); - URIS->note_off_toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#noteofftoggle"); - URIS->channel_id = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#channelid"); - URIS->zero_position = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#zeroposition"); - URIS->sample_add = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampleadd"); - URIS->sample_remove = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampleremove"); - URIS->atom_eventTransfer = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__eventTransfer); -*/ -} - - - # ifdef _LV2_PLUGIN_C_ @@ -433,6 +395,14 @@ static inline LV2_Atom *DR_LV2_Message_Midi_Info_Build( uint8_t *); +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_UI_Port_Notify( LV2_URID, float); + + + /*----------------------------------------------------------------------------*/ /* */ /*----------------------------------------------------------------------------*/ @@ -481,8 +451,6 @@ static inline void DR_Sample_UnSustain( uint32_t); - - /*----------------------------------------------------------------------------*/ /* */ /*----------------------------------------------------------------------------*/ @@ -565,6 +533,32 @@ LV2_SYMBOL_EXPORT const LV2_Descriptor *lv2_descriptor( uint32_t); +/*----------------------------------------------------------------------------*/ +/* Post Private Definitions */ +/*----------------------------------------------------------------------------*/ + + + +/*----------------------------------------------------------------------------*/ +/* DRG_LV2_Descritor */ +/*----------------------------------------------------------------------------*/ + +static const LV2_Descriptor DRG_LV2_Descriptor = +{ + DRD_DRUMMER_URI, + DR_LV2_Instantiate, + DR_LV2_Connect_Port, + DR_LV2_Activate, + DR_LV2_Run, + DR_LV2_DeActivate, + DR_LV2_Cleanup, + DR_LV2_Extension_Data +}; + + + + + # else // ifdef _LV2_PLUGIN_C_ /*----------------------------------------------------------------------------*/ diff --git a/lv2_ui.c b/lv2_ui.c new file mode 100644 index 0000000..41156b8 --- /dev/null +++ b/lv2_ui.c @@ -0,0 +1,811 @@ +/*----------------------------------------------------------------------------*/ +/* Includes */ +/*----------------------------------------------------------------------------*/ + +#define _LV2_UI_C_ + + + +#include + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Log_Write */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_LV2UI_Log_Write( DRT_Log_Type_Id Log_Type_Id, char *Out_Fmt, va_list Args) +{ + LV2_URID type; + + + switch( Log_Type_Id) + { + case DRD_LOG_TYPE_ID_TRACE: + { + type = DRG_LV2UI_Base.Logger.Trace; + break; + } + + case DRD_LOG_TYPE_ID_INFO: + { + type = DRG_LV2UI_Base.Logger.Note; + break; + } + + case DRD_LOG_TYPE_ID_WARNING: + { + type = DRG_LV2UI_Base.Logger.Warning; + break; + } + + case DRD_LOG_TYPE_ID_ERROR: + case DRD_LOG_TYPE_ID_UNKNOWN: + default: + { + type = DRG_LV2UI_Base.Logger.Error; + break; + } + } + + if( lv2_log_vprintf( &(DRG_LV2UI_Base.Logger), type, Out_Fmt, Args) == 0) + { + fprintf( stderr, "LV2 logger error...\n"); + } + + return( DRS_OK); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Map_URIS */ +/*----------------------------------------------------------------------------*/ + +static inline void DR_LV2UI_Map_URIS( LV2_URID_Map *Map_Ptr, DRT_LV2UI_URIS *URIS) +{ + URIS->Atom_Object = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Object); + + URIS->String_URId = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__String); + URIS->Bool_URId = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Bool); + URIS->Int_URId = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__Int); + + URIS->Midi_Event = Map_Ptr->map( Map_Ptr->handle, "http://lv2plug.in/ns/ext/midi#MidiEvent"); + + URIS->UI_Msg = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#uimsg"); + + URIS->Atom_EventTransfer = Map_Ptr->map( Map_Ptr->handle, LV2_ATOM__eventTransfer); + + URIS->Velocity_Ignore_Flag_Toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#velocitytoggle"); + URIS->Note_Off_Ignore_Flag_Toggle = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#noteofftoggle"); + +/* + URIS->kit_path = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#kitpath"); + URIS->get_state = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#getstate"); + URIS->midi_info = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#midiinfo"); + URIS->sample_trigger = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampletrigger"); + URIS->channel_id = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#channelid"); + URIS->zero_position = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#zeroposition"); + URIS->sample_add = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampleadd"); + URIS->sample_remove = Map_Ptr->map( Map_Ptr->handle, DRD_DRUMMER_URI "#sampleremove"); +*/ + +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static void send_ui_disable( LV2UI_Handle handle) +{ + fprintf( stderr, "send_ui_disable called!\n"); + +/* + EgScopeUI* ui = (EgScopeUI*)handle; + send_ui_state(handle); + + uint8_t obj_buf[64]; + lv2_atom_forge_set_buffer(&ui->forge, obj_buf, sizeof(obj_buf)); + + LV2_Atom_Forge_Frame frame; + LV2_Atom* msg = + (LV2_Atom*)lv2_atom_forge_object(&ui->forge, &frame, 0, ui->uris.ui_Off); + + assert(msg); + + lv2_atom_forge_pop(&ui->forge, &frame); + ui->write(ui->controller, + 0, + lv2_atom_total_size(msg), + ui->uris.atom_eventTransfer, + msg); + */ +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static void send_ui_enable(LV2UI_Handle handle) +{ + fprintf( stderr, "send_ui_enable called!\n"); + +/* + EgScopeUI* ui = (EgScopeUI*)handle; + + uint8_t obj_buf[64]; + lv2_atom_forge_set_buffer(&ui->forge, obj_buf, sizeof(obj_buf)); + + LV2_Atom_Forge_Frame frame; + LV2_Atom* msg = + (LV2_Atom*)lv2_atom_forge_object(&ui->forge, &frame, 0, ui->uris.ui_On); + + assert(msg); + + lv2_atom_forge_pop(&ui->forge, &frame); + ui->write(ui->controller, + 0, + lv2_atom_total_size(msg), + ui->uris.atom_eventTransfer, + msg); +*/ +} + + + + + +/*----------------------------------------------------------------------------*/ +/* */ +/*----------------------------------------------------------------------------*/ + +static gboolean on_cfg_changed( GtkWidget *widget, gpointer data) +{ + fprintf( stderr, "on_cfg_changed called!\n"); + +/* + EgScopeUI* ui = (EgScopeUI*)data; + if (!ui->updating) { + // Only send UI state if the change is from user interaction + send_ui_state(data); + } +*/ + return TRUE; +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Expose_Callback */ +/*----------------------------------------------------------------------------*/ + +static gulong DRG_LV2UI_Expose_Id; + +static gboolean DR_LV2UI_Expose_Callback (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + DR_LOG_INFO_0( "Expose Callback called!"); + + /* + DrMrUi *ui = (DrMrUi*)data; + uint8_t msg_buf[1024]; + lv2_atom_forge_set_buffer(&ui->forge, msg_buf, 1024); + LV2_Atom *msg = build_get_state_message(ui); + ui->write(ui->controller,DRMR_CONTROL, + lv2_atom_total_size(msg), + ui->uris.atom_eventTransfer, + msg); + g_signal_handler_disconnect(widget,expose_id); + */ + + + + return FALSE; +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Channel_Id_ComboBox_Create */ +/*----------------------------------------------------------------------------*/ + +static GtkWidget *DR_LV2UI_Channel_Id_ComboBox_Create( void) +{ + GtkWidget *combobox_ptr; + GtkListStore *list_store_ptr; + GtkCellRenderer *cell_ptr; + GtkTreeIter iter; + int i; + char label[8]; + + + list_store_ptr = gtk_list_store_new( 1, G_TYPE_STRING); + + gtk_list_store_append( list_store_ptr, &iter); + gtk_list_store_set( list_store_ptr, &iter, 0, "Omni", -1); + + for( i = 1; i <= 16; i++) + { + sprintf( label, "%02d", i); + gtk_list_store_append( list_store_ptr, &iter); + gtk_list_store_set( list_store_ptr, &iter, 0, label, -1); + } + + combobox_ptr = gtk_combo_box_new_with_model( GTK_TREE_MODEL( list_store_ptr)); + + gtk_combo_box_set_active( GTK_COMBO_BOX( combobox_ptr), 0); + + g_object_unref( list_store_ptr); + + cell_ptr = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combobox_ptr), cell_ptr, TRUE); + gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( combobox_ptr), cell_ptr, "text", 0, NULL); + + return( combobox_ptr); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Channel_Id_ComboBox_Change */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Channel_Id_ComboBox_Changed( GtkComboBox *ComboBox_Ptr, gpointer Data_Ptr) +{ + DRG_LV2UI_Base.Channel_Id = (float)gtk_combo_box_get_active( GTK_COMBO_BOX( ComboBox_Ptr)); + + DR_LOG_INFO_1( "Channel_Id_ComboBox_Changed: Id: (%d)!", (int)( DRG_LV2UI_Base.Channel_Id)); + + DRG_LV2UI_Base.Write( DRG_LV2UI_Base.Controller, DRD_LV2_CHANNEL_ID, 4, 0, &( DRG_LV2UI_Base.Channel_Id)); + +// return( FALSE); +} + + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Base_Note_Spin_Change */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Base_Note_Label_Set( int Note_Id) +{ + int oct = ( Note_Id / 12) - 1; + int nmt = ( Note_Id % 12) * 2; + + + snprintf( DRG_LV2UI_Base.Base_Note_Label_Buf, 32, "Midi Base Note (%c%c%i):", DRG_LV2UI_Note_String[nmt], DRG_LV2UI_Note_String[nmt+1], oct); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Base_Note_Spin_Change */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Base_Note_Spin_Changed( GtkSpinButton *Spin_Ptr, gpointer Data_Ptr) +{ + float base = (float)gtk_spin_button_get_value( Spin_Ptr); + + + if( base >= 21.0f && base <= 107.0f) + { + DRG_LV2UI_Base.Base_Note = base; + + DR_LOG_INFO_1( "Channel_Id_ComboBox_Changed: Id: (%d)!", (int)( base)); + + DRG_LV2UI_Base.Write( DRG_LV2UI_Base.Controller, DRD_LV2_BASE_NOTE, 4, 0, &( DRG_LV2UI_Base.Base_Note)); + + DR_LV2UI_Base_Note_Label_Set( (int)base); + gtk_label_set_markup( GTK_LABEL( DRG_LV2UI_Base.Base_Note_Label_Ptr), DRG_LV2UI_Base.Base_Note_Label_Buf); + } + else + { + fprintf( stderr,"Base spin got out of range: %f\n",base); + } +} + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Position_Id_ComboBox_Create */ +/*----------------------------------------------------------------------------*/ + +static GtkWidget *DR_LV2UI_Position_Id_ComboBox_Create( void) +{ + GtkWidget *combobox_ptr; + GtkListStore *list_store_ptr; + GtkCellRenderer *cell_ptr; + GtkTreeIter iter; + + + list_store_ptr = gtk_list_store_new( 1, G_TYPE_STRING); + + gtk_list_store_append( list_store_ptr, &iter); + gtk_list_store_set( list_store_ptr, &iter, 0, "Top Left", -1); + gtk_list_store_append( list_store_ptr, &iter); + gtk_list_store_set( list_store_ptr, &iter, 0, "Bottom Left", -1); + gtk_list_store_append( list_store_ptr, &iter); + gtk_list_store_set( list_store_ptr, &iter, 0, "Top Right", -1); + gtk_list_store_append( list_store_ptr, &iter); + gtk_list_store_set( list_store_ptr, &iter, 0, "Bottom Right", -1); + + combobox_ptr = gtk_combo_box_new_with_model( GTK_TREE_MODEL( list_store_ptr)); + + gtk_combo_box_set_active( GTK_COMBO_BOX( combobox_ptr), 0); + + g_object_unref( list_store_ptr); + + cell_ptr = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combobox_ptr), cell_ptr, TRUE); + gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( combobox_ptr), cell_ptr, "text", 0, NULL); + + return( combobox_ptr); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Position_Id_ComboBox_Change */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Position_Id_ComboBox_Changed( GtkComboBox *ComboBox_Ptr, gpointer Data_Ptr) +{ + DRG_LV2UI_Base.Position_Id = (float)gtk_combo_box_get_active( GTK_COMBO_BOX( ComboBox_Ptr)); + + DR_LOG_INFO_1( "Position_Id_ComboBox_Changed: Id: (%d)!", (int)( DRG_LV2UI_Base.Position_Id)); + +// DRG_LV2UI_Base.Write( DRG_LV2UI_Base.Controller, DRD_LV2_POSITION_ID, 4, 0, &( DRG_LV2UI_Base.Position_Id)); + +// return( FALSE); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Velocity_Ignore_Flag_Toggled */ +/*----------------------------------------------------------------------------*/ + +static gboolean DR_LV2UI_Velocity_Ignore_Flag_Toggled( GtkToggleButton *Button_Ptr, gpointer Data_Ptr) +{ + DRG_LV2UI_Base.Velocity_Ignore_Flag = (float)gtk_toggle_button_get_active( Button_Ptr); + + DR_LOG_INFO_1( "Velocity_Ignore_Flag_Toggled called: State: (%d)!", (int)( DRG_LV2UI_Base.Velocity_Ignore_Flag)); + + DRG_LV2UI_Base.Write( DRG_LV2UI_Base.Controller, DRD_LV2_VELOCITY_IGNORE_FLAG, 4, 0, &( DRG_LV2UI_Base.Velocity_Ignore_Flag)); + + return( FALSE); +} + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Note_Off_Ignore_Flag_Toggled */ +/*----------------------------------------------------------------------------*/ + +static gboolean DR_LV2UI_Note_Off_Ignore_Flag_Toggled( GtkToggleButton *Button_Ptr, gpointer Data_Ptr) +{ + DRG_LV2UI_Base.Note_Off_Ignore_Flag = (float)gtk_toggle_button_get_active( Button_Ptr); + + DR_LOG_INFO_1( "Note_Off_Ignore_Flag_Toggled called: State: (%d)!", (int)( DRG_LV2UI_Base.Note_Off_Ignore_Flag)); + + DRG_LV2UI_Base.Write( DRG_LV2UI_Base.Controller, DRD_LV2_NOTE_OFF_IGNORE_FLAG, 4, 0, &( DRG_LV2UI_Base.Note_Off_Ignore_Flag)); + + return( FALSE); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Build */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_LV2UI_UI_Build( GtkWidget **Main_Widget_Ptr_Ptr) +{ + GtkWidget *opts_hbox1_ptr, *opts_hbox2_ptr, *channel_id_hbox_ptr, *position_id_hbox_ptr, + *channel_id_label_ptr, *channel_id_combobox_ptr, *position_id_label_ptr, *position_id_combobox_ptr, *base_note_label_ptr, *base_note_spin_ptr, *velocity_ignore_flag_checkbox_ptr, *note_off_ignore_flag_checkbox_ptr; + GtkLabel *label_ptr; + GtkAdjustment *base_note_adj_ptr; + + *Main_Widget_Ptr_Ptr = gtk_vbox_new( false, 0); + DRG_LV2UI_Expose_Id = g_signal_connect( *Main_Widget_Ptr_Ptr, "expose-event", G_CALLBACK( DR_LV2UI_Expose_Callback), &DRG_LV2UI_Base); + + g_object_set( *Main_Widget_Ptr_Ptr, "border-width", 6, NULL); + + label_ptr = GTK_LABEL( gtk_label_new( "Test!")); + + /* Option Boxes */ + + opts_hbox1_ptr = gtk_hbox_new( false, 0); + opts_hbox2_ptr = gtk_hbox_new( false, 0); + + // Midi Channel_Id + channel_id_hbox_ptr = gtk_hbox_new( false, 0); + channel_id_label_ptr = gtk_label_new( "Midi Channel: "); + + channel_id_combobox_ptr = DR_LV2UI_Channel_Id_ComboBox_Create(); + gtk_box_pack_start( GTK_BOX( channel_id_hbox_ptr), channel_id_label_ptr, true, false, 0); + gtk_box_pack_start( GTK_BOX( channel_id_hbox_ptr), channel_id_combobox_ptr, false, false, 0); + + // Midi Base Note + base_note_label_ptr = gtk_label_new("Midi Base Note (C 2):"); + gtk_label_set_use_markup( GTK_LABEL( base_note_label_ptr), true); + base_note_adj_ptr = GTK_ADJUSTMENT( gtk_adjustment_new( 36.0, // val + 21.0,107.0, // min/max + 1.0, // step + 5.0,0.0)); // page adj/size + + base_note_spin_ptr = gtk_spin_button_new( base_note_adj_ptr, 1.0, 0); + + // Sample Zero Position Id + position_id_hbox_ptr = gtk_hbox_new( false, 0); + position_id_label_ptr = gtk_label_new( "Sample Zero Position: "); + + position_id_combobox_ptr = DR_LV2UI_Position_Id_ComboBox_Create(); + gtk_box_pack_start( GTK_BOX( position_id_hbox_ptr), position_id_label_ptr, true, false, 0); + gtk_box_pack_start( GTK_BOX( position_id_hbox_ptr), position_id_combobox_ptr, false, false, 0); + + // Velocity Ignore + velocity_ignore_flag_checkbox_ptr = gtk_check_button_new_with_label( "Ignore Velocity"); + + // Note Off Ignore + note_off_ignore_flag_checkbox_ptr = gtk_check_button_new_with_label( "Ignore Note Off"); + + + gtk_box_pack_start( GTK_BOX( opts_hbox1_ptr), base_note_label_ptr, false, false, 15); + gtk_box_pack_start( GTK_BOX( opts_hbox1_ptr), base_note_spin_ptr, true, true, 0); + + gtk_box_pack_start( GTK_BOX( opts_hbox2_ptr), channel_id_hbox_ptr, true, false, 0); + gtk_box_pack_start( GTK_BOX( opts_hbox2_ptr), position_id_hbox_ptr, true, false, 0); + gtk_box_pack_start( GTK_BOX( opts_hbox2_ptr), velocity_ignore_flag_checkbox_ptr, true, false, 15); + gtk_box_pack_start( GTK_BOX( opts_hbox2_ptr), note_off_ignore_flag_checkbox_ptr, true, true, 15); + + gtk_box_pack_start( GTK_BOX( *Main_Widget_Ptr_Ptr), GTK_WIDGET( label_ptr), false, false, 5); + gtk_box_pack_start( GTK_BOX( *Main_Widget_Ptr_Ptr), opts_hbox1_ptr, false, false, 5); + gtk_box_pack_start( GTK_BOX( *Main_Widget_Ptr_Ptr), opts_hbox2_ptr, false, false, 5); + + // Signals +// g_signal_connect( G_OBJECT( kit_combo_box), "changed", G_CALLBACK( kit_combobox_changed), &DRG_LV2UI_Note); +// g_signal_connect( G_OBJECT( base_note_spin_ptr), "value-changed", G_CALLBACK( DR_LV2UI_Base_Note_Note_Changed), &DRG_LV2UI_Base); + g_signal_connect( G_OBJECT( channel_id_combobox_ptr), "changed", G_CALLBACK( DR_LV2UI_Channel_Id_ComboBox_Changed), &DRG_LV2UI_Base); + g_signal_connect( G_OBJECT( position_id_combobox_ptr), "changed", G_CALLBACK( DR_LV2UI_Position_Id_ComboBox_Changed), &DRG_LV2UI_Base); + g_signal_connect( G_OBJECT( velocity_ignore_flag_checkbox_ptr), "toggled", G_CALLBACK( DR_LV2UI_Velocity_Ignore_Flag_Toggled), &DRG_LV2UI_Base); + g_signal_connect( G_OBJECT( note_off_ignore_flag_checkbox_ptr), "toggled", G_CALLBACK( DR_LV2UI_Note_Off_Ignore_Flag_Toggled), &DRG_LV2UI_Base); + + + // Save + DRG_LV2UI_Base.Main_Widget_Ptr = *Main_Widget_Ptr_Ptr; + DRG_LV2UI_Base.Channel_ComboBox_Ptr = channel_id_combobox_ptr; + DRG_LV2UI_Base.Base_Note_Spin_Ptr = base_note_spin_ptr; + DRG_LV2UI_Base.Base_Note_Label_Ptr = base_note_label_ptr; + DRG_LV2UI_Base.Position_ComboBox_Ptr = position_id_combobox_ptr; +// DRG_LV2UI_Base.Velocity_Ignore_Note_Spin_Ptr = velocity_ignore_note_spin_ptr; +// DRG_LV2UI_Base.Note_Off_Ignore_Note_Spin_Ptr = note_off_ignore_note_spin_ptr; + DRG_LV2UI_Base.Velocity_Ignore_Flag_CheckBox_Ptr = velocity_ignore_flag_checkbox_ptr; + DRG_LV2UI_Base.Note_Off_Ignore_Flag_CheckBox_Ptr = note_off_ignore_flag_checkbox_ptr; + + gtk_widget_show_all( *Main_Widget_Ptr_Ptr); + + DR_LOG_INFO_0( "UI Build completed!"); + + return( DRS_OK); +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Instantiate */ +/*----------------------------------------------------------------------------*/ + +static LV2UI_Handle DR_LV2UI_Instantiate( const LV2UI_Descriptor *LV2UI_Descriptor, + const char *Plugin_URI, + const char *Bundle_Path, + LV2UI_Write_Function Write_Function, + LV2UI_Controller Controller, + LV2UI_Widget *Widget_Ptr_Ptr, + const LV2_Feature * const *LV2_Features_Ptr) +{ + DRT_Status status; + + + fprintf( stderr, "instanciate called!\n"); + + DRG_LV2UI_Base.Write = Write_Function; + DRG_LV2UI_Base.Controller = Controller; + *Widget_Ptr_Ptr = NULL; + + DRG_LV2UI_Base.Velocity_Ignore_Flag = 0; + DRG_LV2UI_Base.Note_Off_Ignore_Flag = 0; + + while( *LV2_Features_Ptr != NULL) + { + fprintf( stderr, "Feature URI: [%s]\n", (*LV2_Features_Ptr)->URI); + + if( !strcmp( ( *LV2_Features_Ptr)->URI, LV2_URID_URI "#map")) + { + DRG_LV2UI_Base.Map_Ptr = (LV2_URID_Map *)( ( *LV2_Features_Ptr)->data); + } + else + { + if( !strcmp( ( *LV2_Features_Ptr)->URI, LV2_LOG__log)) + { + DRG_LV2UI_Base.Logger.log = (LV2_Log_Log *)( ( *LV2_Features_Ptr)->data); + } + } + + LV2_Features_Ptr++; + } + + if( ( DRG_LV2UI_Base.Map_Ptr == NULL) || ( DRG_LV2UI_Base.Logger.log == NULL)) + { + if( DRG_LV2UI_Base.Map_Ptr == NULL) + { + fprintf( stderr, "LV2 host does not support urid#map!\n"); + } + + if( DRG_LV2UI_Base.Logger.log == NULL) + { + fprintf( stderr, "LV2 host does not support log#log!\n"); + } + + return( NULL); + } + else + { +// lv2_log_logger_init( &(DRG_LV2UI_Base.Logger), DRG_LV2UI_Base.Map_Ptr, DRG_LV2UI_Base.Logger.log); + lv2_log_logger_set_map( &(DRG_LV2UI_Base.Logger), DRG_LV2UI_Base.Map_Ptr); + + DRG_Base.Log_Stream_Out = stderr; + DRG_Base.Log_Writer_Ptr = DRD_LOG_WRITER_DEFAULT; + + if( ( status = DR_DataStruct_Init( DRD_LOG_WRITER_DEFAULT, DRD_SAMPLE_RATE_DEFAULT, DRD_THREAD_NUMBER_DEFAULT)) != DRS_OK) + { + fprintf( stderr, "Can't init data structures (%d)!\n", status); + } + else + { + lv2_log_error( &(DRG_LV2UI_Base.Logger), "UI: Test error log <%s>!\n", "Krash!"); + DR_LOG_ERROR_1( "Test error log <%s>!", "Krash!"); + + DR_LV2UI_Map_URIS( DRG_LV2UI_Base.Map_Ptr, &(DRG_LV2UI_Base.URIS)); + + lv2_atom_forge_init( &(DRG_LV2UI_Base.Forge), DRG_LV2UI_Base.Map_Ptr); + + if( ( status = DR_Kits_Load()) != DRS_OK) + { + fprintf( stderr, "Can't load kits (%d)!\n", status); + } + else + { + if( DR_LV2UI_UI_Build( (GtkWidget **)Widget_Ptr_Ptr) != DRS_OK) + { + return( NULL); + } + else + { + return( &DRG_LV2UI_Base); + } + } + } + + DR_DataStruct_DeInit(); + } +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Cleanup */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Cleanup( LV2UI_Handle Instance_Ptr) +{ + fprintf( stderr, "cleanup called!\n"); + +/* + EgScopeUI* ui = (EgScopeUI*)handle; +*/ + /* Send UIOff message to plugin, which will save state and disable message + * transmission. */ +/* + send_ui_disable(ui); + gtk_widget_destroy(ui->darea); + free(ui); +*/ +} + + + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Port_Event */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Port_Event( LV2UI_Handle Instance_Ptr, + uint32_t Port_Id, + uint32_t Buffer_size, + uint32_t Format, + const void *Buffer_Ptr) +{ +// DR_LOG_INFO_2( "Port_Event called: Port: (%d) Format: (%d)!", Port_Id, Format); + + if( Port_Id == DRD_LV2_CORE_EVENT) + { + DR_LOG_INFO_0( "Port_Event called: Core Event!"); + + if( Format == DRG_LV2UI_Base.URIS.Atom_EventTransfer) + { + LV2_Atom *atom = (LV2_Atom *)Buffer_Ptr; + + if( atom->type == DRG_LV2UI_Base.URIS.Atom_Object) + { + LV2_Atom_Object *obj = (LV2_Atom_Object *)atom; + + if( obj->body.otype == DRG_LV2UI_Base.URIS.UI_Msg) + { + const LV2_Atom *velocity_ignore_flag_ptr = NULL; + const LV2_Atom *note_off_ignore_flag_ptr = NULL; + + lv2_atom_object_get( obj, + DRG_LV2UI_Base.URIS.Velocity_Ignore_Flag_Toggle, &velocity_ignore_flag_ptr, + DRG_LV2UI_Base.URIS.Note_Off_Ignore_Flag_Toggle, ¬e_off_ignore_flag_ptr, + NULL); + + if( velocity_ignore_flag_ptr) + { + DRG_LV2UI_Base.Velocity_Ignore_Flag = ( (const LV2_Atom_Float *)velocity_ignore_flag_ptr)->body; + + DR_LOG_INFO_1( "UI Msg: Velocity Ignore Flag: (%f)!", DRG_LV2UI_Base.Velocity_Ignore_Flag); + + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( DRG_LV2UI_Base.Velocity_Ignore_Flag_CheckBox_Ptr), (int)( DRG_LV2UI_Base.Velocity_Ignore_Flag)); + } + + if( note_off_ignore_flag_ptr) + { + DRG_LV2UI_Base.Note_Off_Ignore_Flag = ( (const LV2_Atom_Float *)note_off_ignore_flag_ptr)->body; + + DR_LOG_INFO_1( "UI Msg: Note Off Ignore Flag: (%f)!", DRG_LV2UI_Base.Note_Off_Ignore_Flag); + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( DRG_LV2UI_Base.Note_Off_Ignore_Flag_CheckBox_Ptr), (int)( DRG_LV2UI_Base.Note_Off_Ignore_Flag)); + } + } + else + { + DR_LOG_ERROR_0( "Unknown resource type passed to ui!"); + } + } + else + { + DR_LOG_ERROR_0( "Non resource message passed to ui!"); + } + } + else + { + DR_LOG_ERROR_0( "Unknown format!"); + } + } + else if( Port_Id == DRD_LV2_CHANNEL_ID) + { + DRG_LV2UI_Base.Channel_Id = *(float *)Buffer_Ptr; + + DR_LOG_INFO_1( "Port_Event called: Channel Id: (%d)!", (int)( DRG_LV2UI_Base.Channel_Id)); + gtk_combo_box_set_active( GTK_COMBO_BOX( DRG_LV2UI_Base.Channel_ComboBox_Ptr), (int)( DRG_LV2UI_Base.Channel_Id)); + } + else if( Port_Id == DRD_LV2_BASE_NOTE) + { + DR_LOG_INFO_0( "Port_Event called: Base Note!"); + } + else if( Port_Id == DRD_LV2_VELOCITY_IGNORE_NOTE) + { + DR_LOG_INFO_0( "Port_Event called: Velocity Ignore Note!"); + } + else if( Port_Id == DRD_LV2_NOTE_OFF_IGNORE_NOTE) + { + DR_LOG_INFO_0( "Port_Event called: Note Off Ignore Note!"); + } + else if( Port_Id == DRD_LV2_VELOCITY_IGNORE_FLAG) + { + DRG_LV2UI_Base.Velocity_Ignore_Flag = *(float *)Buffer_Ptr; + + DR_LOG_INFO_1( "Port_Event called: Velocity Ignore Flag: (%d)!", (int)( DRG_LV2UI_Base.Velocity_Ignore_Flag)); + + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( DRG_LV2UI_Base.Velocity_Ignore_Flag_CheckBox_Ptr), (int)( DRG_LV2UI_Base.Velocity_Ignore_Flag)); + } + else if( Port_Id == DRD_LV2_NOTE_OFF_IGNORE_FLAG) + { + DRG_LV2UI_Base.Note_Off_Ignore_Flag = *(float *)Buffer_Ptr; + + DR_LOG_INFO_1( "Port_Event called: Note Off Ignore Flag: (%d)!", (int)( DRG_LV2UI_Base.Note_Off_Ignore_Flag)); + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( DRG_LV2UI_Base.Note_Off_Ignore_Flag_CheckBox_Ptr), (int)( DRG_LV2UI_Base.Note_Off_Ignore_Flag)); + } + else if( ( Port_Id >= DRD_LV2_GAIN_00) && ( Port_Id <= DRD_LV2_GAIN_31)) + { + DR_LOG_INFO_1( "Port_Event called: Gain: (%d)!", ( Port_Id - DRD_LV2_GAIN_00)); + } + else if( ( Port_Id >= DRD_LV2_PAN_00) && ( Port_Id <= DRD_LV2_PAN_31)) + { + DR_LOG_INFO_1( "Port_Event called: Pan: (%d)!", ( Port_Id - DRD_LV2_PAN_00)); + } + else + { + DR_LOG_INFO_2( "Port_Event called: Port: (%d) Format: (%d)!", Port_Id, Format); + DR_LOG_ERROR_0( "Port_Event called: Unknown port!"); + } + +// if( Format == DRG_LV2UIBase.URIS.Atom_Object) + +/* + EgScopeUI* ui = (EgScopeUI*)handle; + const LV2_Atom* atom = (const LV2_Atom*)buffer; + + /* Check type of data received + * - format == 0: Control port event (float) + * - format > 0: Message (atom) + */ + /* + if (format == ui->uris.atom_eventTransfer && + lv2_atom_forge_is_object_type(&ui->forge, atom->type)) { + const LV2_Atom_Object* obj = (const LV2_Atom_Object*)atom; + if (obj->body.otype == ui->uris.RawAudio) { + recv_raw_audio(ui, obj); + } else if (obj->body.otype == ui->uris.ui_State) { + recv_ui_state(ui, obj); + } + } + */ +} + + + + + +/*----------------------------------------------------------------------------*/ +/* LV2UI_Descritor */ +/*----------------------------------------------------------------------------*/ + +LV2_SYMBOL_EXPORT const LV2UI_Descriptor *lv2ui_descriptor( uint32_t Index) +{ + switch( Index) + { + case 0: + { + return &DRG_LV2UI_Descriptor; + } + + default: + { + return NULL; + } + } +} diff --git a/lv2_ui.h b/lv2_ui.h new file mode 100644 index 0000000..98a0aaf --- /dev/null +++ b/lv2_ui.h @@ -0,0 +1,320 @@ +/*---------------------------------------------------------------------------------*/ +/* Includes */ +/*---------------------------------------------------------------------------------*/ + +#ifndef _LV2_UI_H_ +#define _LV2_UI_H_ + +#include + +#include "lv2/ui/ui.h" + +#include +#include + + + + + +/*----------------------------------------------------------------------------*/ +/* Global definitions */ +/*----------------------------------------------------------------------------*/ + +#define DRD_DRUMMER_UI_URI "http://rx3.net/AlkorZ3/drummer#ui" + + + + +/* +typedef struct { + LV2_Atom_Forge forge; + LV2_URID_Map* map; + LV2UI_Request_Value* request_value; + LV2_Log_Logger logger; + SamplerURIs uris; + PeaksReceiver precv; + + LV2UI_Write_Function write; + LV2UI_Controller controller; + + GtkWidget* box; + GtkWidget* play_button; + GtkWidget* file_button; + GtkWidget* request_file_button; + GtkWidget* button_box; + GtkWidget* canvas; + + uint32_t width; + uint32_t requested_n_peaks; + char* filename; + + uint8_t forge_buf[1024]; + + // Optional show/hide interface + GtkWidget* window; + bool did_init; +} SamplerUI; +*/ + + + +typedef struct DRT_LV2UI_URIS +{ + LV2_URID Atom_Object; + + LV2_URID String_URId; + LV2_URID Bool_URId; + LV2_URID Int_URId; + + LV2_URID Midi_Event; + + LV2_URID UI_Msg; + +// LV2_URID kit_path; + + LV2_URID Atom_EventTransfer; + +// LV2_URID get_state; +// LV2_URID midi_info; +// LV2_URID sample_trigger; +// LV2_URID channel_id; + + LV2_URID Velocity_Ignore_Flag_Toggle; + LV2_URID Note_Off_Ignore_Flag_Toggle; + +// LV2_URID zero_position; +// LV2_URID sample_add; +// LV2_URID sample_remove; +} DRT_LV2UI_URIS; + + + +typedef struct DRT_LV2UI_Base +{ + // LV2 + LV2UI_Write_Function Write; + LV2UI_Controller Controller; + LV2_Atom_Forge Forge; + + // Ports + LV2_Atom_Sequence *Control_Port; + LV2_Atom_Sequence *Core_Event_Port; + + //Config + float Channel_Id; + float Base_Note; + float Velocity_Ignore_Note; + float Note_Off_Ignore_Note; + float Velocity_Ignore_Flag; + float Note_Off_Ignore_Flag; + float Position_Id; + + // params + int Zero_Position; + float **Gains; + float **Pans; + + // URIs + LV2_URID_Map *Map_Ptr; + DRT_LV2UI_URIS URIS; + + // Logger + LV2_Log_Logger Logger; + + // UI + GtkWidget *Main_Widget_Ptr; + GtkWidget *Channel_ComboBox_Ptr; + GtkWidget *Base_Note_Spin_Ptr; + GtkWidget *Base_Note_Label_Ptr; + char Base_Note_Label_Buf[32]; + GtkWidget *Position_ComboBox_Ptr; + GtkWidget *Velocity_Ignore_Note_Spin_Ptr; + GtkWidget *Note_Off_Ignore_Note_Spin_Ptr; + GtkWidget *Velocity_Ignore_Flag_CheckBox_Ptr; + GtkWidget *Note_Off_Ignore_Flag_CheckBox_Ptr; + +} DRT_LV2UI_Base; + + + + + +# ifdef _LV2_UI_C_ + +/*----------------------------------------------------------------------------*/ +/* Private Definitions */ +/*----------------------------------------------------------------------------*/ + +#define DRD_MODULE_NAME "gui" + + + +/*----------------------------------------------------------------------------*/ +/* DRT_LV2UI_Base */ +/*----------------------------------------------------------------------------*/ + +DRT_LV2UI_Base DRG_LV2UI_Base; + +char *DRG_LV2UI_Note_String = "C C#D D#E F F#G G#A A#B "; + + + + + +/*----------------------------------------------------------------------------*/ +/* Private Prototypes */ +/*----------------------------------------------------------------------------*/ + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Map_URIS */ +/*----------------------------------------------------------------------------*/ + +static inline void DR_LV2UI_Map_URIS( LV2_URID_Map *, DRT_LV2UI_URIS *); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Log_Write */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_LV2UI_Log_Write( DRT_Log_Type_Id, char *, va_list); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Channel_ID_ComboBox_Create */ +/*----------------------------------------------------------------------------*/ + +static GtkWidget *DR_LV2UI_Channel_Id_ComboBox_Create( void); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Channel_Id_ComboBox_Change */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Channel_Id_ComboBox_Changed( GtkComboBox *, gpointer); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Position_Id_ComboBox_Create */ +/*----------------------------------------------------------------------------*/ + +static GtkWidget *DR_LV2UI_Position_Id_ComboBox_Create( void); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Position_Id_ComboBox_Change */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Position_Id_ComboBox_Changed( GtkComboBox *, gpointer); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Velocity_Ignore_Flag_Toggled */ +/*----------------------------------------------------------------------------*/ + +static gboolean DR_LV2UI_Velocity_Ignore_Flag_Toggled( GtkToggleButton *, gpointer); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Note_Off_Ignore_Flag_Toggled */ +/*----------------------------------------------------------------------------*/ + +static gboolean DR_LV2UI_Note_Off_Ignore_Flag_Toggled( GtkToggleButton *, gpointer); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Build */ +/*----------------------------------------------------------------------------*/ + +DRT_Status DR_LV2UI_UI_Build(); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Instantiate */ +/*----------------------------------------------------------------------------*/ + +static LV2UI_Handle DR_LV2UI_Instantiate( const LV2UI_Descriptor *, const char *, const char *, LV2UI_Write_Function, LV2UI_Controller, LV2UI_Widget *, const LV2_Feature * const *); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Cleanup */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Cleanup( LV2UI_Handle); + + + +/*----------------------------------------------------------------------------*/ +/* DR_LV2UI_Port_Event */ +/*----------------------------------------------------------------------------*/ + +static void DR_LV2UI_Port_Event( LV2UI_Handle, uint32_t, uint32_t, uint32_t, const void *); + + + +/*----------------------------------------------------------------------------*/ +/* LV2UI_Descritor */ +/*----------------------------------------------------------------------------*/ + +LV2_SYMBOL_EXPORT const LV2UI_Descriptor *lv2ui_descriptor( uint32_t); + + + + + +/*----------------------------------------------------------------------------*/ +/* Post Private Definitions */ +/*----------------------------------------------------------------------------*/ + +/*----------------------------------------------------------------------------*/ +/* DRG_LV2UI_Descritor */ +/*----------------------------------------------------------------------------*/ + +static const LV2UI_Descriptor DRG_LV2UI_Descriptor = +{ + DRD_DRUMMER_URI "#ui", + DR_LV2UI_Instantiate, + DR_LV2UI_Cleanup, + DR_LV2UI_Port_Event, + NULL}; + + + +# else // ifdef _LV2_UI_C_ + + + + + +/*----------------------------------------------------------------------------*/ +/* Public Prototypes */ +/*----------------------------------------------------------------------------*/ + + + + + + + + +# endif // ifndef _LV2_UI_C_ + + + + + +/*----------------------------------------------------------------------------*/ + +#endif // ifndef _LV2_UI_H_ +