-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathosc.cpp
3593 lines (2530 loc) · 143 KB
/
osc.cpp
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
#include "config_TPM.h" // include the main Defines
#include "osc.h"
#include <WiFiUdp.h>
#ifdef ESP32
#include <WiFi.h>
#endif
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>
#include <QueueArray.h>
#include "tools.h" // include the Tools enums for reading and writing bools
#include "config_fs.h"
#include "httpd.h"
#include "tpm_artnet.h"
// External Variables/ Structures
#include "wifi-ota.h"
extern wifi_Struct wifi_cfg;
extern artnet_struct artnet_cfg;
#include "leds.h"
extern deck_struct deck[2] ;
extern led_cfg_struct led_cfg;
extern uint8_t fft_bin_results[7];
extern void LEDS_load_default_play_conf();
extern uint8_t LEDS_fft_get_fxbin_result(uint8_t fxbin, uint8_t deckNo);
extern uint16_t play_conf_time_min[MAX_NR_SAVES];
extern artnet_node_struct artnetNode[ARTNET_NR_NODES_TPM] ;
#include "mmqt.h"
extern mqtt_Struct mqtt_cfg;
extern SaveStruct SaveConf;
// ************* Local Variables
// Queues for outgoing OSC messages
QueueArray <char> osc_out_float_addr;
QueueArray <float> osc_out_float_value;
QueueArray <char> osc_out_rgb_addr;
QueueArray <uint8_t> osc_out_rgb_value;
QueueArray <char> osc_out_SelVal_addr;
QueueArray <int> osc_out_SelVal_value;
QueueArray <char> osc_out_int_addr;
QueueArray <int> osc_out_int_value;
QueueArray <char> osc_out_fx_addr;
QueueArray <int> osc_out_fx_intvalue;
QueueArray <char> osc_out_StringAddress;
QueueArray <char> osc_out_Stringvalue;
//QueueArray <uint8_t> osc_out_StringIntvalue;
// OSC configuration
osc_cfg_struct osc_cfg = { OSC_IPMULTI_ ,OSC_PORT_MULTI_,OSC_OUTPORT, OSC_INPORT,1 }; //
// The OSC Server
WiFiUDP osc_server; // the normal osc server
uint8_t Refreshloop = 255;
uint8_t MobRefreshloop = 255;
void OSC_setup()
{ // OSC Setup function
osc_server.begin(osc_cfg.inPort);
debugMe("OSC Setup Done In Port: ", false ); debugMe(String(osc_cfg.inPort), true );
debugMe(" - Out Port: ", false );debugMe(String(osc_cfg.outPort), true ); // osc_server.remotePort() // OSC_OUTPORT
}
void OSC_debug_call()
{
//int64_t time = esp_timer_get_time() ;
debugMe( String( micros()) , false); debugMe( " : NOW" , true);
debugMe( String( led_cfg.update_time) , false); debugMe( " : next frame" , true);
}
bool osc_Isconnected()
{
IPAddress testIP = osc_server.remoteIP();
if (testIP != IPAddress(0,0,0,0))
return true;
else return false;
}
/////////////////////////////////////////// OSC SEND / gerneral functions
//
//
float osc_byte_tofloat(byte value, uint8_t max_value = 255)
{ // convert int 0-255 to float 0-1 value
float float_out = float(value) / max_value;
return float_out;
}
void osc_send_MSG_rgb(String addr_string , uint8_t red = 128, uint8_t green = 128, uint8_t blue = 128 )
{ // Send out a color Directly to the OCS target not bufferd for bundle
if (osc_Isconnected())
{
debugMe("sending RGB");
char address_out[30];
addr_string.toCharArray(address_out, addr_string.length() + 1); //address_out
IPAddress ip_out(osc_server.remoteIP());
//OSCMessage msg_out(address_out);
OSCBundle bundle_out;
bundle_out.add(address_out).add(red).add(green).add(blue).add(255);
osc_server.beginPacket(ip_out,OSC_OUTPORT);// OSC_OUTPORT); //{172,16,222,104}, 8001) ; // osc_server.remotePort()
bundle_out.send(osc_server);
osc_server.endPacket();
bundle_out.empty();
/*
msg_out.add(red);
msg_out.add(green);
msg_out.add(blue);
msg_out.add(255);
msg_out.send(osc_server);
osc_server.endPacket();
msg_out.empty();
*/
}
}
void osc_send_MSG_led(String addr_string , uint8_t state )
{ // Send out a predifined color Directly to the OCS target not bufferd for bundle
// 0 = black
// 1 = red
// 2 = green
// 3 = blue
// 4 = white
if (osc_Isconnected())
{
char address_out[30];
addr_string.toCharArray(address_out, addr_string.length() + 1); //address_out
//IPAddress ip_out(osc_server.remoteIP());
OSCMessage msg_out(address_out);
switch(state)
{
case 0: // black
msg_out.add(uint8_t(0));
msg_out.add(uint8_t(0));
msg_out.add(uint8_t(0));
break;
case 1: // red
msg_out.add(uint8_t(255));
msg_out.add(uint8_t(0));
msg_out.add(uint8_t(0));
break;
case 2: // green
msg_out.add(uint8_t(0));
msg_out.add(uint8_t(255));
msg_out.add(uint8_t(0));
break;
case 3: // blue
msg_out.add(uint8_t(0));
msg_out.add(uint8_t(0));
msg_out.add(uint8_t(255));
break;
case 4: // white
msg_out.add(uint8_t(255));
msg_out.add(uint8_t(255));
msg_out.add(uint8_t(255));
break;
}
msg_out.send(osc_server);
osc_server.endPacket();
msg_out.empty();
yield();
}
}
void osc_queu_MSG_SEL_VAL(String addr_string, int select, int value)
{ // Queue a Message to bundle output with 2 options
//
if (osc_Isconnected())
{
for (int i = 0; i < addr_string.length(); i++)
osc_out_SelVal_addr.enqueue(addr_string.charAt(i));
osc_out_SelVal_addr.enqueue(0); // add a null on the end
osc_out_SelVal_value.enqueue(select);
osc_out_SelVal_value.enqueue(value);
}
}
void osc_queu_MSG_VAL_STRING(String addr_string, String StringValue)
{ // Queue a Message to bundle output with 2 options
//
if (osc_Isconnected())
{
for (int i = 0; i < addr_string.length(); i++)
osc_out_StringAddress.enqueue(addr_string.charAt(i));
osc_out_StringAddress.enqueue(0); // add a null on the end
for (int i = 0; i < StringValue.length(); i++)
osc_out_Stringvalue.enqueue(StringValue.charAt(i));
osc_out_Stringvalue.enqueue(0);
//osc_out_Stringvalue.enqueue(StringValue);
//osc_out_StringIntvalue.enqueue(value);
}
}
void osc_queu_MSG_float(String addr_string, float value)
{ // Queue a float value message to the bundle output
//IPAddress ip_out(osc_server.remoteIP());
//osc_cfg.return_ip_LB = ip_out[3];
if (osc_Isconnected())
{
for (int i = 0; i < addr_string.length(); i++)
osc_out_float_addr.enqueue(addr_string.charAt(i));
osc_out_float_addr.enqueue(0); // add a null on the end
osc_out_float_value.enqueue(value);
}
}
void osc_queu_MSG_int(String addr_string, int value)
{ // Queue a int value message to the bundle output
//IPAddress ip_out(osc_server.remoteIP());
//osc_cfg.return_ip_LB = ip_out[3];
if (osc_Isconnected())
{
for (int i = 0; i < addr_string.length(); i++)
osc_out_int_addr.enqueue(addr_string.charAt(i));
osc_out_int_addr.enqueue(0); // add a null on the end
osc_out_int_value.enqueue(value);
}
}
void osc_queu_MSG_fx_Bool(String addr_string, int deck, byte inarray[_M_NR_FORM_BYTES_][_M_NR_FORM_PAL_OPTIONS_] , uint8_t valSelect)
{ // Queue a int value message to the bundle output
//IPAddress ip_out(osc_server.remoteIP());
//osc_cfg.return_ip_LB = ip_out[3];
if (osc_Isconnected())
{
for (int i = 0; i < addr_string.length(); i++)
osc_out_fx_addr.enqueue(addr_string.charAt(i));
osc_out_fx_addr.enqueue(0); // add a null on the end
osc_out_fx_intvalue.enqueue(deck);
for (uint8_t bit = 0; bit < _M_NR_FORM_BYTES_ ; bit++)
{
for (uint8_t bit_formNr = 0; bit_formNr < 8 ; bit_formNr++)
{
//if ( bit_formNr < 3 ) debugMe( bitRead(inarray[bit][valSelect], bit_formNr));
osc_out_fx_intvalue.enqueue(uint8_t( bitRead(inarray[bit][valSelect], bit_formNr)));
}
}
}
}
void osc_queu_MSG_fx_Int(String addr_string, int deck, byte inarray[NR_FORM_PARTS] )
{ // Queue a int value message to the bundle output
//IPAddress ip_out(osc_server.remoteIP());
//osc_cfg.return_ip_LB = ip_out[3];
if (osc_Isconnected())
{
for (int i = 0; i < addr_string.length(); i++) osc_out_fx_addr.enqueue(addr_string.charAt(i));
osc_out_fx_addr.enqueue(0); // add a null on the end
osc_out_fx_intvalue.enqueue(deck);
for (uint8_t bit = 0; bit < NR_FORM_PARTS ; bit++) osc_out_fx_intvalue.enqueue(inarray[bit]);
}
}
void osc_queu_MSG_rgb(String addr_string, uint8_t red,uint8_t green,uint8_t blue)
{ // Queue a RGB value message to the bundle output
//IPAddress ip_out(osc_server.remoteIP());
//osc_cfg.return_ip_LB = ip_out[3];
if (osc_Isconnected())
{
for (int i = 0; i < addr_string.length(); i++)
osc_out_rgb_addr.enqueue(addr_string.charAt(i));
osc_out_rgb_addr.enqueue(0); // add a null on the end
osc_out_rgb_value.enqueue(red);
osc_out_rgb_value.enqueue(green);
osc_out_rgb_value.enqueue(blue);
}
}
void osc_send_MSG_String(String addr_string, String value)
{ // Send out a String directly to osc target
if (osc_Isconnected())
{
char address_out[20];
char message[20];
addr_string.toCharArray(address_out, addr_string.length() + 1); //address_out
value.toCharArray(message, value.length() + 1);
OSCMessage msg_out(address_out);
msg_out.add(message);
osc_server.beginPacket(osc_server.remoteIP(), OSC_OUTPORT);
msg_out.send(osc_server);
osc_server.endPacket();
msg_out.empty();
yield();
}
}
// Other Functions like Sending loop
bool osc_send_out_float_MSG_buffer()
{ // Send out the Queues as Bundles
// Max bundle size = OSC_BUNDLE_SEND_COUNT
// return true if the buffer still has contents.
if ((osc_out_float_value.isEmpty() != true || osc_out_rgb_value .isEmpty() != true || osc_out_SelVal_value.isEmpty() != true || osc_out_int_value.isEmpty() != true) )
{
if (!osc_Isconnected()) debugMe("Sending withouot OSC connection!");
char address_out[OSC_QEUE_ADD_LEN] ;
memset(address_out, 0, OSC_QEUE_ADD_LEN);
uint8_t i = 0;
float value = 0;
uint8_t red_val = 0;
uint8_t green_val = 0;
uint8_t blue_val = 0;
int menu_select = 0;
int menu_value = 0;
if (osc_out_float_value.count() != 0 || (osc_out_rgb_value.count()) != 0 || (osc_out_SelVal_value.count()) != 0 || (osc_out_int_value.count()) != 0 || osc_out_Stringvalue.count() !=0)
{
OSCBundle bundle_out;
//IPAddress ip_out(WiFi.localIP());
IPAddress ip_out(osc_server.remoteIP());
uint8_t bundlecount = 0;
while ( bundlecount <= OSC_BUNDLE_SEND_COUNT)
{
for (uint8_t z = 0; z < osc_out_float_value.count(); z++)
{
if(osc_out_float_value.isEmpty() != true)
{
i = 0;
while (osc_out_float_addr.peek() != 0 && i < OSC_QEUE_ADD_LEN)
{
address_out[i] = osc_out_float_addr.dequeue();
i++;
}
address_out[i] = osc_out_float_addr.dequeue(); // get the null char for end of string as well. so that we can fetch the next msg next time
value = osc_out_float_value.dequeue();
bundle_out.add(address_out).add(float(value));
bundlecount++;
yield();
memset(address_out, 0, OSC_QEUE_ADD_LEN);
}
if ( bundlecount >= OSC_BUNDLE_SEND_COUNT) { break; }
}
if ( bundlecount >= OSC_BUNDLE_SEND_COUNT) { break; }
for (uint8_t z = 0; z < (osc_out_rgb_value.count() /3 ); z++)
{
if(osc_out_rgb_value.isEmpty() != true)
{
i = 0;
while (osc_out_rgb_addr.peek() != 0 && i <OSC_QEUE_ADD_LEN) {
address_out[i] = osc_out_rgb_addr.dequeue();
i++;
}
address_out[i] = osc_out_rgb_addr.dequeue(); // get the null char for end of string as well. so that we can fetch the next msg next time
red_val = osc_out_rgb_value.dequeue();
green_val = osc_out_rgb_value.dequeue();
blue_val = osc_out_rgb_value.dequeue();
//debugMe("rgb-Addr: " + String(address_out));
bundle_out.add(address_out).add(red_val).add(green_val).add(blue_val).add(255);
bundlecount++;
yield();
memset(address_out, 0, OSC_QEUE_ADD_LEN);
}
if ( bundlecount >= OSC_BUNDLE_SEND_COUNT) { break; }
}
if ( bundlecount >= OSC_BUNDLE_SEND_COUNT) { break; }
for (uint8_t z = 0; z < (osc_out_SelVal_value.count() /2 ); z++)
{
if(osc_out_SelVal_value.isEmpty() != true)
{
i = 0;
while (osc_out_SelVal_addr.peek() != 0 && i <OSC_QEUE_ADD_LEN) {
address_out[i] = osc_out_SelVal_addr.dequeue();
i++;
}
address_out[i] = osc_out_SelVal_addr.dequeue(); // get the null char for end of string as well. so that we can fetch the next msg next time
menu_select = osc_out_SelVal_value.dequeue();
menu_value = osc_out_SelVal_value.dequeue();
//debugMe("SelVal-Addr: " + String(address_out));
bundle_out.add(address_out).add(menu_select).add(menu_value);
bundlecount++;
yield();
memset(address_out, 0, OSC_QEUE_ADD_LEN);
}
if ( bundlecount >= OSC_BUNDLE_SEND_COUNT) { break; }
}
if ( bundlecount >= OSC_BUNDLE_SEND_COUNT) { break; }
for (uint8_t z = 0; z < (osc_out_int_value.count() ); z++)
{
if(osc_out_int_value.isEmpty() != true)
{
i = 0;
while (osc_out_int_addr.peek() != 0 && i <OSC_QEUE_ADD_LEN) {
address_out[i] = osc_out_int_addr.dequeue();
i++;
}
address_out[i] = osc_out_int_addr.dequeue(); // get the null char for end of string as well. so that we can fetch the next msg next time
menu_value = osc_out_int_value.dequeue();
//debugMe("SelVal-Addr: " + String(address_out));
bundle_out.add(address_out).add(menu_value);
bundlecount++;
yield();
memset(address_out, 0, OSC_QEUE_ADD_LEN);
}
if ( bundlecount >= OSC_BUNDLE_SEND_COUNT) { break; }
}
if ( bundlecount >= OSC_BUNDLE_SEND_COUNT) { break; }
for (uint8_t z = 0; z < (osc_out_Stringvalue.count() ); z++)
{
if(osc_out_Stringvalue.isEmpty() != true)
{
i = 0;
while (osc_out_StringAddress.peek() != 0 && i <OSC_QEUE_ADD_LEN) {
address_out[i] = osc_out_StringAddress.dequeue();
i++;
}
address_out[i] = osc_out_StringAddress.dequeue(); // get the null char for end of string as well. so that we can fetch the next msg next time
i = 0;
char CharVal[OSC_QEUE_ADD_LEN] ;
memset(CharVal, 0, OSC_QEUE_ADD_LEN);
while (osc_out_Stringvalue.peek() != 0 && i <OSC_QEUE_ADD_LEN) {
CharVal[i] = osc_out_Stringvalue.dequeue();
i++;
}
CharVal[i] = osc_out_Stringvalue.dequeue(); // get the null char for end of string as well. so that we can fetch the next msg next time
//String StringVal = osc_out_Stringvalue.dequeue();
debugMe(CharVal);
//uint8_t IntVal = osc_out_StringIntvalue.dequeue();
//debugMe("SelVal-Addr: " + String(address_out));
bundle_out.add(address_out).add(CharVal);
bundlecount++;
yield();
memset(address_out, 0, OSC_QEUE_ADD_LEN);
}
if ( bundlecount >= OSC_BUNDLE_SEND_COUNT || osc_out_Stringvalue.isEmpty()) { break; }
}
if (osc_out_float_value.isEmpty() && (osc_out_rgb_value.isEmpty()) && (osc_out_SelVal_value.isEmpty()) && (osc_out_int_value.isEmpty()) && osc_out_Stringvalue.isEmpty() ) break;
} // end while
//debugMe(String("E " + String(osc_out_float_value.isEmpty()) + " - " + String(osc_out_SelVal_value.isEmpty()) + " - " + String(osc_out_int_value.isEmpty()) + " - " + String(osc_out_Stringvalue.isEmpty()) + " - " + String(Refreshloop) ));
//debugMe(String("C " + String(osc_out_float_value.count()) + " - " + String(osc_out_SelVal_value.count()) + " - " + String(osc_out_int_value.count()) + " - " + String(osc_out_Stringvalue.count()) + " - " + String(Refreshloop) ));
if (osc_out_float_value.isEmpty()
&& (osc_out_rgb_value.isEmpty())
&& (osc_out_SelVal_value.isEmpty())
&& (osc_out_int_value.isEmpty())
&& osc_out_Stringvalue.isEmpty()
&& Refreshloop >= REFRESH_LOOP_END
&& MobRefreshloop >= REFRESH_LOOP_END
&& !get_bool(FFT_OSTC_VIZ))
bundle_out.add("/ostc/master/connled").add(0).add(255).add(random8(192)).add(255); // each bundle should refresh the led. when the buffers are amty and were not refreshing all send green
else if (!get_bool(FFT_OSTC_VIZ)) bundle_out.add("/ostc/master/connled").add(255).add(0).add(random8()).add(255); // else send red+some blue to indicate that we are still refreshing
osc_server.beginPacket(ip_out,OSC_OUTPORT);// OSC_OUTPORT); //{172,16,222,104}, 8001) ; // osc_server.remotePort()
bundle_out.send(osc_server);
osc_server.endPacket();
bundle_out.empty();
yield();
//delay(1);
}
}
if (osc_out_float_value.count() == 0 && (osc_out_rgb_value.count()) == 0 && (osc_out_SelVal_value.count()) == 0 && (osc_out_int_value.count()) == 0 && osc_out_Stringvalue.count () == 0)
return false;
else return true;
}
bool osc_send_out_API_FX_MSG_buffer()
{ // Send out the Queues as Bundles
// Max bundle size = OSC_FX_BUNDLE_SEND_COUNT
// return true if the buffer still has contents.
if (osc_out_fx_intvalue.isEmpty() != true )
{
char address_out[OSC_QEUE_ADD_LEN] ;
memset(address_out, 0, OSC_QEUE_ADD_LEN);
uint8_t i = 0;
int deckSel ;
uint8_t send_val = 0;
if (osc_out_fx_intvalue.count() != 0 )
{
OSCBundle bundle_out;
//IPAddress ip_out(WiFi.localIP());
IPAddress ip_out(osc_server.remoteIP());
uint8_t bundlecount = 0;
while ( bundlecount <= OSC_FX_BUNDLE_SEND_COUNT)
{
for (uint8_t z = 0; z < (osc_out_fx_intvalue.count() ); z++)
{
if(osc_out_fx_intvalue.isEmpty() != true)
{
i = 0;
while (osc_out_fx_addr.peek() != 0 && i <OSC_QEUE_ADD_LEN) {
address_out[i] = osc_out_fx_addr.dequeue();
i++;
}
address_out[i] = osc_out_fx_addr.dequeue(); // get the null char for end of string as well. so that we can fetch the next msg next time
deckSel = osc_out_fx_intvalue.dequeue();
OSCMessage msg_out(address_out);
msg_out.add(deckSel);
for (uint8_t foromi = 0; foromi < NR_FORM_PARTS ; foromi++)
{
int sendVal = osc_out_fx_intvalue.dequeue() ;
if ( foromi < 5 ) debugMe(sendVal);
msg_out.add(sendVal);
}
bundle_out.add(msg_out);
bundlecount++;
yield();
memset(address_out, 0, OSC_QEUE_ADD_LEN);
}
if ( bundlecount >= OSC_FX_BUNDLE_SEND_COUNT) { break; }
}
if (osc_out_fx_intvalue.isEmpty() ) break;
} // end while
osc_server.beginPacket(ip_out,OSC_OUTPORT);// OSC_OUTPORT); //{172,16,222,104}, 8001) ; // osc_server.remotePort()
bundle_out.send(osc_server);
osc_server.endPacket();
bundle_out.empty();
yield();
//delay(1);
}
}
if (osc_out_fx_intvalue.count() == 0 )
return false;
else return true;
}
/*
void osc_StC_Send_Confname(uint8_t SaveNo, char ConfName[])
{
OSCBundle bundle_out;
IPAddress ip_out(osc_server.remoteIP());
char ConfOutAddress[25] ;
String CounfOutString = "/ostc/master/savename/" + String(SaveNo);
CounfOutString.toCharArray(ConfOutAddress, CounfOutString.length() + 1);
bundle_out.add(ConfOutAddress ).add(ConfName);
osc_server.beginPacket(ip_out , OSC_OUTPORT); //osc_server.remotePort());//
bundle_out.send(osc_server);
osc_server.endPacket();
bundle_out.empty();
}*/
void osc_StC_Send_CharArray(String Address, char ConfName[])
{
if (osc_Isconnected())
{
OSCBundle bundle_out;
IPAddress ip_out(osc_server.remoteIP());
char ConfOutAddress[25] ;
Address.toCharArray(ConfOutAddress, Address.length() + 1);
bundle_out.add(ConfOutAddress ).add(ConfName);
osc_server.beginPacket(ip_out , OSC_OUTPORT); //osc_server.remotePort());//
bundle_out.send(osc_server);
osc_server.endPacket();
bundle_out.empty();
}
}
void osc_Send_String(String Address, String StringName)
{
if (osc_Isconnected())
{
OSCBundle bundle_out;
IPAddress ip_out(osc_server.remoteIP());
char ConfOutAddress[32] ;
Address.toCharArray(ConfOutAddress, Address.length() + 1);
bundle_out.add(ConfOutAddress ).add(StringName.c_str());
osc_server.beginPacket(ip_out , OSC_OUTPORT); //osc_server.remotePort());//
bundle_out.send(osc_server);
osc_server.endPacket();
bundle_out.empty();
}
}
void osc_StC_Load_confname_Refresh(uint8_t sel_save_no)
{
osc_queu_MSG_VAL_STRING("/ostc/master/confname" , deck[0].cfg.confname );
osc_queu_MSG_int("/ostc/master/playNr" , led_cfg.Play_Nr);
osc_queu_MSG_VAL_STRING("/ostc/master/savename/" + String(sel_save_no) , deck[0].cfg.confname);
osc_queu_MSG_rgb(String("/ostc/master/conf/l/"+String(sel_save_no)), 0,255,0);
}
void osc_multiply_send()
{ // TouchOSC M
for (uint8_t x = 1;x <= 11 ; x++ )
{
if (x != osc_cfg.conf_multiply)
osc_queu_MSG_float((String("/multipl/") + String(x) + String("/1")), 0);
else
osc_queu_MSG_float((String("/multipl/") + String(x) + String("/1")), 1);
}
}
uint16_t osc_miltiply_get()
{
uint16_t value = 1;
switch (osc_cfg.conf_multiply)
{
case 1:
value = 1;
break;
case 2:
value = 10;
break;
case 3:
value = 100;
break;
case 4:
value = 8;
break;
case 5:
value = 16;
break;
case 6:
value = 32;
break;
case 7:
value = 64;
break;
case 8:
value = 128;
break;
case 9:
value = 256;
break;
case 10:
value = 512;
break;
case 11:
value = 1024;
break;
default:
value = 1;
break;
}
return value;
}
// recive conf multiply toggle
void osc_multipl_rec(OSCMessage &msg, int addrOffset)
{ // recive routing of Multiply ocs settings by 1 10 or 100
// OSC MESSAGE :/m/multipl/?/1
if (bool(msg.getFloat(0)) == true)
{
String select_mode_string;
// String select_bit_string;
char address[10];
bool switch_bool = false;
msg.getAddress(address, addrOffset + 1);
for (byte i = 0; i < sizeof(address); i++)
{
if (address[i] == '/')
{
switch_bool = true;
}
else if (switch_bool == false)
{
select_mode_string = select_mode_string + address[i];
}
}
osc_cfg.conf_multiply = select_mode_string.toInt();
osc_multiply_send();
} // end new msg
}
#ifndef ARTNET_DISABLED
void osc_rec_artnet_info(OSCMessage &msg, int addrOffset)
{
// OSC MESSAGE :/s/AN/Row/collum
String collum_string;
String row_string;
char address[4]; // to pick info aut of the msg address
//char address_out[20];
//int select_bit = 0;
String select_bit_string;
bool switch_bool = false; // for toggels to get row and collum
String outbuffer = "/s/ANL"; // OSC return address
float outvalue = 0; // return value to labels
String out_add_label; // address label
msg.getAddress(address, addrOffset - 4, 1); // get the select-bit info
memset(address, 0, sizeof(address)); // rest the address to blank
msg.getAddress(address, addrOffset + 1); // get the address for row / collum
for (byte i = 0; i < sizeof(address); i++)
{
if (address[i] == '/') {
switch_bool = true;
}
else if (switch_bool == false)
{
row_string = row_string + address[i];
}
else
collum_string = collum_string + address[i];
}
int row = row_string.toInt() - 1;
int collum = collum_string.toInt() - 1; // Whit CRGB value in the pallete
memset(address, 0, sizeof(address));
switch (collum)
{
case 0: // Artnet Start universe
switch (row)
{
case 0:
artnet_cfg.startU = constrain(artnet_cfg.startU - osc_miltiply_get(), 0, 255);
break;
case 2:
artnet_cfg.startU = constrain(artnet_cfg.startU + osc_miltiply_get(), 0, 255);
break;
}
outvalue = artnet_cfg.startU;
out_add_label = "/ASUL";
break;
case 1: // artnet NR universes
switch (row)
{
case 0:
artnet_cfg.numU = constrain(artnet_cfg.numU - osc_miltiply_get(), 0, 4);
break;
case 2:
artnet_cfg.numU = constrain(artnet_cfg.numU + osc_miltiply_get(), 0, 4);
break;
}
outvalue = artnet_cfg.numU;
out_add_label = "/ANUL";
break;
}
outbuffer = String("/DS" + out_add_label);
osc_queu_MSG_float(outbuffer, outvalue);
}
void osc_toggle_artnet(bool value)
{
//debugMe("in artnet");
if (value == true) {
debugMe("enable artnet recive");
write_bool(ARTNET_RECIVE, true); // artnet_enabled = true;
FS_artnet_write();
deck[0].cfg.led_master_cfg.bri = led_cfg.max_bri;
WiFi_artnet_rc_enable();
}
else {
debugMe("disable artnet recive");
write_bool(ARTNET_RECIVE, false); //artnet_enabled = false;
FS_artnet_write();
ESP.restart();
}
}
#endif
void osc_StC_FFT_vizIt()
{ // Send out the values x times a second for visualisation
/*
OSCBundle bundle_out;
IPAddress ip_out(osc_server.remoteIP());
//char ConfOutAddress[32] ;
//Address.toCharArray(ConfOutAddress, Address.length() + 1);
bundle_out.add("/ostc/audio/color").add(LEDS_FFT_get_color_result(0,0)).add(LEDS_FFT_get_color_result(0,1)).add(LEDS_FFT_get_color_result(0,2)).add(255);
bundle_out.add("/ostc/audio/rfps").add(LEDS_get_FPS());
bundle_out.add("/ostc/audio/rbri").add(LEDS_get_real_bri() );
bundle_out.add("/ostc/audio/sum/bri").add(deck[0].run.fft.fft_color_result_bri );
bundle_out.add("/ostc/audio/sum/fps").add( deck[0].run.fft.fft_color_fps);
bundle_out.add("/ostc/audio/sum/red").add( LEDS_FFT_get_color_result(0,0));
bundle_out.add("/ostc/audio/sum/green").add( LEDS_FFT_get_color_result(0,1));
bundle_out.add("/ostc/audio/sum/blue").add( LEDS_FFT_get_color_result(0,2));
osc_server.beginPacket(ip_out , OSC_OUTPORT); //osc_server.remotePort());//
bundle_out.send(osc_server);
osc_server.endPacket();
bundle_out.empty();
for(uint8_t bin = 0 ; bin < 4 ; bin++)
{
bundle_out.add("/ostc/audio/abin/"+ char(bin)).add(deck[0].run.fft_data[6-bin].avarage ) ;
bundle_out.add("/ostc/audio/mbin/"+ char(bin)).add(deck[0].run.fft_data[6-bin].max );
bundle_out.add("/ostc/audio/trig/"+ char(bin)).add(deck[0].cfg.fft_config.trigger[6-bin] );
bundle_out.add("/ostc/audio/lbin/"+ char(bin)).add(fft_bin_results[6-bin] );
bundle_out.add("/ostc/audio/rbin/"+ char(bin)).add(constrain((fft_bin_results[6-bin] - deck[0].cfg.fft_config.trigger[6-bin] ) , 0 ,255 ) );
}