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
|
/* Petri-Foo is a fork of the Specimen audio sampler.
Original Specimen author Pete Bessman
Copyright 2005 Pete Bessman
Copyright 2011 James W. Morris
This file is part of Petri-Foo.
Petri-Foo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
Petri-Foo 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 Petri-Foo. If not, see <http://www.gnu.org/licenses/>.
This file is a derivative of a Specimen original, modified 2011
*/
#include "mod_src_gui.h"
#include "phin.h"
#include "gui.h"
#include "petri-foo.h"
#include "patch_set_and_get.h"
#include "mod_src.h"
enum {
COLUMN_STRING,
COLUMN_INT,
N_COLUMNS
};
static GtkListStore* mod_src_list_all = 0;
static GtkListStore* mod_src_list_global = 0;
static void mod_src_create_models(void)
{
GtkTreeIter iter;
id_name* mod_src_ids;
id_name* msp;
mod_src_list_all = gtk_list_store_new(N_COLUMNS,
G_TYPE_STRING,
G_TYPE_INT);
mod_src_list_global = gtk_list_store_new(N_COLUMNS,
G_TYPE_STRING,
G_TYPE_INT);
mod_src_ids = mod_src_get(MOD_SRC_ALL);
for (msp = mod_src_ids; msp->name; ++msp)
{
/*
debug("mod_src:%d %s\n", msp->id, msp->name);
*/
gtk_list_store_append ( mod_src_list_all, &iter);
gtk_list_store_set( mod_src_list_all, &iter,
COLUMN_STRING, msp->name,
COLUMN_INT, msp->id,
-1);
if (mod_src_is_global(msp->id))
{
gtk_list_store_append ( mod_src_list_global,&iter);
gtk_list_store_set( mod_src_list_global,&iter,
COLUMN_STRING, msp->name,
COLUMN_INT, msp->id,
-1);
}
}
mod_src_free(mod_src_ids);
}
GtkWidget* mod_src_new_combo_with_cell()
{
GtkWidget* combo;
GtkCellRenderer* cell;
if (!mod_src_list_all)
mod_src_create_models();
combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(mod_src_list_all));
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT(combo),
cell, "text", 0, NULL );
return combo;
}
GtkWidget* mod_src_new_pitch_adjustment(void)
{
GtkWidget* amt;
amt = phin_slider_button_new_with_range(12, -PATCH_MAX_PITCH_STEPS,
PATCH_MAX_PITCH_STEPS,
0.1, 1.0);
phin_slider_button_set_format(PHIN_SLIDER_BUTTON(amt),
-1, NULL, NULL);
gtk_widget_set_tooltip_text(amt, "Semitones");
phin_slider_button_set_threshold(PHIN_SLIDER_BUTTON(amt),
GUI_THRESHOLD);
return amt;
}
int mod_src_combo_get_mod_src_id(GtkComboBox* combo)
{
GtkTreeIter iter;
if (gtk_combo_box_get_active_iter(combo, &iter))
{
int id;
gtk_tree_model_get( gtk_combo_box_get_model(combo),
&iter, COLUMN_INT, &id, -1);
return id;
}
return MOD_SRC_NONE;
}
gboolean mod_src_callback_helper(int patch_id, int slot,
GtkComboBox* combo, PatchParamType par)
{
GtkTreeIter iter;
if (gtk_combo_box_get_active_iter(combo, &iter))
{
char* string;
int id;
GtkTreeModel* model = gtk_combo_box_get_model(combo);
gtk_tree_model_get(model, &iter, 0, &string, 1, &id, -1);
debug("patch id:%d slot:%d mod src:%s (%d)\n",
patch_id, slot, mod_src_name(id), id);
/* FIXME: probably should check return value */
patch_param_set_mod_src(patch_id, par, slot, id);
return id != MOD_SRC_NONE;
}
return FALSE;
}
gboolean mod_src_callback_helper_lfo(int patch_id,
int input_no,
GtkComboBox* combo,
int lfo_id)
{
GtkTreeIter iter;
if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter))
{
char* string;
int id;
GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
gtk_tree_model_get(model, &iter, 0, &string, 1, &id, -1);
switch(input_no)
{
case FM1: patch_set_lfo_fm1_src(patch_id, lfo_id, id); break;
case FM2: patch_set_lfo_fm2_src(patch_id, lfo_id, id); break;
case AM1: patch_set_lfo_am1_src(patch_id, lfo_id, id); break;
case AM2: patch_set_lfo_am2_src(patch_id, lfo_id, id); break;
default:
debug("attempt to set mod src for out of range input %d.\n",
input_no);
return FALSE;
}
return id != MOD_SRC_NONE;
}
return FALSE;
}
gboolean mod_src_combo_get_iter_with_id(GtkComboBox* combo,
int mod_src_id,
GtkTreeIter* iter)
{
GtkTreeModel* model = gtk_combo_box_get_model(combo);
gboolean valid = gtk_tree_model_get_iter_first(model, iter);
while (valid)
{
gchar *str_data;
gint int_data;
gtk_tree_model_get(model, iter, 0, &str_data, 1, &int_data, -1);
if (int_data == mod_src_id)
return TRUE;
valid = gtk_tree_model_iter_next(model, iter);
}
return FALSE;
}
gboolean mod_src_combo_set_model(GtkComboBox* combo, int model_id)
{
GtkTreeModel* model = 0;
switch(model_id)
{
case MOD_SRC_ALL:
model = GTK_TREE_MODEL(mod_src_list_all);
break;
case MOD_SRC_GLOBALS:
model = GTK_TREE_MODEL(mod_src_list_global);
break;
default:
debug("unknown mod src model.\n");
return FALSE;
}
gtk_combo_box_set_model(combo, model);
return TRUE;
}
int mod_src_combo_get_model_id(GtkComboBox* combo)
{
GtkTreeModel* model = gtk_combo_box_get_model(combo);
if (model == GTK_TREE_MODEL(mod_src_list_all))
return MOD_SRC_ALL;
else if (model == GTK_TREE_MODEL(mod_src_list_global))
return MOD_SRC_GLOBALS;
return MOD_SRC_NONE;
}
|