-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
2600 lines (2300 loc) · 66.3 KB
/
main.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
/* main.c
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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
xreplacestringGNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'candor' is JACK-enabled realtime performance software for use
with a monome (http://www.monome.org/).
Copyright 2014 murray foster */
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <monome.h>
#include <jack/jack.h>
#include <alsa/asoundlib.h>
#include <lo/lo.h>
#include "libficus.h"
unsigned int grid[16][16] = { [0 ... 15][0 ... 15] = 0 };
unsigned int grid_led_state[16][16] = { [0 ... 15][0 ... 15] = 0 };
unsigned int mixer_row_grid[16][16] = { [0 ... 15][0 ... 15] = 0 };
/* following arrays keep track of Leds for each 'page'/mode for each device
sampler - sampler_page_pos
[0] - playback
[1] - loop
[2] - kill playback per sample
[3] - capture
[4] - set capture time limit
[5] - input mixer
[6] - output mixer
[7] - kill all playback
sequencer - sequencer_page_pos
[0] - playhead view
[1] - voices per 1st 8 steps
[2] - voices per 2nd 8 steps
[3] - voices per 3rd 8 steps
[4] - voices per 4th 8 steps
[5] - voices per 5th 8 steps
[6] - voices per 6th 8 steps
[7] - start/stop sequencer */
int sampler_page_pos[8] = {0};
int sampler_page_leds[48] = {0};
int sampler_loop_leds[48] = {0};
/* sampler_capture_leds[0] == 1 : armed
sampler_capture_leds[1] == 1 : capturing */
int sampler_capture_leds[2][48] = {{0}};
/* used to load the sample after we're
finished capturing it */
int sampler_capture_loadcheck[48] = {0};
int sampler_capture_armed_order[48] = {-1};
int sampler_capture_armed_pos = 0;
int sampler_capture_armed_pos_read = 0;
int sampler_capture_armed_count = 0;
/* sampler_capture_limit_leds[0] : limit multiple
sampler_capture_limit_leds[1] : refresh storage
sampler_capture_limit_leds[2] : limit */
int sampler_capture_limit_leds[2] = {0};
int sampler_capture_limit=0;
int sampler_capture_limit_set=0;
int sampler_inmix_leds[48] = {0};
int sampler_outmix_leds[48] = {0};
int sampler_monitors[8] = {0};
int sequencer_page_pos[7] = {0};
/* these integers hold libficus' state */
int *playback_state;
int *loop_state;
int *capture_state;
int *limitcapture_state;
int *inputmix_state;
int *outputmix_state;
/* global path/prefix for sample storage on disk */
char *sampler_path=NULL;
char *sampler_prefix=NULL;
/* tap_recorder_leds[0]==0 off
tap_recorder_leds[0]==1 armed
tap_recorder_leds[1]==1 recording */
int tap_recorder_leds[2]={0};
/* tap recorder step storage */
int recorded_steps[15000000]={0};
/* signals sequencer to play next step */
int sequencer_nextstep_pretap=0;
/* sequencer playhead/position/tempo */
int seq_playhead=0;
int seq_stepcount=0;
float seq_bpm=0.0;
int seq_bpm_led=0;
int seq_bpm_dec_led=0;
int seq_bpm_inc_led=0;
int sequencer_voice_leds[6][48]={{0}};
int sequencer_bank_pos[7]={0};
int sequencer_bank_leds[6][48]={{0}};
int sequencer_bank_select=0;
int sequencer_transport_led = 0;
/* for samples assigned to this map,
index starts at '1'. '0' is
unassigned */
int sequencer_voice_map[6][48]={{0}};
float sampler_playback_speed=0;
int playback_speed_led=0;
int playback_reverse=0;
float sampler_playback_rampup=0;
float sampler_playback_rampdown=0;
int playback_rampup_led=0;
int playback_rampdown_led=0;
int playback_upnoclip=0;
int playback_downnoclip=0;
int playback_modifiers_enable[48]={0};
/* these are the speed and attack/decay ramps for
each sample. given x is any sample;
playback_modifiers[x][0] - speed
..[x][1] - attack
..[x][2] - decay
*/
float playback_modifiers[48][3]={{0}};
int signal_playback_trigger[48] = {0};
/* these variables are for automagically hooking up monome */
char *monome_name;
char *monome_name_user_defined="init";
char *monome_device_type;
int monome_serialosc_port = 0;
/* serialosc host, default = 127.0.0.1, port: 12002 */
int osc_interface_disable = 0;
/* osc_port_out to be used by all outgoing osc messages */
char *osc_port_out = NULL;
/* button state used to indicate if we are accepting internal clock signal */
int external_clock_enable = 0;
void
managed_led_on(monome_t *monome, int x, int y)
{
if(grid_led_state[x][y] != 1) {
monome_led_on(monome, x, y);
grid_led_state[x][y] = 1;
}
}
void
managed_led_off(monome_t *monome, int x, int y)
{
if(grid_led_state[x][y] != 0) {
monome_led_off(monome, x, y);
grid_led_state[x][y] = 0;
}
}
void
managed_led_set(monome_t *monome, int x, int y, int state)
{
if(grid_led_state[x][y] != state) {
monome_led_set(monome, x, y, state);
grid_led_state[x][y] = state;
}
}
void
init_default_state(monome_t *monome)
{
/* on sampler, we start out on the 'playback' page.
on sequencer, we start out on the first page */
sequencer_page_pos[0]=1;
sampler_page_pos[0]=1;
sampler_capture_limit_leds[0]=0;
/* 48 is OFF for the following two LED states */
sampler_capture_limit_leds[1]=48;
sampler_capture_limit_leds[2]=48;
seq_bpm=7.5;
managed_led_on(monome,0,6);
sequencer_bank_pos[1]=1;
sampler_playback_speed=1.0;
playback_speed_led=4;
} /* init_default_state */
void
clear_frame(const monome_event_t *e, int xmod, int ymod)
{
/* black out top 6 rows of interactive LEDs */
int x, y;
for( x=0; x<8; x++)
for( y=0; y<6; y++)
managed_led_off(e->monome, x+xmod, y+ymod);
} /* clear_frame */
void
clear_frame_monome(monome_t *monome, int xmod, int ymod)
{
/* black out top 6 rows of interactive LEDs */
int x, y;
for( x=0; x<8; x++)
for( y=0; y<6; y++)
managed_led_off(monome, x+xmod, y+ymod);
} /* clear_frame_monome */
int
coordinate_to_led(int x, int y)
{
return (x + 1) * (y + 1) + (7 * y) - (x * y) - 1;
} /* coordinate_to_led */
void
clear_armed()
{
int c=0;
/* clear all samples 'armed' for capturing */
for(c=0; c<48; c++)
sampler_capture_leds[0][c] = 0;
memset(sampler_capture_armed_order,-1,48);
sampler_capture_armed_count = 0;
sampler_capture_armed_pos = 0;
sampler_capture_armed_pos_read = 0;
} /* clear_armed */
void
fill_sampler_row(monome_t *monome, int y, int x, int xmod)
{
int i;
for(i=0; i<x; i++)
managed_led_on(monome, i+xmod, y);
} /* fill_sampler_row */
void
fill_to_button(monome_t *monome, int button)
{
/* fill led rows of this quadrant to the given button */
int x, y;
/* first, clear all LEDs */
clear_frame_monome(monome, 8, 0);
/* figure out how many LEDs to light up and do it */
if( button < 8 )
fill_sampler_row(monome, 0, button+1, 8);
else
if( (button < 16) && (button > 7) )
{
fill_sampler_row(monome, 0, 8, 8);
fill_sampler_row(monome, 1, button-7, 8);
}
else
if( (button < 24) && (button > 15))
{
fill_sampler_row(monome, 0, 8, 8);
fill_sampler_row(monome, 1, 8, 8);
fill_sampler_row(monome, 2, button-15, 8);
}
else
if( (button < 32) && (button > 23) )
{
fill_sampler_row(monome, 0, 8, 8);
fill_sampler_row(monome, 1, 8, 8);
fill_sampler_row(monome, 2, 8, 8);
fill_sampler_row(monome, 3, button-23, 8);
}
else
if( (button < 40) && (button > 31) )
{
fill_sampler_row(monome, 0, 8, 8);
fill_sampler_row(monome, 1, 8, 8);
fill_sampler_row(monome, 2, 8, 8);
fill_sampler_row(monome, 3, 8, 8);
fill_sampler_row(monome, 4, button-31, 8);
}
else
if( (button < 48) && (button > 39) )
{
fill_sampler_row(monome, 0, 8, 8);
fill_sampler_row(monome, 1, 8, 8);
fill_sampler_row(monome, 2, 8, 8);
fill_sampler_row(monome, 3, 8, 8);
fill_sampler_row(monome, 4, 8, 8);
fill_sampler_row(monome, 5, button-39, 8);
}
else
fprintf(stderr, "candor: fill_to_button() is FUBARD\n");
} /* fill_to_button */
void
set_input_group(int bank, int state)
{
int c=0;
if( bank<8 )
for(c=0; c<8; c++)
ficus_setmixin(c, bank, state);
else
if( bank<16 )
for(c=8; c<16; c++)
ficus_setmixin(c, bank-8, state);
else
if( bank<24 )
for(c=16; c<24; c++)
ficus_setmixin(c, bank-16, state);
else
if( bank<32 )
for(c=24; c<32; c++)
ficus_setmixin(c, bank-24, state);
else
if( bank<40 )
for(c=32; c<40; c++)
ficus_setmixin(c, bank-32, state);
else
if( bank<48 )
for(c=40; c<48; c++)
ficus_setmixin(c, bank-40, state);
} /* set_input_group */
void
set_output_group(int bank, int state)
{
int c=0;
if( bank<8 )
for(c=0; c<8; c++)
ficus_setmixout(c, bank, state);
else
if( bank<16 )
for(c=8; c<16; c++)
ficus_setmixout(c, bank-8, state);
else
if( bank<24 )
for(c=16; c<24; c++)
ficus_setmixout(c, bank-16, state);
else
if( bank<32 )
for(c=24; c<32; c++)
ficus_setmixout(c, bank-24, state);
else
if( bank<40 )
for(c=32; c<40; c++)
ficus_setmixout(c, bank-32, state);
else
if( bank<48 )
for(c=40; c<48; c++)
ficus_setmixout(c, bank-40, state);
} /* set_output_group */
int candor_playback(int samplenum)
{
int button=0;
button=samplenum;
/* we need to put the ficus modifier calls here */
if(playback_modifiers_enable[button])
{
ficus_playback_speed(button,playback_modifiers[button][0]);
ficus_playback_rampup(button,playback_modifiers[button][1]);
ficus_playback_rampdown(button,playback_modifiers[button][2]);
}
else
{
ficus_playback_speed(button,1);
ficus_playback_rampup(button,0.0);
ficus_playback_rampdown(button,0.0);
}
ficus_playback(button);
return 0;
}/* candor_playback */
int
sampler_page_chooser(const monome_event_t *e, int button)
{
unsigned int c, page=0;
int finallimit=0;
char *tempstring;
/* store our bank number */
for(c=0; c<7; c++)
if( sampler_page_pos[c] )
page = c;
/* triggers appropriate actions based on given
linear button number and selected mode */
/* sampler */
switch( page )
{
/* playback page */
case 0:
/* if you hold down the 'playback' menu button, and
press one of the sample pads, if that sample is currently
playing it will kill the playback for that sample. */
if(grid[8][7]==1)
ficus_killplayback(button);
else
{
playback_modifiers[button][1]=sampler_playback_rampup;
playback_modifiers[button][2]=sampler_playback_rampdown;
/* set speed/ramp parameters */
playback_modifiers[button][0]=sampler_playback_speed;
if( playback_reverse )
playback_modifiers[button][0]*=-1;
candor_playback(button);
}
break;
case 1:
/* looping page */
if( ficus_islooping(button) )
ficus_loop(button, 0);
else
ficus_loop(button, 1);
break;
case 2:
/* toggle modifiers page */
playback_modifiers_enable[button]=!playback_modifiers_enable[button];
/* set speed/ramp parameters */
playback_modifiers[button][0]=sampler_playback_speed;
if( playback_reverse )
playback_modifiers[button][0]*=-1;
playback_modifiers[button][1]=sampler_playback_rampup;
playback_modifiers[button][2]=sampler_playback_rampdown;
break;
case 3:
/* capture page */
if( !sampler_capture_leds[0][button] &&
sampler_capture_leds[1][button] ) {
ficus_killcapture(button);
for(c=0;c<48;c++)
if(sampler_capture_armed_order[c]==button)
sampler_capture_armed_order[c] = -1;
}
else
if( sampler_capture_leds[0][button] &&
!sampler_capture_leds[1][button] )
{
/* ficus_capturef_in captures an audio file to a bank for n
number of frames. we calculate the recording time IF there
is a set limit. */
/* impose a capture limit if one is set */
/* if (!ficus_durationf_out(sampler_capture_limit))
finallimit=0;
else {
finallimit=ficus_durationf_out(sampler_capture_limit) *
(sampler_capture_limit_leds[0] + 1);
} */
finallimit = 0;
ficus_capturef(button, finallimit);
sampler_capture_leds[0][button]=0;
/* we have to wait to load this sample until we're
done recording so we add a check for it in our
state_manager() and wait on it */
/* WE NEED TO WRITE THE NEW SOUNDFILE TO A TEMPORARY
FILE AND THEN REPLACE IT WHEN DONE RECORDING USING
A FILESYSTEM OPERATION SO WE AVOID PLAYBACK OF
AUDIO THAT'S NOT FINISHED CAPTURING. THIS IS TO
BE DONE (PROBABLY) IN libficus.c
^^badly worded, but you'll remember (looping) */
sampler_capture_loadcheck[button]=1;
sampler_capture_armed_count = sampler_capture_armed_count - 1;
for( c=0; c<48; c++)
if( sampler_capture_armed_order[c] == button )
sampler_capture_armed_order[c] = -1;
}
else
if( !sampler_capture_leds[0][button] &&
!sampler_capture_leds[1][button] )
{
sampler_capture_leds[0][button] = 1;
sampler_capture_armed_order[sampler_capture_armed_pos] = button;
sampler_capture_armed_count += 1;
sampler_capture_armed_pos += 1;
if( sampler_capture_armed_pos == 48 )
sampler_capture_armed_pos = 0;
}
else
fprintf(stderr, "candor: capture page is FUBARD\n");
break;
case 4:
if (grid[12][7]==1)
{
if( sampler_capture_limit_leds[2]==button )
{
sampler_capture_limit_leds[2]=48;
/* we set the capture_limits_led[1] and [2] to 48
to trigger a refresh on the page so we
don't have LEDs out that we need on. */
sampler_capture_limit_leds[1]=48;
sampler_capture_limit=48;
sampler_capture_limit_set=0;
}
else
{
sampler_capture_limit_leds[2]=button;
sampler_capture_limit=button;
sampler_capture_limit_set=1;
/* see explanation in the corresponding
'if' to this 'else' */
sampler_capture_limit_leds[1]=48;
}
}
else
{
sampler_capture_limit_leds[0]=button;
sampler_capture_limit_set=0;
break;
}
case 5:
/* toggle mix in for samples */
if( sampler_inmix_leds[button] )
{
sampler_inmix_leds[button]=0;
set_input_group(button, 0);
}
else
{
sampler_inmix_leds[button]=1;
set_input_group(button, 1);
}
break;
case 6:
/* toggle mix out for samples */
if( sampler_outmix_leds[button] )
{
sampler_outmix_leds[button]=0;
set_output_group(button, 0);
}
else
{
sampler_outmix_leds[button]=1;
set_output_group(button, 1);
}
break;
}
return 0;
} /* sampler_page_chooser */
int
sequencer_page_chooser(const monome_event_t *e, int button)
{
unsigned int c, page=0;
/* store our bank number */
for(c=0; c<7; c++)
if( sequencer_page_pos[c] )
page = c;
if( sequencer_voice_leds[page-1][button] )
sequencer_voice_leds[page-1][button]=0;
else
sequencer_voice_leds[page-1][button]=1;
} /* sequencer_page_chooser */
int
togglevoice_page_chooser(const monome_event_t *e, int button)
{
unsigned int c, page=0;
int x=0;
int tempint=0;
char *tempstring;
/* store our bank number */
for(c=0; c<7; c++)
if( sequencer_bank_pos[c] )
page = c;
if(sequencer_voice_map[page-1][button]==sequencer_bank_select+1)
sequencer_voice_map[page-1][button]=0;
else
{
/*this bit makes sure we only assign once sample per step*/
/* i'm looking at it now and slightly inebriated so i'm short
on patience but this converts a [48][6]-type array to [6][48]
which allows us to toggle-off/forget the previously set
sequencer_bank_select and set the new one. sorry. */
x=button%8;
for(c=0;c<7;c++)
if( sequencer_voice_map[page-1][x+(c*8)]==sequencer_bank_select+1)
sequencer_voice_map[page-1][x+(c*8)]=0;
sequencer_voice_map[page-1][button]=sequencer_bank_select+1;
}
} /* togglevoice_page_chooser */
int
togglebank_page_chooser(const monome_event_t *e, int button)
{
sequencer_bank_select=button;
} /* togglebank_voice_chooser */
void
handle_press(const monome_event_t *e, void *data)
{
unsigned int x, y, x2, y2, button, c;
x = e->grid.x;
y = e->grid.y;
/* store monome state change */
grid[x][y]=1;
/* SEQUENCER, top-left quadrant filtering */
if( (x < 8) && (y < 8) )
{
/* convert matrix indeces (ex. (2, 5), (0, 0)) to linear
sample number (ex. 42, 0) */
button = coordinate_to_led(x, y);
/* SEQUENCER, top 48 pads */
if( button < 48 && sequencer_page_pos[0] == 0)
{
/* only do this if we're NOT on the first sequencer page */
sequencer_page_chooser(e, button);
}
if( grid[0][7] && button==55)
{
if (external_clock_enable == 0)
external_clock_enable = 1;
else
external_clock_enable = 0;
return;
}
if ( (button>47) && (button<56) && (external_clock_enable==0))
{
/* SEQUENCER, bpm row */
seq_bpm_led=button-47;
switch(button-48)
{
case 0:
seq_bpm=15;
break;
case 1:
seq_bpm=30;
break;
case 2:
seq_bpm=60;
break;
case 3:
seq_bpm=120;
break;
case 4:
seq_bpm=240;
break;
case 5:
seq_bpm=480;
break;
case 6:
seq_bpm=600;
break;
case 7:
seq_bpm=700;
break;
}
}
if( (button >= 56) && (button < 63) )
{
/* clear and set new current sequencer function */
if( !sequencer_page_pos[button-56] )
{
for( c = 0; c < 7; c++)
sequencer_page_pos[c] = 0;
sequencer_page_pos[button - 56] = 1;
clear_frame(e, 0, 0);
}
}
/* clear tap recorder and arm for recording */
if( grid[0][7] && button==63 && (external_clock_enable==0))
if( !tap_recorder_leds[1] && !tap_recorder_leds[0] )
tap_recorder_leds[0]=1;
else
if( !tap_recorder_leds[1] && tap_recorder_leds[0] )
{
tap_recorder_leds[1]=1;
tap_recorder_leds[2]=0;
}
else
if( tap_recorder_leds[1] && tap_recorder_leds[0] )
{
tap_recorder_leds[0]=0;
tap_recorder_leds[1]=0;
tap_recorder_leds[2]=0;
}
/* record if we enter 'armed' mode and we start tapping */
if( button==63 && (external_clock_enable==0))
{
if( (!tap_recorder_leds[1] && tap_recorder_leds[0])
&& !tap_recorder_leds[2])
{
tap_recorder_leds[2]=1;
}
else
if( (tap_recorder_leds[0] && !tap_recorder_leds[1])
&& tap_recorder_leds[2] )
{
sequencer_nextstep_pretap=1;
}
}
}
/* SAMPLER, top-right quadrant filtering */
if( (x > 7) && (y < 8) )
{
/* adjust equation inputs for offset of in-use monome quadrant
(read: i'm too lazy to adjust the equation) */
x2 = x - 8;
/* convert matrix indeces (ex. (10, 5), (8, 0)) to linear
sample number (ex. 42, 0) */
button = coordinate_to_led(x2, y);
/* SAMPLER, top 48 pads */
if( button < 48 )
sampler_page_chooser(e, button);
/* SAMPLER, turn jack monitors on or off (8, 6) .. (15, 6) */
if( (button >= 48) && (button < 56) )
{
mixer_row_grid[x][y] = !mixer_row_grid[x][y];
managed_led_set(e->monome, x, y, mixer_row_grid[x][y]);
if(sampler_monitors[button-48])
{
ficus_jackmonitor(button-48, 0, 0);
ficus_jackmonitor(button-48, 1, 0);
sampler_monitors[button-48]=0;
}
else
{
ficus_jackmonitor(button-48, 0, 1);
ficus_jackmonitor(button-48, 1, 1);
sampler_monitors[button-48]=1;
}
return;
}
/* SAMPLER control row (8, 7) .. (15, 7) */
if( (button >= 56) && (button < 63) )
{
/* clear and set new current sampler function */
/* pressing the sampler's capture mode control button
(11, 7) after already entering the capture mode
will set 'armed' samples set for capturing to an
'unarmed' state. */
if( ((button-56)==3) && sampler_page_pos[3])
clear_armed();
if( (button-56) == 4 )
sampler_capture_limit_leds[1]=48;
for( c = 0; c < 8; c++)
sampler_page_pos[c] = 0;
sampler_page_pos[button - 56] = 1;
clear_frame(e, 8, 0);
return;
}
/* SAMPLER global mute button */
if( button == 63 )
{
managed_led_set(e->monome, x, y, 1);
for( c=0; c<48; c++)
ficus_killplayback(c);
return;
}
}
/* SEQUENCER-BANKS, bottom-left quadrant filtering */
if( (x < 8) && (y > 7) )
{
y2=y-8;
button=coordinate_to_led(x,y2);
/* SEQUENCER-BANKS, top 48 pads */
if( button < 48 )
togglevoice_page_chooser(e, button);
/* SAMPLER-SEQUENCER, playback row */
if( (button>47) && (button<56) )
{
playback_speed_led=button-47;
switch(button-48)
{
case 0:;
if((sampler_playback_speed==(float)1)&&!playback_reverse)
playback_reverse=1;
else
if(sampler_playback_speed==(float)1)
playback_reverse=0;
sampler_playback_speed=.25;
break;
case 1:
sampler_playback_speed=.50;
break;
case 2:
sampler_playback_speed=.74;
break;
case 3:
sampler_playback_speed=1;
break;
case 4:
sampler_playback_speed=1.25;
break;
case 5:
sampler_playback_speed=1.50;
break;
case 6:
sampler_playback_speed=1.75;
break;
case 7:
sampler_playback_speed=2.0;
break;
}
}
if(button==56)
{
seq_bpm-=1;
seq_bpm_dec_led=1;
}
if(button==63)
{
seq_bpm+=1;
seq_bpm_inc_led=1;
}
/* SEQUENCER-BANKS, control row (0, 15) .. (7, 15) */
if( (button > 56) && (button < 63) )
{
/* clear and set new current sequencer function */
for( c = 1; c < 7; c++)
sequencer_bank_pos[c] = 0;
sequencer_bank_pos[button - 56] = 1;
clear_frame(e, 0, 8);
}
}
/* SEQUENCER-VOICE-SELECT, bottom-right quadrant filtering */
if( (x>7) && (y>7) )
{
x2=x-8;
y2=y-8;
button=coordinate_to_led(x2,y2);
/* SEQUENCER-VOICE-SELECT, top 48 pads */
if( button < 48 )
{
togglebank_page_chooser(e, button);
clear_frame(e,8,8);
clear_frame(e,0,8);
}
/* SAMPLER-SEQUENCER, playback row */
if( (button>47) && (button<56) )
{
if(!playback_upnoclip)
playback_rampup_led=button-47;
switch(button-48)
{
case 0:
if((playback_upnoclip==0)&&(sampler_playback_rampup==0))
{
sampler_playback_rampup=.001;
playback_upnoclip=1;
}
else
{
playback_upnoclip=0;
sampler_playback_rampup=0;
}
break;
case 1:
if(!playback_upnoclip)
sampler_playback_rampup=.01;
break;
case 2:
if(!playback_upnoclip)
sampler_playback_rampup=.05;
break;
case 3:
if(!playback_upnoclip)
sampler_playback_rampup=.1;
break;
case 4:
if(!playback_upnoclip)
sampler_playback_rampup=.25;
break;
case 5:
if(!playback_upnoclip)
sampler_playback_rampup=.5;
break;
case 6:
if(!playback_upnoclip)
sampler_playback_rampup=.75;
break;
case 7:
if(!playback_upnoclip)
sampler_playback_rampup=.99;
break;
}
}
/* SAMPLER-SEQUENCER, playback row */
if( (button>55) && (button<64) )
{
if(!playback_downnoclip)
playback_rampdown_led=button-55;
switch(button-56)
{
case 0:
if((playback_downnoclip==0)&&(sampler_playback_rampdown==0))
{
sampler_playback_rampdown=.001;
playback_downnoclip=1;
}
else
{
playback_downnoclip=0;
sampler_playback_rampdown=0;
}
break;
case 1:
if(!playback_downnoclip)
sampler_playback_rampdown=.01;
break;
case 2:
if(!playback_downnoclip)
sampler_playback_rampdown=.05;
break;
case 3:
if(!playback_downnoclip)
sampler_playback_rampdown=.1;
break;
case 4:
if(!playback_downnoclip)
sampler_playback_rampdown=.25;
break;
case 5:
if(!playback_downnoclip)
sampler_playback_rampdown=.5;
break;
case 6:
if(!playback_downnoclip)
sampler_playback_rampdown=.75;
break;
case 7:
if(!playback_downnoclip)
sampler_playback_rampdown=.99;
break;
}
}
}
} /* handle_press */
void
handle_lift(const monome_event_t *e, void *data)