-
Notifications
You must be signed in to change notification settings - Fork 13
/
main-page-patterns.c
3922 lines (3461 loc) · 132 KB
/
main-page-patterns.c
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Buzztrax
* Copyright (C) 2006 Buzztrax team <buzztrax-devel@buzztrax.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/**
* SECTION:btmainpagepatterns
* @short_description: the editor main pattern page
* @see_also: #BtPattern, #BtPatternEditor
*
* Provides an editor for #BtPattern instances.
*/
/* TODO(ensonic): shortcuts
* - on_pattern_table_key_press_event()
* - used keys:
* a: select all
* b: begin selection
* c: copy
* d:
* e: end selection
* f: flip
* g: transpose fine/coarse down
* h:
* i: interpolate
* j:
* k: select group
* l: select column
* m:
* n:
* o:
* p:
* q:
* r: randomize, randomize range
* s:
* t: transpose fine/coarse up
* u: unselect
* v: paste
* w:
* x: cut
* y:
* z:
*
* - Ctrl-S : Smooth
* - low pass median filter over values
* - when hitting empty tick, we can leave them blank for triggers and
* interpolate for others (maybe, default: skip, Ctrl-Shift-S: fill)
* - Ctrl-M : Mirror
* - value = max - (value-min))
* - Ctrl-Shift-M : Mirror-Range
* - like invert, but take min, max from the values in the selection
* - prev/next for combobox entries
* - trigger "move-active" action signal with GTK_SCROLL_STEP_UP/GTK_SCROLL_STEP_DOWN
* - what mechanism to use:
* - gtk_binding_entry_add_signal (do bindings work when not focused?)
* - gtk_widget_add_accelerator (can't specify signal params)
*/
/* TODO(ensonic): use gray text color for disconnected machines in the machine
* combobox (or machine without patterns) and unused waves
* (like for unused patterns)
* - sensitve property of renderer does not work in comboboxes
* (unlike in treeviews)
* -> we could use italic text in all of them
* ("style", PANGO_STYLE_ITALIC and "style-set")
*/
/* TODO(ensonic): play live note entry
* - support midi keyboard for entering notes and triggers
* - have poly-input mode
* - if there is a keydown, enter the note
* - if there is another keydown before a keyup, go to next voice and
* enter the note there.
* - on keyup, return 'cursor' to that column
* - what keys to use for trigger columns?
* - should we use shift+note for secondary note in same voice (e.g. slide)
*/
/* TODO(ensonic): add the same context menu entries as the machines have in
* machine view for current machine
* - e.g. allow to open machine settings/preferences
* see machine-canvas-item::show_machine_properties_dialog()
* bt_main_page_machines_show_properties_dialog(page,machine);
* bt_main_page_machines_show_preferences_dialog(page,machine);
* .. rename/about/help
* - also do controller-assignments like in machine-property window
*/
#define BT_EDIT
#define BT_MAIN_PAGE_PATTERNS_C
#include "bt-edit.h"
#include "gst/toneconversion.h"
#define MAX_WAVETABLE_ITEMS 200
#define DEFAULT_BASE_OCTAVE 4
struct _BtMainPagePatternsPrivate
{
/* used to validate if dispose has run */
gboolean dispose_has_run;
/* the application */
BtEditApplication *app;
/* machine selection menu */
GtkComboBox *machine_menu;
/* pattern selection menu */
GtkComboBox *pattern_menu;
/* wavetable selection menu */
GtkComboBox *wavetable_menu;
/* base octave selection menu */
GtkSpinButton *base_octave_menu;
/* the pattern table */
BtPatternEditor *pattern_table;
/* local commands */
GtkAccelGroup *accel_group;
/* pattern context_menu */
GtkMenu *context_menu;
GtkWidget *context_menu_voice_add, *context_menu_voice_remove;
GtkWidget *context_menu_pattern_properties, *context_menu_pattern_remove,
*context_menu_pattern_copy, *context_menu_machine_preferences;
/* cursor */
guint cursor_group, cursor_param;
glong cursor_row;
/* selection range */
glong selection_start_column;
glong selection_start_row;
glong selection_end_column;
glong selection_end_row;
/* selection first cell */
glong selection_column;
glong selection_row;
/* octave menu */
guint base_octave;
/* play live flag */
gboolean play_live;
/* the machine that is currently active */
BtMachine *machine;
/* the pattern that is currently shown */
BtPattern *pattern;
gulong number_of_groups, global_params, voice_params;
BtPatternEditorColumnGroup *param_groups;
guint *column_keymode;
/* editor change log */
BtChangeLog *change_log;
/* signal handler ids */
gint pattern_length_changed, pattern_voices_changed;
gint pattern_menu_changed;
/* cached setup properties */
GHashTable *properties;
};
/* - TODO(ensonic): we're converting GValue <-> str <-> float
* - we use bt_persistence to convert between GValue* and char*
* - we have bits and pieces here to convert between char* and float
* - bt_value_group can return strings or pointers to the GValue
*/
typedef struct
{
gfloat (*val_to_float) (gchar * in, gpointer user_data);
const gchar *(*float_to_str) (gfloat in, gpointer user_data);
gfloat min, max;
} BtPatternEditorColumnConverters;
//-- the class
static void bt_main_page_patterns_change_logger_interface_init (gpointer const
g_iface, gconstpointer const iface_data);
G_DEFINE_TYPE_WITH_CODE (BtMainPagePatterns, bt_main_page_patterns,
GTK_TYPE_BOX,
G_ADD_PRIVATE(BtMainPagePatterns)
G_IMPLEMENT_INTERFACE (BT_TYPE_CHANGE_LOGGER,
bt_main_page_patterns_change_logger_interface_init));
/* we need this in machine-properties-dialog.c too */
GdkAtom pattern_atom;
enum
{
PATTERN_KEYMODE_NOTE = 0,
PATTERN_KEYMODE_BOOL,
PATTERN_KEYMODE_NUMBER
};
typedef enum
{
UPDATE_COLUMN_POP = 1,
UPDATE_COLUMN_PUSH,
UPDATE_COLUMN_UPDATE
} BtPatternViewUpdateColumn;
#define PATTERN_CELL_WIDTH 70
#define PATTERN_CELL_HEIGHT 28
enum
{
METHOD_SET_GLOBAL_EVENTS = 0,
METHOD_SET_VOICE_EVENTS,
METHOD_SET_WIRE_EVENTS,
METHOD_SET_PROPERTY,
METHOD_ADD_PATTERN,
METHOD_REM_PATTERN,
METHOD_SET_VOICES,
};
static BtChangeLoggerMethods change_logger_methods[] = {
BT_CHANGE_LOGGER_METHOD ("set_global_events", 18,
"\"([-_a-zA-Z0-9 ]+)\",\"([-_a-zA-Z0-9 ]+)\",([0-9]+),([0-9]+),([0-9]+),(.*)$"),
BT_CHANGE_LOGGER_METHOD ("set_voice_events", 17,
"\"([-_a-zA-Z0-9 ]+)\",\"([-_a-zA-Z0-9 ]+)\",([0-9]+),([0-9]+),([0-9]+),([0-9]+),(.*)$"),
BT_CHANGE_LOGGER_METHOD ("set_wire_events", 16,
"\"([-_a-zA-Z0-9 ]+)\",\"([-_a-zA-Z0-9 ]+)\",\"([-_a-zA-Z0-9 ]+)\",([0-9]+),([0-9]+),([0-9]+),(.*)$"),
BT_CHANGE_LOGGER_METHOD ("set_pattern_property", 21,
"\"([-_a-zA-Z0-9 ]+)\",\"([-_a-zA-Z0-9 ]+)\",\"([-_a-zA-Z0-9 ]+)\",\"([-_a-zA-Z0-9 ]+)\"$"),
BT_CHANGE_LOGGER_METHOD ("add_pattern", 12,
"\"([-_a-zA-Z0-9 ]+)\",\"([-_a-zA-Z0-9 ]+)\",([0-9]+)$"),
BT_CHANGE_LOGGER_METHOD ("rem_pattern", 12,
"\"([-_a-zA-Z0-9 ]+)\",\"([-_a-zA-Z0-9 ]+)\"$"),
BT_CHANGE_LOGGER_METHOD ("set_voices", 10, "\"([-_a-zA-Z0-9 ]+)\",([0-9]+)$"),
{NULL,}
};
#define MAX_CHANGE_LOGGER_METHOD_LEN (22+1000)
static void on_context_menu_pattern_new_activate (GtkMenuItem * menuitem,
gpointer user_data);
static void on_context_menu_pattern_remove_activate (GtkMenuItem * menuitem,
gpointer user_data);
static void on_pattern_size_changed (BtPattern * pattern, GParamSpec * arg,
gpointer user_data);
static gboolean change_current_pattern (const BtMainPagePatterns * self,
BtPattern * new_pattern);
static BtMachine *get_current_machine (const BtMainPagePatterns * self);
static void pattern_edit_set_data_at (gpointer pattern_data,
gpointer column_data, guint row, guint track, guint param, guint digit,
gfloat value);
//-- tree model helper
static void
machine_menu_model_get_iter_by_machine (GtkTreeModel * store,
GtkTreeIter * iter, BtMachine * that_machine)
{
BtMachine *this_machine;
GST_INFO ("look up iter for machine : %" G_OBJECT_REF_COUNT_FMT,
G_OBJECT_LOG_REF_COUNT (that_machine));
if (gtk_tree_model_get_iter_first (store, iter)) {
do {
this_machine =
bt_machine_list_model_get_object ((BtMachineListModel *) store, iter);
if (this_machine == that_machine) {
GST_INFO ("found iter for machine : %" G_OBJECT_REF_COUNT_FMT,
G_OBJECT_LOG_REF_COUNT (that_machine));
break;
}
} while (gtk_tree_model_iter_next (store, iter));
}
}
static gboolean
pattern_menu_model_get_iter_by_pattern (GtkTreeModel * store,
GtkTreeIter * iter, BtPattern * that_pattern)
{
BtPattern *this_pattern;
gboolean res = FALSE;
if (gtk_tree_model_get_iter_first (store, iter)) {
do {
this_pattern =
bt_pattern_list_model_get_object ((BtPatternListModel *) store, iter);
if (this_pattern == that_pattern) {
res = TRUE;
break;
}
} while (gtk_tree_model_iter_next (store, iter));
}
return res;
}
//-- status bar helpers
static gchar *
pattern_view_get_cell_description (const BtMainPagePatterns * self, gint row,
gint group, gint param)
{
GParamSpec *prop = NULL;
BtValueGroup *vg;
BtParameterGroup *pg;
gchar *str = NULL, *desc = NULL;
GValue *v;
vg = self->priv->param_groups[group].vg;
g_object_get (vg, "parameter-group", &pg, NULL);
if (row >= 0 && (v = bt_value_group_get_event_data (vg, row, param)) &&
G_IS_VALUE (v)) {
desc = bt_parameter_group_describe_param_value (pg, param, v);
}
// get parameter description
if ((prop = bt_parameter_group_get_param_spec (pg, param))) {
const gchar *blurb = g_param_spec_get_blurb (prop);
if (desc && *desc) {
str = g_strdup_printf ("%s: %s: %s", prop->name, blurb, desc);
} else {
str = g_strdup_printf ("%s: %s", prop->name, blurb);
}
}
g_free (desc);
g_object_unref (pg);
return str;
}
static void
pattern_view_update_cell_description (const BtMainPagePatterns * self,
BtPatternViewUpdateColumn mode)
{
BtMainPagePatternsPrivate *p = self->priv;
BtMainWindow *main_window;
g_object_get (p->app, "main-window", &main_window, NULL);
// called too early
if (!main_window)
return;
// our page is not the current
if (mode & UPDATE_COLUMN_UPDATE) {
gint page_num;
bt_child_proxy_get (main_window, "pages::page", &page_num, NULL);
if (page_num != BT_MAIN_PAGES_PATTERNS_PAGE) {
g_object_unref (main_window);
return;
}
}
// pop previous text by passing str=NULL;
if (mode & UPDATE_COLUMN_POP)
bt_child_proxy_set (main_window, "statusbar::status", NULL, NULL);
if (mode & UPDATE_COLUMN_PUSH) {
if (p->pattern && p->number_of_groups) {
gchar *str;
g_object_get (p->pattern_table, "cursor-row", &p->cursor_row,
"cursor-param", &p->cursor_param,
"cursor-group", &p->cursor_group, NULL);
str = pattern_view_get_cell_description (self, p->cursor_row,
p->cursor_group, p->cursor_param);
bt_child_proxy_set (main_window, "statusbar::status",
(str ? str : BT_MAIN_STATUSBAR_DEFAULT), NULL);
g_free (str);
} else {
GST_DEBUG ("no or empty pattern");
bt_child_proxy_set (main_window, "statusbar::status",
_("Add new patterns from right click context menu."), NULL);
}
}
g_object_unref (main_window);
}
//-- undo/redo helpers
/* pattern_range_copy:
*
* Serialize the content of the range into @data.
*/
static void
pattern_range_copy (const BtMainPagePatterns * self, gint beg, gint end,
gint group, gint param, GString * data)
{
BtPatternEditorColumnGroup *pc_group;
GST_INFO ("copying : %d %d , %d %d", beg, end, group, param);
// process full pattern
if (group == -1 && param == -1) {
bt_pattern_serialize_columns (self->priv->pattern, beg, end, data);
}
// process whole group
if (group != -1 && param == -1) {
pc_group = &self->priv->param_groups[group];
bt_value_group_serialize_columns (pc_group->vg, beg, end, data);
}
// process one param in one group
if (group != -1 && param != -1) {
pc_group = &self->priv->param_groups[group];
bt_value_group_serialize_column (pc_group->vg, beg, end, param, data);
}
}
static void
pattern_column_log_undo_redo (const BtMainPagePatterns * self,
const gchar * fmt, gint param, gchar ** old_str, gchar ** new_str)
{
gchar *p, *undo_str, *redo_str;
p = strchr (*old_str, '\n');
*p = '\0';
undo_str = g_strdup_printf ("%s,%u,%s", fmt, param, *old_str);
*old_str = &p[1];
if (new_str) {
p = strchr (*new_str, '\n');
*p = '\0';
redo_str = g_strdup_printf ("%s,%u,%s", fmt, param, *new_str);
*new_str = &p[1];
} else {
redo_str = g_strdup (undo_str);
}
bt_change_log_add (self->priv->change_log, BT_CHANGE_LOGGER (self), undo_str,
redo_str);
}
static void
pattern_columns_log_undo_redo (const BtMainPagePatterns * self,
const gchar * fmt, guint num_columns, gchar ** old_str, gchar ** new_str)
{
guint i;
gchar *p, *undo_str, *redo_str;
for (i = 0; i < num_columns; i++) {
p = strchr (*old_str, '\n');
*p = '\0';
undo_str = g_strdup_printf ("%s,%u,%s", fmt, i, *old_str);
*old_str = &p[1];
if (new_str) {
p = strchr (*new_str, '\n');
*p = '\0';
redo_str = g_strdup_printf ("%s,%u,%s", fmt, i, *new_str);
*new_str = &p[1];
} else {
redo_str = g_strdup (undo_str);
}
bt_change_log_add (self->priv->change_log, BT_CHANGE_LOGGER (self),
undo_str, redo_str);
}
}
/* pattern_range_log_undo_redo:
*
* Add undo/redo events for the given data to the log.
*/
static void
pattern_range_log_undo_redo (const BtMainPagePatterns * self, gint beg,
gint end, gint group, gint param, gchar * old_str, gchar * new_str)
{
BtPatternEditorColumnGroup *pc_group;
BtMachine *machine;
gchar fmt[MAX_CHANGE_LOGGER_METHOD_LEN];
g_object_get (self->priv->pattern, "machine", &machine, NULL);
GST_INFO ("logging : %d %d , %d %d", beg, end, group, param);
// process full pattern
if (group == -1 && param == -1) {
gulong wire_groups, voices;
guint g, v;
bt_change_log_start_group (self->priv->change_log);
g_object_get (machine, "voices", &voices, NULL);
wire_groups = g_list_length (machine->dst_wires);
for (g = 0; g < wire_groups; g++) {
pc_group = &self->priv->param_groups[g];
g_snprintf (fmt, MAX_CHANGE_LOGGER_METHOD_LEN, pc_group->fmt, beg, end);
pattern_columns_log_undo_redo (self, fmt, pc_group->num_columns, &old_str,
&new_str);
}
if (self->priv->global_params) {
pc_group = &self->priv->param_groups[g];
g_snprintf (fmt, MAX_CHANGE_LOGGER_METHOD_LEN, pc_group->fmt, beg, end);
pattern_columns_log_undo_redo (self, fmt, pc_group->num_columns, &old_str,
&new_str);
g++;
}
for (v = 0; v < voices; v++, g++) {
pc_group = &self->priv->param_groups[g];
g_snprintf (fmt, MAX_CHANGE_LOGGER_METHOD_LEN, pc_group->fmt, beg, end);
pattern_columns_log_undo_redo (self, fmt, pc_group->num_columns, &old_str,
&new_str);
}
bt_change_log_end_group (self->priv->change_log);
}
// process whole group
if (group != -1 && param == -1) {
bt_change_log_start_group (self->priv->change_log);
pc_group = &self->priv->param_groups[group];
g_snprintf (fmt, MAX_CHANGE_LOGGER_METHOD_LEN, pc_group->fmt, beg, end);
pattern_columns_log_undo_redo (self, fmt, pc_group->num_columns, &old_str,
&new_str);
bt_change_log_end_group (self->priv->change_log);
}
// process one param in one group
if (group != -1 && param != -1) {
pc_group = &self->priv->param_groups[group];
g_snprintf (fmt, MAX_CHANGE_LOGGER_METHOD_LEN, pc_group->fmt, beg, end);
pattern_column_log_undo_redo (self, fmt, param, &old_str, &new_str);
}
g_object_unref (machine);
}
//-- selection helpers
/* this is used for delete/blend/randomize,
* - would be good to generalize to use it also for insert/delete-row.
* -> need to ignore row_end
* - would be good to use this for cut/copy/paste
* -> copy/cut want to return the data from the selection
* -> paste needs to receive the data from the selection
*/
static gboolean
pattern_selection_apply (const BtMainPagePatterns * self, BtValueGroupOp op)
{
gboolean res = FALSE;
gint beg, end, group, param;
if (bt_pattern_editor_get_selection (self->priv->pattern_table, &beg, &end,
&group, ¶m)) {
GString *old_data = g_string_new (NULL), *new_data = g_string_new (NULL);
BtPatternEditorColumnGroup *pc_group;
pattern_range_copy (self, beg, end, group, param, old_data);
GST_INFO ("applying : %d %d , %d %d", beg, end, group, param);
// process full pattern
if (group == -1 && param == -1) {
bt_pattern_transform_colums (self->priv->pattern, op, beg, end);
res = TRUE;
}
// process whole group
if (group != -1 && param == -1) {
pc_group = &self->priv->param_groups[group];
bt_value_group_transform_colums (pc_group->vg, op, beg, end);
res = TRUE;
}
// process one param in one group
if (group != -1 && param != -1) {
pc_group = &self->priv->param_groups[group];
bt_value_group_transform_colum (pc_group->vg, op, beg, end, param);
res = TRUE;
}
if (res) {
gtk_widget_queue_draw (GTK_WIDGET (self->priv->pattern_table));
pattern_range_copy (self, beg, end, group, param, new_data);
pattern_range_log_undo_redo (self, beg, end, group, param, old_data->str,
new_data->str);
}
g_string_free (old_data, TRUE);
g_string_free (new_data, TRUE);
}
return res;
}
//-- event handlers
#if 0
static void
on_pattern_added (BtMachine * machine, BtPattern * pattern, gpointer user_data)
{
/* this would be too early, the pattern properties are not set :/
BtMainPagePatterns *self=BT_MAIN_PAGE_PATTERNS(user_data);
// add undo/redo details
if(bt_change_log_is_active(self->priv->change_log)) {
gchar *undo_str,*redo_str;
gchar *mid,*pid,*pname;
gulong length;
g_object_get(machine,"id",&mid,NULL);
g_object_get(pattern,"id",&pid,"name",&pname,"length",&length,NULL);
undo_str = g_strdup_printf("rem_pattern \"%s\",\"%s\"",mid,pid);
redo_str = g_strdup_printf("add_pattern \"%s\",\"%s\",\"%s\",%lu",mid,pid,pname,length);
bt_change_log_add(self->priv->change_log,BT_CHANGE_LOGGER(self),undo_str,redo_str);
g_free(mid);g_free(pid);g_free(pname);
}
*/
}
#endif
static void
on_pattern_removed (BtMachine * machine, BtPattern * pattern,
gpointer user_data)
{
BtMainPagePatterns *self = BT_MAIN_PAGE_PATTERNS (user_data);
// add undo/redo details
if (bt_change_log_is_active (self->priv->change_log)) {
BtWire *wire;
gchar fmt[MAX_CHANGE_LOGGER_METHOD_LEN];
gchar *mid, *pid, *str, *undo_str, *redo_str;
gulong length;
gulong wire_params, voices, global_params, voice_params;
guint end;
GList *node;
GString *data = g_string_new (NULL);
guint v;
g_object_get (pattern, "name", &pid, "length", &length, NULL);
g_object_get (machine, "id", &mid, "voices", &voices, "global-params",
&global_params, "voice-params", &voice_params, NULL);
bt_change_log_start_group (self->priv->change_log);
undo_str =
g_strdup_printf ("add_pattern \"%s\",\"%s\",%lu", mid, pid, length);
redo_str = g_strdup_printf ("rem_pattern \"%s\",\"%s\"", mid, pid);
bt_change_log_add (self->priv->change_log, BT_CHANGE_LOGGER (self),
undo_str, redo_str);
/* we can't use the usual helpers here
* - we don't need redo data
* - we don't have the BtPatternEditorColumnGroup
*/
end = length - 1;
bt_pattern_serialize_columns (pattern, 0, end, data);
GST_DEBUG ("serialized size: %" G_GSIZE_FORMAT, data->len);
g_string_append_c (data, '\n');
str = data->str;
// log events
for (node = machine->dst_wires; node; node = g_list_next (node)) {
BtMachine *smachine;
gchar *smid;
wire = (BtWire *) node->data;
g_object_get (wire, "src", &smachine, "num-params", &wire_params, NULL);
g_object_get (smachine, "id", &smid, NULL);
g_snprintf (fmt, MAX_CHANGE_LOGGER_METHOD_LEN,
"set_wire_events \"%s\",\"%s\",\"%s\",0,%u", smid, mid, pid, end);
pattern_columns_log_undo_redo (self, fmt, wire_params, &str, NULL);
g_free (smid);
g_object_unref (smachine);
}
if (global_params) {
g_snprintf (fmt, MAX_CHANGE_LOGGER_METHOD_LEN,
"set_global_events \"%s\",\"%s\",0,%u", mid, pid, end);
pattern_columns_log_undo_redo (self, fmt, global_params, &str, NULL);
}
for (v = 0; v < voices; v++) {
g_snprintf (fmt, MAX_CHANGE_LOGGER_METHOD_LEN,
"set_voice_events \"%s\",\"%s\",0,%u,%u", mid, pid, end, v);
pattern_columns_log_undo_redo (self, fmt, voice_params, &str, NULL);
}
g_string_free (data, TRUE);
bt_change_log_end_group (self->priv->change_log);
g_free (mid);
g_free (pid);
}
GST_DEBUG ("removed pattern: %" G_OBJECT_REF_COUNT_FMT,
G_OBJECT_LOG_REF_COUNT (pattern));
}
// use key-press-event, as then we get key repeats
static gboolean
on_pattern_table_key_press_event (GtkWidget * widget, GdkEventKey * event,
gpointer user_data)
{
BtMainPagePatterns *self = BT_MAIN_PAGE_PATTERNS (user_data);
BtMainPagePatternsPrivate *p = self->priv;
gboolean res = FALSE;
gulong modifier =
(gulong) event->state & gtk_accelerator_get_default_mod_mask ();
//gulong modifier=(gulong)event->state&(GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_MOD4_MASK);
if (!gtk_widget_get_realized (GTK_WIDGET (p->pattern_table)))
return FALSE;
GST_INFO
("pattern_table key : state 0x%x, keyval 0x%x, hw-code 0x%x, name %s",
event->state, event->keyval, event->hardware_keycode,
gdk_keyval_name (event->keyval));
if (event->keyval == GDK_KEY_Return) { /* GDK_KP_Enter */
bt_child_proxy_set (p->app, "main-window::pages::page",
BT_MAIN_PAGES_SEQUENCE_PAGE, NULL);
/* TODO(ensonic): if we came from sequence page via Enter we could go back
* to where we came from, but if the machine or pattern has been changed
* here, we could go to first track and first pos where the new pattern is
* used.
*/
//BtMainPageSequence *sequence_page;
//bt_child_proxy_get(p->app,"main-window::pages::sequence-page",&sequence_page,NULL);
//bt_main_page_sequence_goto_???(sequence_page,pattern);
//g_object_unref(sequence_page);
res = TRUE;
} else if (event->keyval == GDK_KEY_Menu) {
gtk_menu_popup (p->context_menu, NULL, NULL, NULL, NULL,
GDK_BUTTON_SECONDARY, gtk_get_current_event_time ());
res = TRUE;
} else if (event->keyval == ',') {
BtPatternEditorColumnGroup *group;
BtParameterGroup *pg;
guint param;
// copy the current value from the machine to the pattern
g_object_get (p->pattern_table, "cursor-row",
&p->cursor_row, "cursor-group", &p->cursor_group,
"cursor-param", &p->cursor_param, NULL);
group = &p->param_groups[p->cursor_group];
param = p->cursor_param;
g_object_get (group->vg, "parameter-group", &pg, NULL);
// don't do this for trigger params !!!!! (not readable) =======================
if (!bt_parameter_group_is_param_trigger (pg, param)) {
GObject *parent;
const gchar *prop_name;
GValue value = { 0, };
gchar *str;
gulong number_of_ticks;
BtPatternEditorColumnConverters *pcc = (BtPatternEditorColumnConverters *)
group->columns[param].user_data;
parent = bt_parameter_group_get_param_parent (pg, param);
prop_name = bt_parameter_group_get_param_name (pg, param);
g_value_init (&value, bt_parameter_group_get_param_type (pg, param));
g_object_get_property (parent, prop_name, &value);
str = bt_str_format_gvalue (&value);
GST_DEBUG ("get property %s: %s", prop_name, str);
pattern_edit_set_data_at (self, pcc, p->cursor_row,
p->cursor_group, param, 0, pcc->val_to_float (str, pcc));
g_object_get (p->pattern, "length", &number_of_ticks, NULL);
if (p->cursor_row + 1 < number_of_ticks) {
g_object_set (p->pattern_table, "cursor-row", p->cursor_row + 1, NULL);
}
gtk_widget_queue_draw (GTK_WIDGET (p->pattern_table));
g_free (str);
g_value_unset (&value);
}
g_object_unref (pg);
} else if (event->keyval == GDK_KEY_Insert) {
GString *old_data = g_string_new (NULL), *new_data = g_string_new (NULL);
gulong number_of_ticks;
gint beg, end, group, param;
g_object_get (p->pattern_table, "cursor-row",
&p->cursor_row, "cursor-group", &p->cursor_group,
"cursor-param", &p->cursor_param, NULL);
g_object_get (p->pattern, "length", &number_of_ticks, NULL);
beg = p->cursor_row;
end = number_of_ticks - 1;
if ((modifier & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) ==
(GDK_CONTROL_MASK | GDK_SHIFT_MASK)) {
group = -1;
param = -1;
} else if (modifier & GDK_SHIFT_MASK) {
group = p->cursor_group;
param = -1;
} else {
group = p->cursor_group;
param = p->cursor_param;
}
pattern_range_copy (self, beg, end, group, param, old_data);
if ((modifier & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) ==
(GDK_CONTROL_MASK | GDK_SHIFT_MASK)) {
// insert full row
GST_INFO ("ctrl-shift-insert pressed, row %lu", p->cursor_row);
bt_pattern_insert_row (p->pattern, p->cursor_row);
res = TRUE;
} else if (modifier & GDK_SHIFT_MASK) {
BtPatternEditorColumnGroup *group = &p->param_groups[p->cursor_group];
// insert group
GST_INFO ("shift-insert pressed, row %ld, group %u",
p->cursor_row, p->cursor_group);
bt_value_group_insert_full_row (group->vg, p->cursor_row);
res = TRUE;
} else {
BtPatternEditorColumnGroup *group = &p->param_groups[p->cursor_group];
// insert column
GST_INFO ("insert pressed, row %ld, group %u, param %u",
p->cursor_row, p->cursor_group, p->cursor_param);
bt_value_group_insert_row (group->vg, p->cursor_row, p->cursor_param);
res = TRUE;
}
if (res) {
gtk_widget_queue_draw (GTK_WIDGET (p->pattern_table));
pattern_range_copy (self, beg, end, group, param, new_data);
pattern_range_log_undo_redo (self, beg, end, group, param, old_data->str,
new_data->str);
}
g_string_free (old_data, TRUE);
g_string_free (new_data, TRUE);
} else if (event->keyval == GDK_KEY_Delete) {
GString *old_data = g_string_new (NULL), *new_data = g_string_new (NULL);
gulong number_of_ticks;
gint beg, end, group, param;
g_object_get (p->pattern_table, "cursor-row",
&p->cursor_row, "cursor-group", &p->cursor_group,
"cursor-param", &p->cursor_param, NULL);
g_object_get (p->pattern, "length", &number_of_ticks, NULL);
beg = p->cursor_row;
end = number_of_ticks - 1;
if ((modifier & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) ==
(GDK_CONTROL_MASK | GDK_SHIFT_MASK)) {
group = -1;
param = -1;
} else if (modifier & GDK_SHIFT_MASK) {
group = p->cursor_group;
param = -1;
} else {
group = p->cursor_group;
param = p->cursor_param;
}
pattern_range_copy (self, beg, end, group, param, old_data);
if ((modifier & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) ==
(GDK_CONTROL_MASK | GDK_SHIFT_MASK)) {
// delete full row
GST_INFO ("ctrl-shift-delete pressed, row %lu", p->cursor_row);
bt_pattern_delete_row (p->pattern, p->cursor_row);
res = TRUE;
} else if (modifier & GDK_SHIFT_MASK) {
BtPatternEditorColumnGroup *group = &p->param_groups[p->cursor_group];
// delete group
GST_INFO ("delete pressed, row %ld, group %u", p->cursor_row,
p->cursor_group);
bt_value_group_delete_full_row (group->vg, p->cursor_row);
res = TRUE;
} else {
BtPatternEditorColumnGroup *group = &p->param_groups[p->cursor_group];
// delete column
GST_INFO ("delete pressed, row %ld, group %u, param %u",
p->cursor_row, p->cursor_group, p->cursor_param);
bt_value_group_delete_row (group->vg, p->cursor_row, p->cursor_param);
res = TRUE;
}
if (res) {
gtk_widget_queue_draw (GTK_WIDGET (p->pattern_table));
pattern_range_copy (self, beg, end, group, param, new_data);
pattern_range_log_undo_redo (self, beg, end, group, param, old_data->str,
new_data->str);
}
g_string_free (old_data, TRUE);
g_string_free (new_data, TRUE);
} else if (event->keyval == GDK_KEY_f) {
if (modifier & GDK_CONTROL_MASK) {
res = pattern_selection_apply (self, BT_VALUE_GROUP_OP_FLIP);
}
} else if (event->keyval == GDK_KEY_i) {
if (modifier & GDK_CONTROL_MASK) {
res = pattern_selection_apply (self, BT_VALUE_GROUP_OP_BLEND);
}
} else if (event->keyval == GDK_KEY_r) {
if (modifier & GDK_CONTROL_MASK) {
res = pattern_selection_apply (self, BT_VALUE_GROUP_OP_RANDOMIZE);
}
} else if (event->keyval == GDK_KEY_R) {
if (modifier & GDK_CONTROL_MASK) {
res = pattern_selection_apply (self, BT_VALUE_GROUP_OP_RANGE_RANDOMIZE);
}
} else if (event->keyval == GDK_KEY_t) {
if (modifier & GDK_CONTROL_MASK) {
res = pattern_selection_apply (self, BT_VALUE_GROUP_OP_TRANSPOSE_FINE_UP);
}
} else if (event->keyval == GDK_KEY_T) {
if (modifier & GDK_CONTROL_MASK) {
res = pattern_selection_apply (self,
BT_VALUE_GROUP_OP_TRANSPOSE_COARSE_UP);
}
} else if (event->keyval == GDK_KEY_g) {
if (modifier & GDK_CONTROL_MASK) {
res = pattern_selection_apply (self,
BT_VALUE_GROUP_OP_TRANSPOSE_FINE_DOWN);
}
} else if (event->keyval == GDK_KEY_G) {
if (modifier & GDK_CONTROL_MASK) {
res = pattern_selection_apply (self,
BT_VALUE_GROUP_OP_TRANSPOSE_COARSE_DOWN);
}
} else if ((event->keyval == GDK_KEY_Up) && (modifier == GDK_CONTROL_MASK)) {
g_signal_emit_by_name (p->machine_menu, "move-active",
GTK_SCROLL_STEP_BACKWARD, NULL);
res = TRUE;
} else if ((event->keyval == GDK_KEY_Down) && (modifier == GDK_CONTROL_MASK)) {
g_signal_emit_by_name (p->machine_menu, "move-active",
GTK_SCROLL_STEP_FORWARD, NULL);
res = TRUE;
} else if (event->keyval == GDK_KEY_KP_Subtract) {
g_signal_emit_by_name (p->pattern_menu, "move-active",
GTK_SCROLL_STEP_BACKWARD, NULL);
res = TRUE;
} else if (event->keyval == GDK_KEY_KP_Add) {
g_signal_emit_by_name (p->pattern_menu, "move-active",
GTK_SCROLL_STEP_FORWARD, NULL);
res = TRUE;
} else if (event->keyval == GDK_KEY_KP_Divide) {
g_signal_emit_by_name (p->base_octave_menu, "change-value",
GTK_SCROLL_STEP_BACKWARD, NULL);
res = TRUE;
} else if (event->keyval == GDK_KEY_KP_Multiply) {
g_signal_emit_by_name (p->base_octave_menu, "change-value",
GTK_SCROLL_STEP_FORWARD, NULL);
res = TRUE;
} else if (event->keyval == GDK_KEY_less) {
g_signal_emit_by_name (p->wavetable_menu, "move-active",
GTK_SCROLL_STEP_BACKWARD, NULL);
res = TRUE;
} else if (event->keyval == GDK_KEY_greater) {
g_signal_emit_by_name (p->wavetable_menu, "move-active",
GTK_SCROLL_STEP_FORWARD, NULL);
res = TRUE;
}
return res;
}
static gboolean
on_pattern_table_button_press_event (GtkWidget * widget, GdkEventButton * event,
gpointer user_data)
{
BtMainPagePatterns *self = BT_MAIN_PAGE_PATTERNS (user_data);
gboolean res = FALSE;
GST_INFO ("pattern_table button_press : button 0x%x, type 0x%d",
event->button, event->type);
if (event->button == GDK_BUTTON_SECONDARY) {
gtk_menu_popup (self->priv->context_menu, NULL, NULL, NULL, NULL,
GDK_BUTTON_SECONDARY, gtk_get_current_event_time ());
res = TRUE;
}
return res;
}
static void
on_pattern_table_cursor_group_changed (const BtPatternEditor * editor,
GParamSpec * arg, gpointer user_data)
{
BtMainPagePatterns *self = BT_MAIN_PAGE_PATTERNS (user_data);
g_object_get ((gpointer) editor, "cursor-group", &self->priv->cursor_group,
"cursor-param", &self->priv->cursor_param, NULL);
pattern_view_update_cell_description (self, UPDATE_COLUMN_UPDATE);
}
static void
on_pattern_table_cursor_param_changed (const BtPatternEditor * editor,
GParamSpec * arg, gpointer user_data)
{
BtMainPagePatterns *self = BT_MAIN_PAGE_PATTERNS (user_data);
g_object_get ((gpointer) editor, "cursor-param", &self->priv->cursor_param,
NULL);
pattern_view_update_cell_description (self, UPDATE_COLUMN_UPDATE);
}
static void
on_pattern_table_cursor_row_changed (const BtPatternEditor * editor,
GParamSpec * arg, gpointer user_data)
{
BtMainPagePatterns *self = BT_MAIN_PAGE_PATTERNS (user_data);
g_object_get ((gpointer) editor, "cursor-row", &self->priv->cursor_row, NULL);
pattern_view_update_cell_description (self, UPDATE_COLUMN_UPDATE);
}
static gboolean
on_pattern_table_query_tooltip (GtkWidget * widget, gint x, gint y,
gboolean keyboard_mode, GtkTooltip * tooltip, gpointer user_data)
{