diff -Nurp Petri-Foo_latest//src/dish_file.c Petri-Foo_vel_chan//src/dish_file.c --- Petri-Foo_latest//src/dish_file.c 2011-07-17 17:55:55.393396740 +1000 +++ Petri-Foo_vel_chan//src/dish_file.c 2011-07-17 17:57:33.759838031 +1000 @@ -434,6 +434,13 @@ int dish_file_write(const char *name) snprintf(buf, BUFSIZE, "%d", patch_get_upper_note(patch_id[i])); xmlNewProp(node2, BAD_CAST "upper", BAD_CAST buf); + + snprintf(buf, BUFSIZE, "%d", patch_get_lower_vel(patch_id[i])); + xmlNewProp(node2, BAD_CAST "velocity_lower", BAD_CAST buf); + + snprintf(buf, BUFSIZE, "%d", patch_get_upper_vel(patch_id[i])); + xmlNewProp(node2, BAD_CAST "velocity_upper", BAD_CAST buf); + /* ------------------------ amplitude @@ -657,7 +664,7 @@ int dish_file_read_sample(xmlNodePtr nod } else if (xmlStrcmp(node1->name, BAD_CAST "Note") == 0) { - int lower, root, upper; + int lower, root, upper, lower_vel, upper_vel; if ((prop = xmlGetProp(node1, BAD_CAST "root"))) if (sscanf((const char*)prop, "%d", &root) == 1) @@ -670,6 +677,14 @@ int dish_file_read_sample(xmlNodePtr nod if ((prop = xmlGetProp(node1, BAD_CAST "upper"))) if (sscanf((const char*)prop, "%d", &upper) == 1) patch_set_upper_note(patch_id, upper); + + if ((prop = xmlGetProp(node1, BAD_CAST "velocity_lower"))) + if (sscanf((const char*)prop, "%d", &lower_vel) == 1) + patch_set_lower_vel(patch_id, lower_vel); + + if ((prop = xmlGetProp(node1, BAD_CAST "velocity_upper"))) + if (sscanf((const char*)prop, "%d", &upper_vel) == 1) + patch_set_upper_vel(patch_id, upper_vel); } else { diff -Nurp Petri-Foo_latest//src/gui/channelsection.c Petri-Foo_vel_chan//src/gui/channelsection.c --- Petri-Foo_latest//src/gui/channelsection.c 2011-07-17 17:55:55.395396858 +1000 +++ Petri-Foo_vel_chan//src/gui/channelsection.c 2011-07-17 17:58:22.432202070 +1000 @@ -52,31 +52,79 @@ static void channel_cb(PhatSliderButton* } +static void lower_vel_cb(PhatSliderButton* button, ChannelSection* self) +{ + int lower_vel = (int)phat_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(PhatSliderButton* button, ChannelSection* self) +{ + int upper_vel = (int)phat_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* hbox = gtk_hbox_new(FALSE, 0); - GtkBox* h = GTK_BOX(hbox); - + 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; - gui_pack(box, hbox); - gui_label_pack("Channel:", h); - gui_pack(h, gui_hpad_new(GUI_TEXTSPACE)); + 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 = phat_slider_button_new_with_range(1, 1, MIDI_CHANS,1,0); phat_slider_button_set_threshold(PHAT_SLIDER_BUTTON(self->chan_sb), GUI_THRESHOLD); - gui_pack(h, self->chan_sb); + 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 = phat_slider_button_new_with_range(0, 0, 127, 1, 0); + phat_slider_button_set_threshold(PHAT_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 = phat_slider_button_new_with_range(127, 0, 127, 1, 0); + phat_slider_button_set_threshold(PHAT_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); } @@ -97,6 +145,8 @@ static void unblock(ChannelSection* 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); } @@ -108,7 +158,7 @@ GtkWidget* channel_section_new(void) void channel_section_set_patch(ChannelSection* self, int patch) { - int channel; + int channel, lower_vel, upper_vel; self->patch = patch; @@ -118,9 +168,16 @@ void channel_section_set_patch(ChannelSe { 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); phat_slider_button_set_value(PHAT_SLIDER_BUTTON(self->chan_sb), channel+1); + phat_slider_button_set_value(PHAT_SLIDER_BUTTON(self->lower_vel_sb), + lower_vel); + phat_slider_button_set_value(PHAT_SLIDER_BUTTON(self->upper_vel_sb), + upper_vel); unblock(self); } } diff -Nurp Petri-Foo_latest//src/gui/channelsection.h Petri-Foo_vel_chan//src/gui/channelsection.h --- Petri-Foo_latest//src/gui/channelsection.h 2011-07-17 17:55:55.396396917 +1000 +++ Petri-Foo_vel_chan//src/gui/channelsection.h 2011-07-17 17:58:27.304313844 +1000 @@ -58,6 +58,8 @@ struct _ChannelSection /* */ int patch; GtkWidget* chan_sb; + GtkWidget* lower_vel_sb; + GtkWidget* upper_vel_sb; }; diff -Nurp Petri-Foo_latest//src/patch.c Petri-Foo_vel_chan//src/patch.c --- Petri-Foo_latest//src/patch.c 2011-07-17 17:55:55.408397625 +1000 +++ Petri-Foo_vel_chan//src/patch.c 2011-07-17 18:07:12.799095985 +1000 @@ -1066,14 +1066,16 @@ void patch_trigger (int chan, int note, * the same note and have the same cut/cut_by values will end up * stepping over each other before they both are heard. */ - + int int_vel = (int)((vel*127)); // assumes vel comes in as fraction of 127 for (i = j = 0; i < PATCH_COUNT; i++) { if (patches[i] && patches[i]->active && patches[i]->channel == chan && (note >= patches[i]->lower_note - && note <= patches[i]->upper_note)) + && note <= patches[i]->upper_note) + && (int_vel >= patches[i]->lower_vel + && int_vel <= patches[i]->upper_vel)) { idp[j++] = i; } @@ -1085,7 +1087,9 @@ void patch_trigger (int chan, int note, /* do triggers */ for (i = 0; i < j; i++) + { patch_trigger_patch(patches[idp[i]], note, vel, ticks); + } } diff -Nurp Petri-Foo_latest//src/patch.h Petri-Foo_vel_chan//src/patch.h --- Petri-Foo_latest//src/patch.h 2011-07-17 17:55:55.408397625 +1000 +++ Petri-Foo_vel_chan//src/patch.h 2011-07-17 18:19:09.766874873 +1000 @@ -128,6 +128,7 @@ enum PATCH_LFO_ID_INVALID = -13, PATCH_MOD_SRC_INVALID = -14, PATCH_MOD_AMOUNT_INVALID = -15, + PATCH_VELOCITY_INVALID = -16, PATCH_MOD_SLOT_INVALID }; diff -Nurp Petri-Foo_latest//src/patch_private/patch_data.c Petri-Foo_vel_chan//src/patch_private/patch_data.c --- Petri-Foo_latest//src/patch_private/patch_data.c 2011-07-17 17:55:55.409397684 +1000 +++ Petri-Foo_vel_chan//src/patch_private/patch_data.c 2011-07-17 18:21:47.743489413 +1000 @@ -57,6 +57,8 @@ Patch* patch_new(void) p->note = 60; p->lower_note = 60; p->upper_note = 60; + p->lower_vel = 0; + p->upper_vel = 127; p->cut = 0; p->cut_by = 0; diff -Nurp Petri-Foo_latest//src/patch_private/patch_data.h Petri-Foo_vel_chan//src/patch_private/patch_data.h --- Petri-Foo_latest//src/patch_private/patch_data.h 2011-07-17 17:55:55.409397684 +1000 +++ Petri-Foo_vel_chan//src/patch_private/patch_data.h 2011-07-17 18:02:23.349828850 +1000 @@ -68,6 +68,8 @@ struct _Patch int play_stop; /* the last frame to play */ int loop_start; /* the first frame to loop at */ int loop_stop; /* the last frame to loop at */ + int lower_vel; /* lower velocity trigger */ + int upper_vel; /* upper velocity trigger */ int sample_stop; /* very last frame in sample */ diff -Nurp Petri-Foo_latest//src/patch_set_and_get.c Petri-Foo_vel_chan//src/patch_set_and_get.c --- Petri-Foo_latest//src/patch_set_and_get.c 2011-07-17 17:55:55.410397743 +1000 +++ Petri-Foo_vel_chan//src/patch_set_and_get.c 2011-07-17 18:13:33.486424451 +1000 @@ -1165,6 +1165,33 @@ int patch_set_upper_note (int id, int no return 0; } +/* sets the patch lower velocity */ +int patch_set_lower_vel (int id, int vel) +{ + if (!isok (id)) + return PATCH_ID_INVALID; + + if (vel < 0 || vel > 127) + return PATCH_VELOCITY_INVALID; + + patches[id]->lower_vel = vel; + return 0; +} + +/* sets the patch upper velocity */ +int patch_set_upper_vel (int id, int vel) +{ + if (!isok (id)) + return PATCH_ID_INVALID; + + if (vel < 0 || vel > 127) + return PATCH_VELOCITY_INVALID; + + patches[id]->upper_vel = vel; + return 0; +} + + /* set the amplitude */ int patch_set_amplitude (int id, float vol) { @@ -1408,6 +1435,24 @@ int patch_get_upper_note (int id) return patches[id]->upper_note; } +/* get the upper velocity trigger */ +int patch_get_upper_vel (int id) +{ + if (!isok(id)) + return PATCH_ID_INVALID; + + return patches[id]->upper_vel; +} + +/* get the lower velocity trigger */ +int patch_get_lower_vel (int id) +{ + if (!isok(id)) + return PATCH_ID_INVALID; + + return patches[id]->lower_vel; +} + /* get the amplitude */ float patch_get_amplitude (int id) { diff -Nurp Petri-Foo_latest//src/patch_set_and_get.h Petri-Foo_vel_chan//src/patch_set_and_get.h --- Petri-Foo_latest//src/patch_set_and_get.h 2011-07-17 17:55:55.411397802 +1000 +++ Petri-Foo_vel_chan//src/patch_set_and_get.h 2011-07-17 17:59:22.486306653 +1000 @@ -84,6 +84,8 @@ int patch_set_cut_by (int id, int int patch_set_cutoff (int id, float freq); int patch_set_legato (int id, bool val); int patch_set_lower_note (int id, int note); +int patch_set_lower_vel (int id, int vel); +int patch_set_upper_vel (int id, int vel); /* both of these return mark_id on success */ int patch_set_mark_frame (int patch_id, int mark_id, int frame); @@ -122,6 +124,8 @@ int patch_get_display_index (int id) int patch_get_frames (int id); bool patch_get_legato (int id); int patch_get_lower_note (int id); +int patch_get_lower_vel (int id); +int patch_get_upper_vel (int id); int patch_get_mark_frame (int patch_id, int mark_id); int patch_get_mark_frame_range(int patch_id, int mark_id, diff -Nurp Petri-Foo_latest//src/patch_util.c Petri-Foo_vel_chan//src/patch_util.c --- Petri-Foo_latest//src/patch_util.c 2011-07-17 17:55:55.411397802 +1000 +++ Petri-Foo_vel_chan//src/patch_util.c 2011-07-17 18:16:49.263819862 +1000 @@ -210,6 +210,8 @@ int patch_create_default(void) patch_sample_load(id, "Default", 0, 0, 0); p->lower_note = 36; p->upper_note = 83; + p->lower_vel = 0; + p->upper_vel = 127; patch_set_name(id, "Default");