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
|
/* 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 <gtk/gtk.h>
#include "phin.h"
#include "channelsection.h"
#include "gui.h"
#include "patchlist.h"
#include "midi.h"
#include "patch_set_and_get.h"
G_DEFINE_TYPE(ChannelSection, channel_section, GTK_TYPE_VBOX)
static void channel_section_class_init(ChannelSectionClass* klass)
{
channel_section_parent_class = g_type_class_peek_parent(klass);
}
static void channel_cb(PhinSliderButton* button, ChannelSection* self)
{
int channel = (int)phin_slider_button_get_value(button);
PatchList* list = gui_get_patch_list();
patch_set_channel(self->patch, channel-1);
patch_list_update(list, patch_list_get_current_patch(list),
PATCH_LIST_PATCH);
}
static void lower_vel_cb(PhinSliderButton* button, ChannelSection* self)
{
int lower_vel = (int)phin_slider_button_get_value(button);
PatchList* list = gui_get_patch_list();
patch_set_lower_vel(self->patch, lower_vel);
patch_list_update(list, patch_list_get_current_patch(list),
PATCH_LIST_PATCH);
}
static void upper_vel_cb(PhinSliderButton* button, ChannelSection* self)
{
int upper_vel = (int)phin_slider_button_get_value(button);
PatchList* list = gui_get_patch_list();
patch_set_upper_vel(self->patch, upper_vel);
patch_list_update(list, patch_list_get_current_patch(list),
PATCH_LIST_PATCH);
}
static void connect(ChannelSection* self)
{
g_signal_connect(G_OBJECT(self->chan_sb), "value-changed",
G_CALLBACK(channel_cb), (gpointer) self);
g_signal_connect(G_OBJECT(self->lower_vel_sb), "value-changed",
G_CALLBACK(lower_vel_cb), (gpointer) self);
g_signal_connect(G_OBJECT(self->upper_vel_sb), "value-changed",
G_CALLBACK(upper_vel_cb), (gpointer) self);
}
static void channel_section_init(ChannelSection* self)
{
GtkBox* box = GTK_BOX(self);
GtkWidget* table = gtk_table_new( 3, 2, 1);
GtkWidget* lbl_chan = gtk_label_new("Channel");
GtkWidget* lbl_lower = gtk_label_new("Lower Vel.");
GtkWidget* lbl_upper = gtk_label_new("Upper Vel.");
self->patch = -1;
gtk_table_attach_defaults(GTK_TABLE(table),lbl_chan,0,1,0,1);
gtk_widget_show(lbl_chan);
gtk_table_attach_defaults(GTK_TABLE(table),lbl_lower,0,1,1,2);
gtk_widget_show(lbl_lower);
gtk_table_attach_defaults(GTK_TABLE(table),lbl_upper,0,1,2,3);
gtk_widget_show(lbl_upper);
/* channel sliderbutton */
self->chan_sb = phin_slider_button_new_with_range(1, 1, MIDI_CHANS,1,0);
phin_slider_button_set_threshold(PHIN_SLIDER_BUTTON(self->chan_sb),
GUI_THRESHOLD);
gtk_table_attach_defaults(GTK_TABLE(table),self->chan_sb,1,2,0,1);
gtk_widget_show(self->chan_sb);
/* lower velocity slide */
self->lower_vel_sb = phin_slider_button_new_with_range(0, 0, 127, 1, 0);
phin_slider_button_set_threshold(PHIN_SLIDER_BUTTON(self->lower_vel_sb),
GUI_THRESHOLD);
gtk_table_attach_defaults(GTK_TABLE(table),self->lower_vel_sb,1,2,1,2);
gtk_widget_show(self->lower_vel_sb);
/* upper velocity slider */
self->upper_vel_sb = phin_slider_button_new_with_range(127, 0, 127, 1, 0);
phin_slider_button_set_threshold(PHIN_SLIDER_BUTTON(self->upper_vel_sb),
GUI_THRESHOLD);
gtk_table_attach_defaults(GTK_TABLE(table),self->upper_vel_sb,1,2,2,3);
gtk_widget_show(self->upper_vel_sb);
gui_pack(box, table);
/* done */
connect(self);
}
static void block(ChannelSection* self)
{
g_signal_handlers_block_by_func(self->chan_sb, channel_cb, self);
}
static void unblock(ChannelSection* self)
{
g_signal_handlers_unblock_by_func(self->chan_sb, channel_cb, self);
}
static void set_sensitive(ChannelSection* self, gboolean val)
{
gtk_widget_set_sensitive(self->chan_sb, val);
gtk_widget_set_sensitive(self->lower_vel_sb, val);
gtk_widget_set_sensitive(self->upper_vel_sb, val);
}
GtkWidget* channel_section_new(void)
{
return (GtkWidget*) g_object_new(CHANNEL_SECTION_TYPE, NULL);
}
void channel_section_set_patch(ChannelSection* self, int patch)
{
int channel, lower_vel, upper_vel;
self->patch = patch;
if (patch < 0)
set_sensitive(self, FALSE);
else
{
set_sensitive(self, TRUE);
channel = patch_get_channel(patch);
lower_vel = patch_get_lower_vel(patch);
upper_vel = patch_get_upper_vel(patch);
block(self);
phin_slider_button_set_value(PHIN_SLIDER_BUTTON(self->chan_sb),
channel+1);
phin_slider_button_set_value(PHIN_SLIDER_BUTTON(self->lower_vel_sb),
lower_vel);
phin_slider_button_set_value(PHIN_SLIDER_BUTTON(self->upper_vel_sb),
upper_vel);
unblock(self);
}
}
int channel_section_get_channel(ChannelSection* self)
{
return (self->patch < 0) ? 0 : patch_get_channel(self->patch);
}
|