drummer/lv2_ui.c
Arnaud G. GIBERT 68336ef3b6 - Move URL from github to rx3
- Start UI / GTK implementation
- Minor code refactoring
2023-07-28 01:14:53 +02:00

812 lines
27 KiB
C

/*----------------------------------------------------------------------------*/
/* Includes */
/*----------------------------------------------------------------------------*/
#define _LV2_UI_C_
#include <drummer.h>
/*----------------------------------------------------------------------------*/
/* 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 <b>(%c%c%i)</b>:", 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 <b>(C 2)</b>:");
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, &note_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;
}
}
}