add Device struct
This commit is contained in:
42
effects.c
42
effects.c
@@ -1350,8 +1350,6 @@ static EffectList rp250_effects[] = {
|
||||
{"Pickup", pickup_effect, G_N_ELEMENTS(pickup_effect)},
|
||||
};
|
||||
|
||||
static int n_rp250_effects = G_N_ELEMENTS(rp250_effects);
|
||||
|
||||
static EffectList rp500_effects[] = {
|
||||
{"Wah", wah_effect, G_N_ELEMENTS(wah_effect)},
|
||||
{"Amplifier", rp500_amp_effect, G_N_ELEMENTS(rp500_amp_effect)},
|
||||
@@ -1364,11 +1362,30 @@ static EffectList rp500_effects[] = {
|
||||
{"Reverb", reverb_effect, G_N_ELEMENTS(reverb_effect)},
|
||||
};
|
||||
|
||||
static int n_rp500_effects = G_N_ELEMENTS(rp500_effects);
|
||||
static Banks rp_banks[] = {
|
||||
{"User Presets", PRESETS_USER},
|
||||
{"System Presets", PRESETS_SYSTEM},
|
||||
};
|
||||
|
||||
SupportedDevices supported_devices[] = {
|
||||
{"DigiTech RP250", rp250_effects, G_N_ELEMENTS(rp250_effects)},
|
||||
{"DigiTech RP500", rp500_effects, G_N_ELEMENTS(rp500_effects)},
|
||||
static Device rp250 = {
|
||||
.name = "DigiTech RP250",
|
||||
.effects = rp250_effects,
|
||||
.n_effects = G_N_ELEMENTS(rp250_effects),
|
||||
.banks = rp_banks,
|
||||
.n_banks = G_N_ELEMENTS(rp_banks),
|
||||
};
|
||||
|
||||
static Device rp500 = {
|
||||
.name = "DigiTech RP500",
|
||||
.effects = rp500_effects,
|
||||
.n_effects = G_N_ELEMENTS(rp500_effects),
|
||||
.banks = rp_banks,
|
||||
.n_banks = G_N_ELEMENTS(rp_banks),
|
||||
};
|
||||
|
||||
Device* supported_devices[] = {
|
||||
&rp250,
|
||||
&rp500,
|
||||
};
|
||||
|
||||
int n_supported_devices = G_N_ELEMENTS(supported_devices);
|
||||
@@ -1658,27 +1675,24 @@ void modifier_group_free(ModifierGroup *modifier_group)
|
||||
* \param device_id Device ID
|
||||
* \param family_id Family ID
|
||||
* \param product_id Product ID
|
||||
* \param list Variable to hold effect list
|
||||
* \param n_list Variable to hold length of effect list
|
||||
* \param device Variable to hold device information
|
||||
*
|
||||
* Gets appropiate effect list basing on device, family and product IDs.
|
||||
*
|
||||
* \return TRUE if list and n_list were set, FALSE otherwise.
|
||||
**/
|
||||
gboolean get_effect_list(unsigned char device_id, unsigned char family_id,
|
||||
gboolean get_device_info(unsigned char device_id, unsigned char family_id,
|
||||
unsigned char product_id,
|
||||
EffectList **list, int *n_list)
|
||||
Device **device)
|
||||
{
|
||||
switch (family_id) {
|
||||
case 0x5E: /* RP series */
|
||||
switch (product_id) {
|
||||
case 0x02: /* RP250 */
|
||||
*list = rp250_effects;
|
||||
*n_list = n_rp250_effects;
|
||||
*device = &rp250;
|
||||
return TRUE;
|
||||
case 0x05: /* RP500 */
|
||||
*list = rp500_effects;
|
||||
*n_list = n_rp500_effects;
|
||||
*device = &rp500;
|
||||
return TRUE;
|
||||
default:
|
||||
g_message("Unsupported RP model!");
|
||||
|
||||
17
effects.h
17
effects.h
@@ -62,14 +62,21 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
gchar *name;
|
||||
EffectList *list;
|
||||
int n_list;
|
||||
} SupportedDevices;
|
||||
PresetBank bank;
|
||||
} Banks;
|
||||
|
||||
typedef struct {
|
||||
gchar *name;
|
||||
EffectList *effects;
|
||||
gint n_effects;
|
||||
Banks *banks;
|
||||
gint n_banks;
|
||||
} Device;
|
||||
|
||||
ModifierGroup *modifier_linkable_list();
|
||||
void modifier_group_free(ModifierGroup *modifier_group);
|
||||
gboolean get_effect_list(unsigned char device_id, unsigned char family_id,
|
||||
gboolean get_device_info(unsigned char device_id, unsigned char family_id,
|
||||
unsigned char product_id,
|
||||
EffectList **list, int *n_list);
|
||||
Device **device);
|
||||
|
||||
#endif /* GDIGI_EFFECTS_H */
|
||||
|
||||
19
gdigi.c
19
gdigi.c
@@ -28,7 +28,7 @@ static unsigned char product_id = 0x7F;
|
||||
|
||||
static snd_rawmidi_t *output = NULL;
|
||||
static snd_rawmidi_t *input = NULL;
|
||||
static char *device = "hw:1,0,0";
|
||||
static char *device_port = "hw:1,0,0";
|
||||
|
||||
static GQueue *message_queue = NULL;
|
||||
static GMutex *message_queue_mutex = NULL;
|
||||
@@ -62,9 +62,9 @@ gboolean open_device()
|
||||
{
|
||||
int err;
|
||||
|
||||
err = snd_rawmidi_open(&input, &output, device, SND_RAWMIDI_SYNC);
|
||||
err = snd_rawmidi_open(&input, &output, device_port, SND_RAWMIDI_SYNC);
|
||||
if (err) {
|
||||
fprintf(stderr, "snd_rawmidi_open %s failed: %d\n", device, err);
|
||||
fprintf(stderr, "snd_rawmidi_open %s failed: %d\n", device_port, err);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -600,7 +600,7 @@ static void request_device_configuration()
|
||||
#ifndef DOXYGEN_SHOULD_SKIP_THIS
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{"device", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &device, "MIDI device port to use", NULL},
|
||||
{"device", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &device_port, "MIDI device port to use", NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
@@ -644,17 +644,16 @@ int main(int argc, char *argv[]) {
|
||||
if (request_who_am_i(&device_id, &family_id, &product_id) == FALSE) {
|
||||
show_error_message(NULL, "No suitable reply from device");
|
||||
} else {
|
||||
EffectList *list = NULL;
|
||||
int n_list = -1;
|
||||
Device *device = NULL;
|
||||
|
||||
if (get_effect_list(device_id, family_id, product_id, &list, &n_list) == FALSE) {
|
||||
if (unsupported_device_dialog(&list, &n_list) == FALSE) {
|
||||
if (get_device_info(device_id, family_id, product_id, &device) == FALSE) {
|
||||
if (unsupported_device_dialog(&device) == FALSE) {
|
||||
g_message("Shutting down");
|
||||
}
|
||||
}
|
||||
|
||||
if (list != NULL && n_list != -1) {
|
||||
gui_create(list, n_list);
|
||||
if (device != NULL) {
|
||||
gui_create(device);
|
||||
gtk_main();
|
||||
gui_free();
|
||||
}
|
||||
|
||||
40
gui.c
40
gui.c
@@ -494,22 +494,32 @@ static void fill_store_with_presets(GtkTreeStore *model, guint bank, gchar *name
|
||||
**/
|
||||
static void fill_store(GtkTreeStore *model)
|
||||
{
|
||||
fill_store_with_presets(model, PRESETS_USER, "User Presets");
|
||||
fill_store_with_presets(model, PRESETS_SYSTEM, "System Presets");
|
||||
Device *device = g_object_get_data(G_OBJECT(model), "device");
|
||||
|
||||
g_return_if_fail(device != NULL);
|
||||
|
||||
gint i;
|
||||
for (i=0; i<device->n_banks; i++)
|
||||
fill_store_with_presets(model,
|
||||
device->banks[i].bank,
|
||||
device->banks[i].name);
|
||||
}
|
||||
|
||||
/**
|
||||
* \param device device information
|
||||
*
|
||||
* Creates treeview showing list of presets available on device.
|
||||
*
|
||||
* \return treeview containing all preset names found on device.
|
||||
**/
|
||||
GtkWidget *create_preset_tree()
|
||||
GtkWidget *create_preset_tree(Device *device)
|
||||
{
|
||||
GtkWidget *treeview;
|
||||
GtkTreeStore *store;
|
||||
GtkCellRenderer *renderer;
|
||||
|
||||
store = gtk_tree_store_new(NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT);
|
||||
g_object_set_data(G_OBJECT(store), "device", device);
|
||||
fill_store(store);
|
||||
|
||||
treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
|
||||
@@ -844,7 +854,7 @@ static void add_menubar(GtkWidget *window, GtkWidget *vbox)
|
||||
/**
|
||||
* Creates main window.
|
||||
**/
|
||||
void gui_create(EffectList *effects, int n_effects)
|
||||
void gui_create(Device *device)
|
||||
{
|
||||
GtkWidget *window;
|
||||
GtkWidget *vbox;
|
||||
@@ -868,7 +878,7 @@ void gui_create(EffectList *effects, int n_effects)
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), sw, FALSE, FALSE, 0);
|
||||
|
||||
widget = create_preset_tree();
|
||||
widget = create_preset_tree(device);
|
||||
gtk_container_add(GTK_CONTAINER(sw), widget);
|
||||
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
@@ -876,12 +886,12 @@ void gui_create(EffectList *effects, int n_effects)
|
||||
|
||||
knob_anim = gtk_knob_animation_new_from_inline(knob_pixbuf);
|
||||
|
||||
for (x = 0; x<n_effects; x++) {
|
||||
if ((x % ((n_effects+1)/2)) == 0) {
|
||||
for (x = 0; x<device->n_effects; x++) {
|
||||
if ((x % ((device->n_effects+1)/2)) == 0) {
|
||||
hbox = gtk_hbox_new(FALSE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 2);
|
||||
}
|
||||
widget = create_vbox(effects[x].effect, effects[x].amt, effects[x].label);
|
||||
widget = create_vbox(device->effects[x].effect, device->effects[x].amt, device->effects[x].label);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 2);
|
||||
}
|
||||
|
||||
@@ -904,16 +914,15 @@ void gui_free()
|
||||
}
|
||||
|
||||
/**
|
||||
* \param list Variable to hold effect list
|
||||
* \param n_list Variable to hold length of effect list
|
||||
* \param device Variable to hold device information
|
||||
*
|
||||
* Displays dialogbox stating that device is unsupported.
|
||||
*
|
||||
* \return TRUE if user selects "compability mode", otherwise FALSE.
|
||||
**/
|
||||
gboolean unsupported_device_dialog(EffectList **list, int *n_list)
|
||||
gboolean unsupported_device_dialog(Device **device)
|
||||
{
|
||||
extern SupportedDevices supported_devices[];
|
||||
extern Device* supported_devices[];
|
||||
extern int n_supported_devices;
|
||||
|
||||
GtkWidget *dialog;
|
||||
@@ -936,7 +945,7 @@ gboolean unsupported_device_dialog(EffectList **list, int *n_list)
|
||||
|
||||
combo_box = gtk_combo_box_new_text();
|
||||
for (x=0; x<n_supported_devices; x++) {
|
||||
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), supported_devices[x].name);
|
||||
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), supported_devices[x]->name);
|
||||
}
|
||||
|
||||
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), combo_box);
|
||||
@@ -945,9 +954,8 @@ gboolean unsupported_device_dialog(EffectList **list, int *n_list)
|
||||
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
gint number = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box));
|
||||
if (number != -1 && number <n_supported_devices) {
|
||||
g_message("Starting %s compability mode", supported_devices[number].name);
|
||||
*list = supported_devices[number].list;
|
||||
*n_list = supported_devices[number].n_list;
|
||||
g_message("Starting %s compability mode", supported_devices[number]->name);
|
||||
*device = supported_devices[number];
|
||||
gtk_widget_destroy(dialog);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
4
gui.h
4
gui.h
@@ -21,8 +21,8 @@
|
||||
#include "effects.h"
|
||||
|
||||
void show_error_message(GtkWidget *parent, gchar *message);
|
||||
void gui_create(EffectList *list, int n_list);
|
||||
void gui_create(Device *device);
|
||||
void gui_free();
|
||||
gboolean unsupported_device_dialog(EffectList **list, int *n_list);
|
||||
gboolean unsupported_device_dialog(Device **device);
|
||||
|
||||
#endif /* GDIGI_GUI_H */
|
||||
|
||||
Reference in New Issue
Block a user