@@ -73,6 +73,151 @@ void midi_stop() {
7373 do_stop_playback = true;
7474}
7575
76+ void midi_control_change (uint8_t channel , uint8_t control , uint8_t value ) {
77+ // printf("chan/cc/value: %d/%d/%d\n", channel, control, value);
78+ uint8_t new_adcvalue = (value * 2 ) ;
79+ switch (control ) {
80+ case cc_volume : // volume
81+ uint8_t new_vol = new_adcvalue ; // is it 256 total?
82+ if (new_vol != sf -> vol ) {
83+ sf -> vol = new_vol ;
84+ // printf("sf-vol: %d\n", sf->vol);
85+ }
86+ break ;
87+ case cc_bassvolume : // volume
88+ #ifdef INCLUDE_SINEBASS
89+ WaveBass_set_volume (wavebass , new_adcvalue );
90+ #endif
91+ break ;
92+ case cc_tempo : // tempo
93+ uint8_t new_bpm = new_adcvalue ; // what is range?
94+ if (new_bpm != sf -> bpm_tempo ) {
95+ sf -> bpm_tempo = new_bpm ;
96+ // printf("sf-vol: %d\n", sf->vol);
97+ }
98+ break ;
99+ case cc_pitch : // pitch
100+ // if (adc < 2048 - 200) {
101+ // sf->pitch_val_index = adc * PITCH_VAL_MID / (2048 - 200);
102+ // } else if (adc > 2048 + 200) {
103+ // adc -= 2048 + 200;
104+ // sf->pitch_val_index =
105+ // adc * (PITCH_VAL_MAX - PITCH_VAL_MID) / (2048 - 200) +
106+ // PITCH_VAL_MID;
107+ // } else {
108+ // sf->pitch_val_index = PITCH_VAL_MID;
109+ // }
110+
111+ if (new_adcvalue < 127 - 10 ) {
112+ sf -> pitch_val_index = new_adcvalue * PITCH_VAL_MID / (127 - 10 );
113+ } else if (new_adcvalue > 127 + 10 ) {
114+ new_adcvalue -= 127 + 10 ;
115+ sf -> pitch_val_index =
116+ new_adcvalue * (PITCH_VAL_MAX - PITCH_VAL_MID ) / (127 - 10 ) + PITCH_VAL_MID ;
117+ } else {
118+ sf -> pitch_val_index = PITCH_VAL_MID ;
119+ }
120+ break ;
121+ case cc_sampleselect : // sample
122+ uint8_t new_sample = new_adcvalue ; // what is range?
123+ uint8_t sample_selection_index = 0 ;
124+ sample_selection_index = new_sample * (sample_selection_num - 1 ) / 255 ;
125+ uint8_t f_sel_bank_next = sample_selection [sample_selection_index ].bank ;
126+ uint8_t f_sel_sample_next = sample_selection [sample_selection_index ].sample ;
127+ if (f_sel_bank_next != sel_bank_cur ||
128+ f_sel_sample_next != sel_sample_cur ) {
129+ sel_bank_next = f_sel_bank_next ;
130+ sel_sample_next = f_sel_sample_next ;
131+ printf ("[zeptocore] %d bank %d, sample %d\n" ,
132+ sample_selection_index , sel_bank_next , sel_sample_next );
133+ fil_current_change = true;
134+ }
135+ break ;
136+ case cc_quantize : // Qunatize
137+ const uint8_t quantizations [10 ] = {1 , 6 , 12 , 24 , 48 ,
138+ 64 , 96 , 144 , 192 , 192 };
139+ printf ("quantization: %d\n" , quantizations [new_adcvalue * 9 / 255 ]);
140+ Sequencer_quantize (
141+ sf -> sequencers [mode_buttons16 ][sf -> sequence_sel [mode_buttons16 ]],
142+ quantizations [new_adcvalue * 9 / 255 ]);
143+ break ;
144+ case cc_randtunnel : // Random Tunnel
145+ probability_of_random_tunnel = new_adcvalue * 1000 / 256 ;
146+ // if (probability_of_random_tunnel < 100) {
147+ if ((new_adcvalue ) < 20 ) {
148+ probability_of_random_tunnel = 0 ;
149+ }
150+ break ;
151+ case cc_djfilter : // DJ Filter
152+ for (uint8_t channel = 0 ; channel < 2 ; channel ++ ) {
153+ int filter_spacing = 16 ;
154+ for (uint8_t channel = 0 ; channel < 2 ; channel ++ ) {
155+ if (new_adcvalue < 128 - filter_spacing ) {
156+ global_filter_index =
157+ new_adcvalue * (resonantfilter_fc_max ) / (128 - filter_spacing );
158+ global_filter_lphp = 0 ;
159+ ResonantFilter_setFilterType (resFilter [channel ],
160+ global_filter_lphp );
161+ ResonantFilter_setFc (resFilter [channel ], global_filter_index );
162+ } else if (value >= 64 + filter_spacing ) {
163+ global_filter_index = (new_adcvalue - (128 + filter_spacing )) *
164+ (resonantfilter_fc_max ) /
165+ (128 - filter_spacing );
166+ global_filter_lphp = 1 ;
167+ ResonantFilter_setFilterType (resFilter [channel ],
168+ global_filter_lphp );
169+ ResonantFilter_setFc (resFilter [channel ], global_filter_index );
170+ } else {
171+ global_filter_index = resonantfilter_fc_max ;
172+ global_filter_lphp = 0 ;
173+ ResonantFilter_setFilterType (resFilter [channel ],
174+ global_filter_lphp );
175+ ResonantFilter_setFc (resFilter [channel ], resonantfilter_fc_max );
176+ }
177+ }
178+ }
179+ break ;
180+ case cc_randfxbank : // Grimoire
181+ // change the grimoire rune
182+ grimoire_rune = new_adcvalue * 7 / 255 ;
183+ break ;
184+ case cc_randfx : // Grimoire Probability = "Break"
185+ break_knob_set_point = new_adcvalue * 1024 / 255 ;
186+ break ;
187+ case cc_randsequence : // Random sequencer
188+ if (new_adcvalue > 255 ) new_adcvalue = 255 ;
189+ if (new_adcvalue < 32 ) {
190+ // normal
191+ do_retrig_at_end_of_phrase = false;
192+ random_sequence_length = 0 ;
193+ } else if (new_adcvalue < 255 - 32 ) {
194+ do_retrig_at_end_of_phrase = false;
195+ uint8_t sequence_lengths [11 ] = {
196+ 1 , 2 , 4 , 6 , 8 , 12 , 16 , 24 , 32 , 48 , 64 ,
197+ };
198+ random_sequence_length =
199+ sequence_lengths [((int16_t )(new_adcvalue - 32 ) * 11 / (255 - 32 )) % 11 ];
200+ } else {
201+ // new random sequence
202+ regenerate_random_sequence_arr ();
203+ random_sequence_length = 8 ;
204+ do_retrig_at_end_of_phrase = true;
205+ }
206+ break ;
207+ case cc_randjump : // Random Jump - "Amen"
208+ if (new_adcvalue < 128 ) {
209+ sf -> stay_in_sync = true;
210+ probability_of_random_jump = new_adcvalue * 100 / 128 ;
211+ } else if (new_adcvalue >= 128 ) {
212+ sf -> stay_in_sync = false;
213+ probability_of_random_jump = (255 - new_adcvalue ) * 100 / 128 ;
214+ }
215+ break ;
216+ default :
217+ return ;
218+ }
219+
220+ }
76221// Comparator function for qsort
77222int compare_ints (const void * a , const void * b ) {
78223 return (* (int * )a - * (int * )b );
0 commit comments