Don't use hard coded path for knob image, use bundle-path from lv2 host

This commit is contained in:
Nick Lanham 2012-02-23 14:12:03 +01:00
parent 06769d6fd7
commit d3cc0531bf
4 changed files with 36 additions and 8 deletions

View File

@ -50,11 +50,6 @@ target_link_libraries(drmr_ui ${LV2_LIBRARIES} ${GTK2_LIBRARIES} ${SNDFILE_LIBRA
add_definitions ( -DPIC )
set_target_properties (drmr_ui
PROPERTIES
DEFINE_SYMBOL "INSTALL_DIR=\"${CMAKE_INSTALL_PREFIX}/${LV2_INSTALL_DIR}\""
)
if (NOT USE_NKNOB)
set_target_properties (drmr_ui
PROPERTIES
@ -82,7 +77,7 @@ set_target_properties ( htest
target_link_libraries(knobt ${LV2_LIBRARIES} ${GTK2_LIBRARIES} ${SNDFILE_LIBRARIES} ${SAMPLERATE_LIBRARIES} ${EXPAT_LIBRARIES} m)
set_target_properties ( knobt
PROPERTIES
COMPILE_FLAGS "-D_TEST_N_KNOB -DINSTALL_DIR=\\\"${CMAKE_INSTALL_PREFIX}/${LV2_INSTALL_DIR}\\\""
COMPILE_FLAGS "-D_TEST_N_KNOB"
)
# config install

View File

@ -40,6 +40,8 @@ typedef struct {
GtkWidget** pan_sliders;
float *gain_vals,*pan_vals;
gchar *bundle_path;
int cols;
int samples;
@ -101,6 +103,7 @@ static void fill_sample_table(DrMrUi* ui, int samples, char** names,GtkWidget**
slide_expand = true;
#else
gain_slider = n_knob_new_with_range(0.0,GAIN_MIN,6.0,1.0);
n_knob_set_load_prefix(N_KNOB(gain_slider),ui->bundle_path);
gtk_widget_set_has_tooltip(gain_slider,TRUE);
slide_expand = false;
#endif
@ -119,6 +122,7 @@ static void fill_sample_table(DrMrUi* ui, int samples, char** names,GtkWidget**
gtk_scale_add_mark(GTK_SCALE(pan_slider),0.0,GTK_POS_TOP,NULL);
#else
pan_slider = n_knob_new_with_range(0.0,-1.0,1.0,0.1);
n_knob_set_load_prefix(N_KNOB(pan_slider),ui->bundle_path);
gtk_widget_set_has_tooltip(pan_slider,TRUE);
#endif
if (pan_sliders) pan_sliders[si] = pan_slider;
@ -326,6 +330,7 @@ instantiate(const LV2UI_Descriptor* descriptor,
ui->drmr_widget = NULL;
ui->curKit = -1;
ui->samples = 0;
ui->bundle_path = g_strdup(bundle_path);
*widget = NULL;
build_drmr_ui(ui);
@ -359,6 +364,7 @@ static void cleanup(LV2UI_Handle handle) {
gtk_widget_destroy(ui->drmr_widget);
if (ui->gain_sliders) free(ui->gain_sliders);
if (ui->pan_sliders) free(ui->pan_sliders);
g_free(ui->bundle_path);
free_kits(ui->kits);
free(ui);
}

25
nknob.c
View File

@ -158,6 +158,7 @@ static void n_knob_init (NKnob *knob) {
knob->saved_x = knob->saved_y = 0;
knob->size = KNOB_SIZE;
knob->pixbuf = NULL;
knob->load_prefix = NULL;
g_signal_connect(G_OBJECT(knob),"query-tooltip",G_CALLBACK(tooltip_callback),NULL);
}
@ -204,6 +205,14 @@ GtkWidget* n_knob_new_with_range (gdouble value, gdouble lower,
return n_knob_new (adj);
}
void n_knob_set_load_prefix(NKnob* knob, gchar* prefix) {
knob->load_prefix = g_strdup(prefix);
}
gchar* n_knob_get_load_prefix(NKnob* knob) {
return knob->load_prefix;
}
static void n_knob_destroy(GtkObject *object) {
NKnob *knob;
@ -213,6 +222,9 @@ static void n_knob_destroy(GtkObject *object) {
knob = N_KNOB(object);
knob->pixbuf = NULL;
if (knob->load_prefix) g_free(knob->load_prefix);
knob->load_prefix = NULL;
if (GTK_OBJECT_CLASS(parent_class)->destroy)
(*GTK_OBJECT_CLASS(parent_class)->destroy)(object);
}
@ -244,8 +256,16 @@ static void n_knob_realize(GtkWidget *widget) {
* set local pixbuf pointer to global
* set last pixbuf pointer to NULL */
if(pixbuf[i] == NULL){
pixbuf[i] = gdk_pixbuf_new_from_file_at_size(INSTALL_DIR"/drmr.lv2/knob.png",
52*knob->size,knob->size,&gerror);
gchar* path;
if (knob->load_prefix)
path = g_build_path("/",knob->load_prefix,"knob.png",NULL);
else {
g_warning("Trying to show knob with no load prefix, looking only in cwd\n");
path = "knob.png";
}
pixbuf[i] = gdk_pixbuf_new_from_file_at_size(path,52*knob->size,knob->size,&gerror);
if (knob->load_prefix)
g_free(path);
knob->pixbuf = pixbuf[i];
pixbuf=g_realloc(pixbuf,sizeof(GdkPixbuf *) * (i+2));
pixbuf[i+1] = NULL;
@ -558,6 +578,7 @@ int main(int argc, char* argv[]) {
/* knob */
knob = n_knob_new_with_range (-90, -90, 0, 1);
n_knob_set_load_prefix(N_KNOB(knob),"../");
gtk_box_pack_start (GTK_BOX (vbox), knob, TRUE, FALSE, 0);
g_signal_connect (G_OBJECT (knob), "change-value",
G_CALLBACK (changed_callback), NULL);

View File

@ -52,6 +52,9 @@ typedef struct _NKnobClass NKnobClass;
struct _NKnob {
GtkRange range;
/* image prefix */
gchar *load_prefix;
/* State of widget (to do with user interaction) */
guint8 state;
gint saved_x, saved_y;
@ -76,6 +79,9 @@ GtkWidget* n_knob_new_with_range (double value,
double upper,
double step);
void n_knob_set_load_prefix(NKnob* knob, gchar* prefix);
gchar* n_knob_get_load_prefix(NKnob* knob);
G_END_DECLS
#endif