-
Notifications
You must be signed in to change notification settings - Fork 0
/
pxk.C
2229 lines (2169 loc) · 52.5 KB
/
pxk.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
/*
This file is part of prodatum.
Copyright 2011-2015 Jan Eidtmann
prodatum 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.
prodatum 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 prodatum. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <fstream>
#include <FL/fl_ask.H>
#include <FL/Fl_Tooltip.H>
#include "pxk.H"
extern const char* VERSION;
extern PD_UI* ui;
extern PXK* pxk;
// buffer spaces
#ifdef SYNCLOG
extern unsigned int write_space;
extern unsigned int read_space;
extern unsigned int max_write;
extern unsigned int max_read;
#endif
extern bool got_answer;
extern FilterMap FM[51];
extern MIDI* midi;
Cfg* cfg = 0;
volatile bool join_bro = false;
volatile static bool name_set_incomplete;
volatile static int init_progress;
void PXK::widget_callback(int id, int value, int layer)
{
//pmesg("PXK::widget_callback(%d, %d, %d) \n", id, value, layer);
if (!synchronized)
return;
// browser returns -1 when user clicked on empty space
if (value == -1 && (id == 278 || id == 643 || id == 897 || id == 928 || id == 1027 || id == 1409))
{
int current = 0;
// reselect the previous selection for them
switch (id)
{
case (278): // master riff
case (643): // master arp
current = setup->get_value(id);
break;
case 897: // preset
current = setup->get_value(130, selected_channel);
break;
case 1409: // intrument
current = preset->get_value(id, layer);
break;
default: // arp/riff
current = preset->get_value(id);
}
if (layer == -2)
pwid[id][0]->set_value(current);
else
pwid[id][layer]->set_value(current);
return;
}
// channel changed
if (id == 129)
{
if (ui->b_copy_p->value())
{
ui->b_copy_p->value(0);
ui->b_copy_p->do_callback();
}
else if (ui->b_save_p->value())
{
ui->b_save_p->value(0);
ui->b_save_p->do_callback();
}
selected_channel = value;
// select multimode channel (to make pan and channel related controls work)
midi->edit_parameter_value(id, selected_channel);
// select basic channel (to get the edit buffer of the channels preset below)
midi->edit_parameter_value(139, selected_channel);
// update midi input filter
midi->set_channel_filter(selected_channel);
// request preset data
selected_preset_rom = setup->get_value(138, selected_channel);
selected_preset = setup->get_value(130, selected_channel);
ui->preset_rom->set_value(selected_preset_rom);
ui->preset->set_value(selected_preset);
if (cfg->get_cfg_option(CFG_CLOSED_LOOP_DOWNLOAD))
midi->request_preset_dump();
else
midi->request_preset_dump(50 + cfg->get_cfg_option(CFG_SPEED));
// update channel controls (pan etc)
if (midi_mode == MULTI)
pwid[135][0]->set_value(setup->get_value(135, selected_channel)); // MIDI enable
else
pwid[140][0]->set_value(selected_channel); // FX channel
pwid[131][0]->set_value(setup->get_value(131, selected_channel));
pwid[132][0]->set_value(setup->get_value(132, selected_channel));
pwid[133][0]->set_value(setup->get_value(133, selected_channel));
pwid[134][0]->set_value(setup->get_value(134, selected_channel));
pwid[137][0]->set_value(setup->get_value(137, selected_channel));
ui->global_minipiano->reset_active_keys();
ui->main->minipiano->reset_active_keys();
ui->piano->reset_active_keys();
ui->arp_mp->reset_active_keys();
return;
}
if (id == 897) // preset_select (this is effectively id 130 (MULTIMODE_PRESET))
{
// do nothing if the preset didn't change
if (setup->set_value(130, value, selected_channel))
{
selected_preset = value;
pmesg("callback value: %d\n", value);
midi->write_event(0xb0, 0, selected_preset_rom, selected_channel);
midi->write_event(0xb0, 32, selected_preset / 128, selected_channel);
midi->write_event(0xc0, selected_preset % 128, 0, selected_channel);
if (cfg->get_cfg_option(CFG_CLOSED_LOOP_DOWNLOAD))
midi->request_preset_dump();
else
midi->request_preset_dump(50 + cfg->get_cfg_option(CFG_SPEED));
}
return;
}
// select editing layer
if (layer != selected_layer && layer != -2 && !ui->eall)
{
selected_layer = layer;
midi->edit_parameter_value(898, selected_layer);
}
// volume, honor mute state ")
if (id == 1410 && mute_volume[selected_layer] != -100)
{
mute_volume[selected_layer] = value;
return;
}
// update changes locally
int ret = 0;
if (id > 898)
{
if (ui->eall)
{
ret |= preset->set_value(id, value, 0);
ret |= preset->set_value(id, value, 1);
ret |= preset->set_value(id, value, 2);
ret |= preset->set_value(id, value, 3);
}
else
ret = preset->set_value(id, value, selected_layer);
}
else
ret = setup->set_value(id, value, selected_channel);
// update changes remotely but only if we really changed something
if (ret == 1)
midi->edit_parameter_value(id, value);
else
return;
// id's which have deps and need further updates below
switch (id)
{
case 135: // channel enable
if (value == 0)
{
ui->main->minipiano->reset_active_keys();
ui->global_minipiano->reset_active_keys();
ui->piano->reset_active_keys();
}
return;
case 138: // preset rom select
selected_preset_rom = value;
midi->write_event(0xb0, 0, selected_preset_rom, selected_channel);
midi->write_event(0xb0, 32, selected_preset / 128, selected_channel);
midi->write_event(0xc0, selected_preset % 128, 0, selected_channel);
// wait a bit to let it sink...
midi->request_preset_dump(50 + cfg->get_cfg_option(CFG_SPEED));
return;
case 140: // FX channel
selected_fx_channel = value;
if (midi_mode != MULTI || selected_fx_channel != -1)
preset->show_fx();
else
setup->show_fx();
return;
case 385: // MIDI Mode
{
ui->piano->reset_active_keys();
ui->global_minipiano->reset_active_keys();
ui->main->minipiano->reset_active_keys();
int prev_mode = midi_mode;
midi_mode = value;
if (midi_mode != MULTI)
{
if (prev_mode == MULTI)
{
pwid[140][0]->set_value(selected_channel);
preset->show_fx();
}
}
else // multimode
{
pwid[140][0]->set_value(selected_fx_channel);
if (selected_fx_channel != -1)
preset->show_fx();
else
setup->show_fx();
}
ui->main->mix_out->get_value();
return;
}
case 1537: // Filter type
for (char i = 0; i <= 50; i++)
if (FM[i].id == value)
{
Fl_Tooltip::exit((Fl_Widget*) pwid[id][layer]);
ui->main->layer_strip[layer]->filter->tooltip(FM[i].info);
break;
}
return;
case 513: // fx types
case 520:
case 1153:
case 1160:
update_fx_values(id, value);
return;
}
// controller mapping changed
if ((id > 390 && id < 402) || (id > 405 && id < 410))
update_control_map();
// update cc controler values when we change initial amounts
else if ((id > 914 && id < 928) && id != 923)
((Fl_Slider*) ui->main->ctrl_x[(id > 922) ? id - 915 : id - 914])->value((double) value);
}
void PXK::cc_callback(int controller, int value)
{
//pmesg("PXK::cc_callback(%d, %d) \n", controller, value);
midi->write_event(0xb0, ctrl_to_cc[controller], value, selected_channel);
if (!cc_changed && controller < 13)
{
ui->main->b_store->activate();
cc_changed = true;
}
}
// to open another device:
// delete PXK, new PXK :)
PXK::PXK()
{
pmesg("PXK::PXK()\n");
// initialize
device_id = -1;
inquired = false;
device_code = -1;
synchronized = false;
roms = 0;
preset = 0;
preset_copy = 0;
setup = 0;
setup_copy = 0;
setup_init = 0;
selected_multisetup = -1;
selected_fx_channel = -1;
midi_mode = -1;
setup_names = 0;
setup_names_changed = false;
arp = 0;
nak_count = 0;
cc_changed = false;
randomizing = false;
for (unsigned char i = 0; i < 4; i++)
{
mute_volume[i] = -100;
is_solo[i] = 0;
}
for (unsigned char i = 0; i < 5; i++)
{
rom[i] = 0;
rom_index[i] = -1;
}
}
void PXK::Boot(bool autoconnect, int __id)
{
if (!cfg)
{
cfg = new Cfg(__id);
cfg->apply();
}
else if (__id != cfg->get_cfg_option(CFG_DEVICE_ID))
{
delete cfg;
cfg = new Cfg(__id);
cfg->apply();
}
if (cfg->get_cfg_option(CFG_MIDI_IN) != -1 && cfg->get_cfg_option(CFG_MIDI_OUT) != -1)
{
if (autoconnect)
{
ConnectPorts();
Inquire(cfg->get_cfg_option(CFG_DEVICE_ID));
}
else
ui->open_device->showup();
}
else if (midi->in() && midi->out())
Inquire(cfg->get_cfg_option(CFG_DEVICE_ID));
else
ui->open_device->showup();
}
PXK::~PXK()
{
pmesg("PXK::~PXK()\n");
save_setup_names();
// unmute eventually muted voices
mute(0, 0);
mute(0, 1);
mute(0, 2);
mute(0, 3);
ui->device_info->label(0);
// clear browsers and rom choices
for (unsigned char i = 0; i < 4; i++)
{
ui->layer_editor[i]->instrument->reset();
ui->layer_editor[i]->instrument_rom->menu(0);
ui->layer_editor[i]->patchcords->reset_sources();
ui->main->layer_strip[i]->instrument->label(0);
}
ui->preset_editor->patchcords->reset_sources();
ui->preset_editor->patchcords->reset_destinations();
ui->preset->reset();
ui->preset_rom->menu(0);
ui->preset_editor->riff->reset();
ui->preset_editor->riff_rom->menu(0);
ui->preset_editor->arp->reset();
ui->preset_editor->arp_rom->menu(0);
ui->preset_editor->l1->reset();
ui->preset_editor->l1_rom->menu(0);
ui->preset_editor->l2->reset();
ui->preset_editor->l2_rom->menu(0);
ui->main->riff->reset();
ui->main->riff_rom->menu(0);
ui->main->arp->reset();
ui->main->arp_rom->menu(0);
ui->multisetups->clear();
ui->copy_browser->reset();
ui->copy_arp_rom->menu(0);
ui->copy_arp_pattern_browser->reset();
for (unsigned char i = 0; i <= roms; i++)
if (rom[i])
{
delete rom[i];
rom[i] = 0;
}
if (preset)
delete preset;
if (preset_copy)
delete preset_copy;
if (setup)
delete setup;
if (setup_copy)
delete setup_copy;
if (setup_init)
{
setup_init->upload();
delete setup_init;
}
if (setup_names)
delete[] setup_names;
if (cfg)
delete cfg;
preset = 0;
preset_copy = 0;
setup = 0;
setup_copy = 0;
setup_init = 0;
setup_names = 0;
cfg = 0;
}
void PXK::ConnectPorts()
{
pmesg("PXK::ConnectPorts()\n");
if (midi->connect_out(cfg->get_cfg_option(CFG_MIDI_OUT)) && midi->connect_in(cfg->get_cfg_option(CFG_MIDI_IN)))
{
ui->midi_outs->label(ui->midi_outs->text(cfg->get_cfg_option(CFG_MIDI_OUT)));
ui->midi_outs->value(cfg->get_cfg_option(CFG_MIDI_OUT));
ui->midi_ins->label(ui->midi_ins->text(cfg->get_cfg_option(CFG_MIDI_IN)));
ui->midi_ins->value(cfg->get_cfg_option(CFG_MIDI_IN));
if (midi->connect_thru(cfg->get_cfg_option(CFG_MIDI_THRU)))
{
ui->midi_ctrl->label(ui->midi_ctrl->text(cfg->get_cfg_option(CFG_MIDI_THRU)));
ui->midi_ctrl->value(cfg->get_cfg_option(CFG_MIDI_THRU));
}
}
else
ui->open_device->showup();
}
static void sync_bro(void* p)
{
if (join_bro)
goto Club;
// general variables
static bool timed_out = false;
static int name = 0;
static char _label[64];
static unsigned char countdown;
#ifdef SYNCLOG
char logbuffer[128];
#endif
// preset name variables
static unsigned char rom_nr = 0;
static unsigned char type = PRESET;
static int names = 0;
// setup name variables
static char setups_to_load = -1;
static bool requested = false;
if (setups_to_load == -1)
setups_to_load = pxk->load_setup_names(99);
if (setups_to_load)
{
if (pxk->setup_init == 0)
{
if (!requested)
{
ui->init_progress->label("Syncing multisetup names...");
ui->init_progress->maximum((float) setups_to_load);
ui->init_progress->value(.0);
init_progress = 0;
ui->init->position(ui->main_window->x() + (ui->main_window->w() / 2) - (ui->init->w() / 2),
ui->main_window->y() + 80);
ui->init->show();
#ifdef SYNCLOG
ui->init_log->append("sync_bro: Requesting initial setup dump\n");
#endif
midi->request_setup_dump();
requested = true;
countdown = 50; // ~ 1/2 s.
goto Exit;
}
#ifdef SYNCLOG
ui->init_log->append("*");
#endif
if (--countdown == 0) // timeout
{
#ifdef SYNCLOG
ui->init_log->append("\nsync_bro: request for initial setup timed out. Giving up.\n");
#endif
timed_out = true;
goto Club;
}
goto Exit;
} // got init setup
if (name == 0)
{
#ifdef SYNCLOG
ui->init_log->append("# OK\n\nsync_bro: Loading setup names\n");
#endif
requested = false;
}
if (name <= setups_to_load)
{
if (!requested && name < setups_to_load)
{
pxk->load_setup_names(name++);
requested = true;
got_answer = false;
countdown = 50;
goto Exit;
}
if (!got_answer)
{
#ifdef SYNCLOG
ui->init_log->append("*");
#endif
if (--countdown == 0) // timeout
{
#ifdef SYNCLOG
ui->init_log->append("\nsync_bro: timeout syncing setup name. Giving up.\n");
#endif
timed_out = true;
goto Club;
}
goto Exit;
}
else
{
#ifdef SYNCLOG
ui->init_log->append("#");
#endif
if (name == setups_to_load)
{
#ifdef SYNCLOG
ui->init_log->append(" OK\n");
#endif
pxk->load_setup_names(setups_to_load);
setups_to_load = 0;
}
ui->init_progress->value((float) init_progress);
requested = false;
goto Exit;
}
}
}
// setup initialization complete
if (rom_nr <= pxk->roms)
{
if (type <= RIFF) // for every type
{
if (type == SETUP || type == DEMO || (rom_nr == 0 && (type == INSTRUMENT || type == RIFF)))
{
names = 0;
type++;
goto Exit;
}
if (type == RIFF && pxk->member_code == 2) // audity has no riffs
{
names = 0;
type = PRESET; // next rom
rom_nr++;
goto Exit;
}
if (names == 0)
{
name = 0;
names = pxk->rom[rom_nr]->disk_load_names(type);
if (names != -1) // not available on disk
{
name_set_incomplete = true;
if (names == 0) // unknown number of names available
{
if (type == ARP)
names = MAX_ARPS; // max requests
else if (type == RIFF)
names = MAX_RIFFS;
}
const char* _type = 0;
switch (type)
{
case PRESET:
_type = "preset";
break;
case INSTRUMENT:
_type = "instrument";
break;
case ARP:
_type = "arp (estimated progress)";
break;
case RIFF:
_type = "riff (estimated progress)";
break;
}
if (rom_nr == 0)
snprintf(_label, 64, "Syncing flash %s names...", _type);
else
snprintf(_label, 64, "Syncing %s %s names...", pxk->rom[rom_nr]->name(), _type);
ui->init_progress->label(_label);
ui->init_progress->maximum((float) names);
ui->init_progress->value(.0);
init_progress = 0;
if (!ui->init->shown())
{
ui->init->position(ui->main_window->x() + (ui->main_window->w() / 2) - (ui->init->w() / 2),
ui->main_window->y() + 80);
ui->init->show();
}
#ifdef SYNCLOG
// init log
snprintf(logbuffer, 128, "\nsync_bro: Loading %s\n", _label);
ui->init_log->append(logbuffer);
#endif
}
} // if (names == 0)
if (name_set_incomplete && name <= names)
{
if (!requested && name < names)
{
if (type == ARP && rom_nr != 0)
pxk->rom[rom_nr]->load_name(type, name++);
else // turbo
{
if (name == 0)
got_answer = true;
if (!got_answer)
{
name_set_incomplete = false;
goto Exit;
}
ui->init_progress->value((float) init_progress);
while (name < names)
{
pxk->rom[rom_nr]->load_name(type, name++);
if (name % 12 == 0)
{
#ifdef SYNCLOG
ui->init_log->append("R12");
#endif
Fl::repeat_timeout(.12 + (double) (cfg->get_cfg_option(CFG_SPEED) / 1000.), sync_bro, p);
got_answer = false;
return;
}
}
}
requested = true;
got_answer = false;
countdown = 50;
goto Exit;
}
if (!got_answer)
{
#ifdef SYNCLOG
ui->init_log->append("*");
#endif
if (--countdown == 0) // timeout
{
if (type != ARP && type != RIFF) // ok for ARPs and RIFFs
{
#ifdef SYNCLOG
ui->init_log->append("\nsync_bro: timed out syncing ROM name. Giving up.\n");
#endif
timed_out = true;
goto Club;
}
#ifdef SYNCLOG
ui->init_log->append("\nsync_bro: timed out syncing RIFF/ARP name. Skipping.\n");
#endif
name_set_incomplete = false; // stop requesting arp/riff names
}
goto Exit;
}
else
{
#ifdef SYNCLOG
ui->init_log->append("#");
#endif
if (name == names)
{
#ifdef SYNCLOG
ui->init_log->append(" OK\n");
#endif
name_set_incomplete = false;
}
ui->init_progress->value((float) init_progress);
requested = false;
goto Exit;
}
} // if (name_set_incomplete)
else
{
if (name != 0)
pxk->rom[rom_nr]->save(type);
type++;
names = 0; // next type
if (name != 0)
goto Wait;
goto Exit;
}
} // if (type <= RIFF) // for every type
else
{
names = 0;
type = PRESET; // next rom
rom_nr++;
goto Exit;
}
} // if (rom_nr < pxk->roms)
else
*(bool*) p = true;
Exit: if (!*(bool*) p)
Fl::repeat_timeout(.01, sync_bro, p);
else
{
Club: if (pxk->setup_init)
{
pxk->setup_init->upload();
if (join_bro)
{
delete pxk->setup_init;
pxk->setup_init = 0;
goto Wait;
// wait for upload
}
else
mysleep(300); // let it crunch
}
#ifdef SYNCLOG
snprintf(logbuffer, 128,
"\nmin. read buffer space: %u (max. pkt len %u)\nmin. write buffer space: %u (max. pkt len %u)\n", read_space,
max_read, write_space, max_write);
ui->init_log->append(logbuffer);
read_space = RINGBUFFER_READ;
write_space = RINGBUFFER_WRITE;
max_read = 0;
max_write = 0;
#endif
// reset static variables
name = 0;
countdown = 33;
rom_nr = 0;
type = PRESET;
names = 0;
setups_to_load = -1;
requested = false;
ui->init->hide();
ui->main_window->showup(); // make main active (important!)
if (timed_out)
{
timed_out = false;
fl_alert("Sync failed. Please send the init log to rdxesy@@yahoo.de and check your cables & MIDI drivers etc.");
#ifdef SYNCLOG
ui->init_log_w->showup();
#endif
}
else if (join_bro)
{
int id = cfg->get_cfg_option(CFG_DEVICE_ID);
delete pxk;
pxk = new PXK();
pxk->Boot(false, id);
ui->open_device->showup();
pxk->Inquire(id);
}
else
{
midi->filter_loose();
if (pxk->setup_init)
pxk->load_setup();
else
midi->request_setup_dump();
midi->master_volume(cfg->get_cfg_option(CFG_MASTER_VOLUME));
}
}
return;
Wait: Fl::repeat_timeout(.5 + (double) (cfg->get_cfg_option(CFG_SPEED) / 1000.), sync_bro, p);
}
void PXK::Join()
{
if (!join_bro)
{
ui->device_info->label(0);
join_bro = true;
}
}
bool PXK::Synchronize()
{
if (synchronized)
return false;
pmesg("PXK::Synchronize()\n");
display_status("Synchronizing...");
#ifdef SYNCLOG
char buf[64];
snprintf(buf, 64, "PXK::Synchronize() %d[ms]\n\n", cfg->get_cfg_option(CFG_SPEED));
ui->init_log->append(buf);
#endif
midi->filter_strict(); // filter everything but sysex for sync
init_progress = 0;
name_set_incomplete = false;
Fl::add_timeout(0, sync_bro, (void*) &synchronized);
return true;
}
bool PXK::Synchronized() const
{
return synchronized;
}
void PXK::log_add(const unsigned char* sysex, const unsigned int len, unsigned char io) const
{
//pmesg("PXK::log_add(sysex, %d, %d)\n", len, io);
bool log = false;
char* buf = 0;
if ((io == 1 && cfg->get_cfg_option(CFG_LOG_SYSEX_IN)) || (io == 0 && cfg->get_cfg_option(CFG_LOG_SYSEX_OUT)))
{
log = true;
buf = new char[2 * len + 18];
}
unsigned char n = 0;
if (log)
{
if (io == 1)
{
static unsigned int count_i = 0;
n = snprintf(buf, 16, "\nI.%u::", ++count_i);
}
else
{
static unsigned int count_o = 0;
n = snprintf(buf, 16, "\nO.%u::", ++count_o);
}
}
for (unsigned int i = 0; i < len; i++)
{
if (log)
sprintf(n + buf + 2 * i, "%02hhX", sysex[i]);
if (io == 1)
ui->scope_i->Add(sysex[i]);
else
ui->scope_o->Add(sysex[i]);
}
if (buf)
{
ui->logbuf->append(buf);
delete[] buf;
}
}
/* if autoconnection is enabled but the device is not powered
we end up with an unconnected main window. this shows
the open dialog if there is no answer*/
static void check_connection(void* p)
{
if (*(char*) p == -1)
{
ui->open_device->showup();
pxk->inquired = false;
}
}
void PXK::Inquire(int id)
{
pmesg("PXK::Inquire(%d)\n", id);
if (!synchronized)
{
join_bro = false;
if (id == -1)
device_id = 0x7f;
else
device_id = id;
unsigned char sid = id & 0xff;
unsigned char s[] =
{ 0xf0, 0x7e, sid, 0x06, 0x01, 0xf7 };
midi->write_sysex(s, 6);
midi->write_sysex(s, 6);
inquired = true;
device_code = -1;
Fl::add_timeout(.6, check_connection, (void*) &device_code);
}
}
void request_hardware_config_timeout(void*)
{
midi->request_hardware_config();
}
void PXK::incoming_inquiry_data(const unsigned char* data)
{
pmesg("PXK::incoming_inquiry_data(data)\n");
if (!inquired || synchronized)
return;
device_code = data[7] * 128 + data[6];
if (device_code == 516 && (data[2] == device_id || device_id == 127)) // talking to our PXK!
{
inquired = false;
if (device_id == 127)
{
device_id = data[2];
ui->device_id->value((double) data[2]);
// load user config if we scanned using ID 127
delete cfg;
cfg = new Cfg(device_id);
cfg->apply();
}
midi->set_device_id((unsigned char) device_id); // so further sysex comes through
Fl::add_timeout(.1, request_hardware_config_timeout);
snprintf(os_rev, 5, "%c%c%c%c", data[10], data[11], data[12], data[13]);
member_code = data[9] * 128 + data[8];
switch (member_code)
{
case 2: // AUDITY
ui->main->b_audit->deactivate();
ui->m_audit->hide();
ui->main->g_riff->deactivate();
ui->main->g_superbeats->deactivate();
ui->preset_editor->g_riff->deactivate();
ui->main->post_d->hide();
ui->main->pre_d->label("Delay");
ui->preset_editor->post_d->hide();
ui->preset_editor->pre_d->label("Delay");
break;
default:
ui->main->b_audit->activate();
ui->m_audit->show();
ui->main->g_riff->activate();
ui->main->g_superbeats->activate();
ui->preset_editor->g_riff->activate();
ui->main->post_d->show();
ui->main->pre_d->label("Pre D");
ui->preset_editor->post_d->show();
ui->preset_editor->pre_d->label("Pre D");
}
}
else
device_code = -1;
}
unsigned char PXK::get_rom_index(char id) const
{
if (id == 0)
return 0;
if (rom_index[1] == id)
return 1;
if (rom_index[2] == id)
return 2;
if (rom_index[3] == id)
return 3;
if (rom_index[4] == id)
return 4;
return 5;
}
void PXK::incoming_hardware_config(const unsigned char* data)
{
pmesg("PXK::incoming_hardware_config(data)\n");
user_presets = data[8] * 128 + data[7];
roms = data[9];
rom_index[0] = 0;
rom[0] = new ROM(0, user_presets);
for (unsigned char j = 1; j <= roms; j++)
{
int idx = 11 + (j - 1) * 6;
rom[j] = new ROM(data[idx + 1] * 128 + data[idx], data[idx + 3] * 128 + data[idx + 2],
data[idx + 5] * 128 + data[idx + 4]);
rom_index[j] = data[idx + 1] * 128 + data[idx];
}
create_device_info();
if (roms != 0)
{
if (!ui->open_device->shown_called())
Synchronize();
else
ui->connect->activate();
}
}
unsigned char PXK::load_setup_names(unsigned char start)
{
//pmesg("PXK::load_setup_names(%d)\n", start);
char available_setups = 64;
if (member_code == 2)
available_setups = 16;
// try to load from disk
if (start == 99)
{
if (setup_names)
{
delete[] setup_names;
setup_names = 0;
}
char filename[PATH_MAX];
snprintf(filename, PATH_MAX, "%s/n_set_0_%d", cfg->get_config_dir(), cfg->get_cfg_option(CFG_DEVICE_ID));
std::fstream file(filename, std::ios::in | std::ios::binary | std::ios::ate);
if (file.is_open())
{
int size = file.tellg();
if (size != available_setups * 16)
{
file.close();
return available_setups - 1;
}
setup_names = new unsigned char[available_setups * 16];
file.seekg(0, std::ios::beg);
file.read((char*) setup_names, available_setups * 16);
file.close();
ui->multisetups->clear();
char buf[21];
for (char i = 0; i < available_setups; i++)
{
snprintf(buf, 21, "%02d: %s", i, setup_names + i * 16);
ui->multisetups->add(buf);
}
return 0;
}
return available_setups - 1;
}
// midi load setup names
if (start < available_setups - 1)
{
midi->copy(C_SETUP, start, -1);
midi->request_name(SETUP, start, 0);
}