1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
/* ghostess - A GUI host for DSSI plugins.
*
* Copyright (C) 2005, 2006, 2008, 2010, 2012 Sean Bolton.
*
* This program 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 2 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, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
#define _BSD_SOURCE 1
#define _SVID_SOURCE 1
#define _ISOC99_SOURCE 1
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <errno.h>
#include <glib.h>
#include <gtk/gtk.h>
#include "ghostess.h"
#include "eyecandy.h"
#include "gui_callbacks.h"
#include "gui_interface.h"
#ifdef MIDI_ALSA
#include "midi.h"
#endif
static void (*file_selection_handler)(GtkWidget *widget, gpointer data);
static gchar *last_save_filename = NULL;
static gchar *last_patchlist_filename = NULL;
static d3h_instance_t *ui_context_menu_instance;
void
file_selection_set_path(gchar *filename)
{
if (filename) {
gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_selection),
filename);
} else if (project_directory && strlen(project_directory)) {
if (project_directory[strlen(project_directory) - 1] != '/') {
char *buffer = g_strdup_printf("%s/", project_directory);
gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_selection),
buffer);
g_free(buffer);
} else {
gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_selection),
project_directory);
}
}
}
void
on_menu_save_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
file_selection_set_path(last_save_filename);
gtk_window_set_title(GTK_WINDOW(file_selection), "ghostess - Save Configuration");
file_selection_handler = on_save_file_ok;
gtk_widget_show(file_selection);
}
void
on_menu_patchlist_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
file_selection_set_path(last_patchlist_filename);
gtk_window_set_title(GTK_WINDOW(file_selection), "ghostess - Export Patchlist for Freewheeling");
file_selection_handler = on_patchlist_file_ok;
gtk_widget_show(file_selection);
}
void
on_menu_quit_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
gtk_main_quit();
host_exiting = 1;
}
void
on_menu_about_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
char buf[1024];
int maxlen = 1024,
len;
#ifdef HAVE_CONFIG_H
snprintf(buf, maxlen, "%s " VERSION "\n"
#else
snprintf(buf, maxlen, "%s\n"
#endif
"Copyright (C) 2012 by Sean Bolton and others.\n\n"
"This is sloppy, hurried HACKWARE -- please do not "
"consider this exemplary of the authors' skills or "
"preferences, nor of good DSSI or general programming "
"practices. (In particular, I don't want anyone "
"attributing my mess to Chris or Steve ;-)\n\n"
"%s comes with ABSOLUTELY NO WARRANTY. "
"It is free software, and you are welcome to "
"redistribute it under certain conditions; see "
"the file COPYING for details.\n\n",
host_name_default, host_name_default);
len = strlen(buf);
snprintf(buf + len, maxlen - len, "Host OSC URL: %s\n", host_osc_url);
#ifdef MIDI_ALSA
len = strlen(buf);
snprintf(buf + len, maxlen - len, "ALSA MIDI input port: %d:%d\n",
alsa_client_id, alsa_port_id);
#endif
#ifdef MIDI_JACK
len = strlen(buf);
snprintf(buf + len, maxlen - len, "Using >experimental< JACK MIDI input\n");
#endif
#ifdef MIDI_COREMIDI
len = strlen(buf);
snprintf(buf + len, maxlen - len, "Using >experimental< CoreMIDI input\n");
#endif
gtk_label_set_text (GTK_LABEL (about_label), buf);
gtk_widget_show(about_window);
}
gint
on_delete_event_wrapper( GtkWidget *widget, GdkEvent *event, gpointer data )
{
void (*handler)(GtkWidget *, gpointer) = (void (*)(GtkWidget *, gpointer))data;
/* call our 'dismiss' or 'cancel' callback (which must not need the user data) */
(*handler)(widget, NULL);
/* tell GTK+ to NOT emit 'destroy' */
return TRUE;
}
void
on_file_selection_ok( GtkWidget *widget, gpointer data )
{
gtk_widget_hide(file_selection);
(*file_selection_handler)(widget, data);
}
void
on_file_selection_cancel( GtkWidget *widget, gpointer data )
{
ghss_debug(GDB_GUI, ": on_save_file_cancel called");
gtk_widget_hide(file_selection);
}
void
on_save_file_ok( GtkWidget *widget, gpointer data )
{
if (last_save_filename) free(last_save_filename);
last_save_filename = (gchar *)g_strdup(gtk_file_selection_get_filename(
GTK_FILE_SELECTION(file_selection)));
ghss_debug(GDB_GUI, " on_save_file_ok: file '%s' selected",
last_save_filename);
if (!write_configuration(last_save_filename, NULL)) {
display_notice("Save Configuration failed:", strerror(errno));
} else {
display_notice("Configuration Saved.", "");
}
}
void
on_patchlist_file_ok( GtkWidget *widget, gpointer data )
{
if (last_patchlist_filename) free(last_patchlist_filename);
last_patchlist_filename = (gchar *)g_strdup(gtk_file_selection_get_filename(
GTK_FILE_SELECTION(file_selection)));
/* -FIX- add '.xml' to filename if it's not already there? */
ghss_debug(GDB_GUI, " on_patchlist_file_ok: file '%s' selected",
last_patchlist_filename);
if (!write_patchlist(last_patchlist_filename)) {
display_notice("Patchlist export failed:", strerror(errno));
} else {
display_notice("Patchlist exported.", "");
}
}
void
on_about_dismiss( GtkWidget *widget, gpointer data )
{
gtk_widget_hide(about_window);
}
void
on_strip_ui_button_toggled(GtkWidget *widget, gpointer data)
{
d3h_instance_t *instance = ((plugin_strip *)data)->instance;
int state = GTK_TOGGLE_BUTTON (widget)->active;
ghss_debug(GDB_GUI, " on_strip_ui_button_toggled: instance %d button changed to %s",
instance->number, (state ? "on" : "off"));
if (instance->ui_osc_address) {
if (state) {
lo_send(instance->ui_osc_address, instance->ui_osc_show_path, "");
instance->ui_visible = 1;
} else {
lo_send(instance->ui_osc_address, instance->ui_osc_hide_path, "");
instance->ui_visible = 0;
}
} else if (state && !instance->ui_running) {
instance->ui_visible = 1;
start_ui(instance);
}
}
gboolean
on_strip_ui_button_event(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
d3h_instance_t *instance = ((plugin_strip *)data)->instance;
if (event->button != 3) /* we're only interested in third button clicks */
return FALSE; /* propagate to other handlers, if any */
ghss_debug(GDB_GUI, " on_strip_ui_button_event: third button click on instance %d",
instance->number);
/* set menu item sensitivity according to assumed UI state */
gtk_widget_set_sensitive (ui_context_menu_launch, !instance->ui_running);
gtk_widget_set_sensitive (ui_context_menu_show, instance->ui_running && !instance->ui_visible);
gtk_widget_set_sensitive (ui_context_menu_hide, instance->ui_running && instance->ui_visible);
gtk_widget_set_sensitive (ui_context_menu_exit, instance->ui_running);
ui_context_menu_instance = instance;
gtk_menu_popup (GTK_MENU(ui_context_menu), NULL, NULL, NULL, NULL,
event->button, event->time);
return TRUE;
}
void
update_ui_button_internal(d3h_instance_t *instance, int value)
{
/* -FIX- should be g_signal_handlers_block_by_func if we're GTK+ 2.x only */
gtk_signal_handler_block_by_func(GTK_OBJECT(instance->strip->ui_button),
GTK_SIGNAL_FUNC(on_strip_ui_button_toggled),
(gpointer)instance->strip);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(instance->strip->ui_button),
value);
gtk_signal_handler_unblock_by_func(GTK_OBJECT(instance->strip->ui_button),
GTK_SIGNAL_FUNC(on_strip_ui_button_toggled),
(gpointer)instance->strip);
}
void
on_ui_context_menu_activate(GtkWidget *widget, gpointer data)
{
int mode = (intptr_t)data;
d3h_instance_t *instance = ui_context_menu_instance;
ghss_debug(GDB_GUI, " on_ui_context_menu_activate: menu mode %d selected", mode);
switch (mode) {
default:
break;
case 0: /* launch */
if (instance->ui_osc_address == NULL) {
instance->ui_visible = 1;
start_ui(instance);
update_ui_button_internal(instance, TRUE);
}
break;
case 1: /* show */
if (instance->ui_osc_address) {
lo_send(instance->ui_osc_address, instance->ui_osc_show_path, "");
instance->ui_visible = 1;
update_ui_button_internal(instance, TRUE);
}
break;
case 2: /* hide */
if (instance->ui_osc_address) {
lo_send(instance->ui_osc_address, instance->ui_osc_hide_path, "");
instance->ui_visible = 0;
update_ui_button_internal(instance, FALSE);
}
break;
case 3: /* exit */
if (instance->ui_osc_address) {
lo_send(instance->ui_osc_address, instance->ui_osc_quit_path, "");
ui_osc_free(instance);
}
instance->ui_running = 0;
instance->ui_visible = 0;
update_ui_button_internal(instance, FALSE);
break;
}
}
void
display_notice(char *message1, char *message2)
{
gtk_label_set_text (GTK_LABEL (notice_label_1), message1);
gtk_label_set_text (GTK_LABEL (notice_label_2), message2);
gtk_widget_show(notice_window);
}
void
on_notice_dismiss( GtkWidget *widget, gpointer data )
{
gtk_widget_hide(notice_window);
}
void
update_from_exiting(d3h_instance_t *instance)
{
update_ui_button_internal(instance, FALSE);
}
void
update_eyecandy(d3h_instance_t *instance)
{
int state;
state = (main_timeout_tick - instance->midi_activity_tick <= 1);
if (instance->strip->previous_midi_state != state) {
blinky_set_state(BLINKY(instance->strip->midi_status), state);
instance->strip->previous_midi_state = state;
}
}
|