-
Notifications
You must be signed in to change notification settings - Fork 2
/
ti_lpc.cpp
7543 lines (4963 loc) · 171 KB
/
ti_lpc.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
/*
Copyright (C) 2018 BrerDawg
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 2
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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//portions of this code come from the 'Speech library for Arduino' project: https://github.com/going-digital/Talkie
//ti_lpc.cpp
//v1.01 01-jun-2018 //
//v1.02 12-may-2019 //started to incorperate rtaudio
//v1.03 31-may-2019 //updated to mgraph v1.13
//v1.04 25-oct-2020 //further fixes
//v1.05 18-sep-2022 //added more features, such as auto address stepping with delta and delay options, see 'addr_step_auto_val_delay', 'addr_step_auto_val_delta'
//v1.06 22-jul-2023 //moded for namespace 'filter_code::'
//v1.07 18-sep-2023 //moded for namespace 'gc_srateconv::'
//v1.08 27-aug-2024 //added .au audio file select dialog via button, refer: 'select_au_file()' 'slast_au_filename'
#include "ti_lpc.h"
//refer: https://en.wikipedia.org/wiki/Texas_Instruments_LPC_Speech_Chips
//refer: http://www.stuartconner.me.uk/ti_portable_speech_lab/ti_portable_speech_lab.htm
//rom dump site
//refer: http://seanriddle.com/speakandspell.html
//mame coeffs
//refer: https://github.com/mamedev/mame/blob/master/src/devices/sound/tms5110r.hxx
//description of rom and hardware - good
//refer: http://furrtek.free.fr/index.php?a=speakandspell&ss=6&i=2
//talkie coeff discussion
//refer: https://github.com/going-digital/Talkie/issues/6
//pitch details from patent 4331836
//page 22(right) mentions pitch interpolator
//page 12(right) mentions pitch register increment details
//tms5220 emulator for beeb -
//http://sam.aiki.info/code/beebem-pnd/beebem-0.0.13-x/src/speech.cc
//https://www.google.com.au/search?biw=1746&bih=915&ei=g9kAW63hJ4Op0gTi2IfYBA&q=beeb+emulator+Palazzolo+tms5220&oq=beeb+emulator+Palazzolo+tms5220&gs_l=psy-ab.3...16768.17286.0.17636.4.4.0.0.0.0.0.0..0.0....0...1.1.64.psy-ab..4.0.0....0.20mkwRhrpGY
//global vars
Fl_Double_Window* wndMain;
PrefWnd* pref_wnd=0;
PrefWnd* font_pref_wnd=0;
GCLed *led_addr_step0;
//Fl_Value_Slider *fvs_aud_gain;
string csIniFilename;
int iBorderWidth;
int iBorderHeight;
int maximize_boundary_x, maximize_boundary_y, maximize_boundary_w, maximize_boundary_h; //resize()
//int restore_size_x, restore_size_y, restore_size_w, restore_size_h;
int gi0,gi1,gi2,gi3,gi4;
double gd0,gd1,gd2,gd3,gd4;
string app_path; //path this app resides on
string dir_seperator="\\"; //assume dos\windows folder directory seperator
string sglobal;
string sg_col1, sg_col2;
int gi;
int font_num = cnFontEditor;
int font_size = cnSizeEditor;
//static Fl_Font extra_font;
unsigned long long int ns_tim_start1; //a ns timer start val
double perf_period; //used for windows timings in timing_start( ), timing_stop( )
string pref_aud_editor;
string slpc_bytes;
int iAppExistDontRun = 1; //if set, app probably exist and user doesn't want to run another
//set it to assume we don't want to run another incase user closes
//wnd without pressing either 'Run Anyway' or 'Don't Run, Exit' buttons
#ifndef compile_for_windows
Display *gDisp;
#endif
//windows code
#ifdef compile_for_windows
PROCESS_INFORMATION processInformation;
#endif
bool inited = 0;
string slast_filename;
string slast_binary_file;
string slast_rom0_filename;
string slast_rom1_filename;
string slast_au_filename;
string slast_lpc_hex_byte_text_fname;
string slast_tms_code_tables_text_fname;
extern unsigned char phrom_rom[16][16384];
int stop_lpc_addr = 0;
int last_render_rom_byte_cnt = 0; //how many rom byte consumed by the last rendering
bool my_verbose = 0;
int audio_hardware_bits_max_integer = 32767;
int audio_hardware_bits_min_integer = -32768;
int lev_clip_flag;
int lev_clip_ch;
int lev_clip_polarity;
double lev_clip_val;
//linux code
#ifndef compile_for_windows
bool b_use_jack = 1; // see also in 'globals.h': #define include_jack
#endif
//windows code
#ifdef compile_for_windows
bool b_use_jack = 0; // see also in 'globals.h': #define include_jack
#endif
int pref_use_jack = b_use_jack;
unsigned int framecnt = 4096;
double VU0 = def_VU0; //integer value req to show 0 VU, e.g: for 16 bit audio at -20dBFS = 3276
#ifdef include_jack
cjack myjack; //jack obj
st_jack_tag st_jack; //jack variables
#endif
flts *inbuf1, *inbuf2;
flts *outbuf1, *outbuf2;
#ifdef include_jack
sample_t *jinbuf[ 8 ];
sample_t *joutbuf[ 8 ];
#endif
float lpc_srate = 8000; //srate the rom was encoded with
//int srate = cn_srate;
float frame_time = 25e-3;
int generated_samp_cnt = 0;
double twopi = 2.0 * M_PI;
filter_code::st_fir fir1, fir2;
int dbg_dump = 10;
int bufcnt = 0;
int imin = 0;
int imax = 0;
int lpccnt = 1; //set this to show first byte has been counted
audio_formats af, af2;
st_audio_formats_tag saf;
unsigned int last_say_offset = 0;
uint8_t periodCounter;
float x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10;
float chirp_step;
Talkie talk;
bool bperiod_6bits = 0;
uint8_t *vsm = 0; //holds a voice synth memory rom
float *bufsamp0 = 0;
float *bufsamp1 = 0;
int bufsamp_sz = cn_bufsz;
//int mode = 1;
//int aud_pos = 0;
//function protos
void cb_user1(void *o, int row,int ctrl);
void cb_user2(void *o, int row,int ctrl);
void update_fonts();
void DoQuit();
bool process_audio( int16_t* buf, int bufsz, int &bufptr, bool showframes, bool tmc_0280, float interp_step );
bool process_audio_not_tmc0280( int16_t* buf, int bufsz, int &bufptr, bool showframes );
bool process_audio_tmc0280( int16_t* buf, int16_t* bf2, int16_t* bf3, int bufsz, bool showframes, float interp_step, bool newframe, float chirp_sub_steps, bool skip_interp, float chirp_sub_modulo );
bool build_rom_word_addr_list( int offs, string fname );
int str_to_hex_buf( string ss, uint16_t *bf, int bfsz );
int str_to_decimal_buf( string ss, int16_t *bf, int bfsz );
void stop_audio();
bool start_audio( void* obj );
void cb_pref(Fl_Widget*w, void* v);
void cb_font_pref(Fl_Widget*w, void* v);
void cb_btAbout(Fl_Widget *, void *);
void cb_help(Fl_Widget *, void *);
void cb_open_audio_editor(Fl_Widget *, void *);
void cb_bt_quit(Fl_Widget *, void *);
void cb_open_file(Fl_Widget *, void *);
void cb_save_file(Fl_Widget *, void *);
int16_t buf[ cn_bufsz ];
int16_t buf2[ cn_bufsz ];
int16_t buf3[ cn_bufsz ];
int buf4[ cn_bufsz ];
float fbuf1[ cn_bufsz ];
float fbuf2[ cn_bufsz ];
int16_t from_k0, from_k1, from_k2, from_k3, from_k4, from_k5, from_k6, from_k7, from_k8, from_k9;
int16_t tgt_k0, tgt_k1, tgt_k2, tgt_k3, tgt_k4, tgt_k5, tgt_k6, tgt_k7, tgt_k8, tgt_k9;
/*
uint8_t tmsEnergy[0x10] = {0x00,0x02,0x03,0x04,0x05,0x07,0x0a,0x0f,0x14,0x20,0x29,0x39,0x51,0x72,0xa1,0xff};
uint8_t tmsPeriod[0x40] = {0x00,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2D,0x2F,0x31,0x33,0x35,0x36,0x39,0x3B,0x3D,0x3F,0x42,0x45,0x47,0x49,0x4D,0x4F,0x51,0x55,0x57,0x5C,0x5F,0x63,0x66,0x6A,0x6E,0x73,0x77,0x7B,0x80,0x85,0x8A,0x8F,0x95,0x9A,0xA0};
int16_t tmsK1[0x20] = {0x82C0,0x8380,0x83C0,0x8440,0x84C0,0x8540,0x8600,0x8780,0x8880,0x8980,0x8AC0,0x8C00,0x8D40,0x8F00,0x90C0,0x92C0,0x9900,0xA140,0xAB80,0xB840,0xC740,0xD8C0,0xEBC0,0x0000,0x1440,0x2740,0x38C0,0x47C0,0x5480,0x5EC0,0x6700,0x6D40};
int16_t tmsK2[0x20] = {0xAE00,0xB480,0xBB80,0xC340,0xCB80,0xD440,0xDDC0,0xE780,0xF180,0xFBC0,0x0600,0x1040,0x1A40,0x2400,0x2D40,0x3600,0x3E40,0x45C0,0x4CC0,0x5300,0x5880,0x5DC0,0x6240,0x6640,0x69C0,0x6CC0,0x6F80,0x71C0,0x73C0,0x7580,0x7700,0x7E80};
int8_t tmsK3[0x10] = {0x92,0x9F,0xAD,0xBA,0xC8,0xD5,0xE3,0xF0,0xFE,0x0B,0x19,0x26,0x34,0x41,0x4F,0x5C};
int8_t tmsK4[0x10] = {0xAE,0xBC,0xCA,0xD8,0xE6,0xF4,0x01,0x0F,0x1D,0x2B,0x39,0x47,0x55,0x63,0x71,0x7E};
int8_t tmsK5[0x10] = {0xAE,0xBA,0xC5,0xD1,0xDD,0xE8,0xF4,0xFF,0x0B,0x17,0x22,0x2E,0x39,0x45,0x51,0x5C};
int8_t tmsK6[0x10] = {0xC0,0xCB,0xD6,0xE1,0xEC,0xF7,0x03,0x0E,0x19,0x24,0x2F,0x3A,0x45,0x50,0x5B,0x66};
int8_t tmsK7[0x10] = {0xB3,0xBF,0xCB,0xD7,0xE3,0xEF,0xFB,0x07,0x13,0x1F,0x2B,0x37,0x43,0x4F,0x5A,0x66};
int8_t tmsK8[0x08] = {0xC0,0xD8,0xF0,0x07,0x1F,0x37,0x4F,0x66};
int8_t tmsK9[0x08] = {0xC0,0xD4,0xE8,0xFC,0x10,0x25,0x39,0x4D};
int8_t tmsK10[0x08] = {0xCD,0xDF,0xF1,0x04,0x16,0x20,0x3B,0x4D};
*/
//T0280A 0281, year: ~1978
//see: https://github.com/mamedev/mame/blob/master/src/devices/sound/tms5110r.hxx
int16_t tmsEnergy_0280[ 16 ] = { 0, 0, 1, 1, 2, 3, 5, 7, 10, 15, 21, 30, 43, 61, 86, 0 };
int16_t tmsPeriod_0280[ 64 ] = { 0, 41, 43, 45, 47, 49, 51, 53, 55, 58, 60, 63, 66, 70, 73, 76, 79, 83, 87, 90, 94, 99, 103, 107, 112, 118, 123, 129, 134, 140, 147, 153 };
//coeffs are multiplied by 512
int16_t tms_k0_0280[ 32 ] = { -501, -497, -493, -488, -480, -471, -460, -446, -427, -405, -378, -344, -305, -259, -206, -148, -86, -21, 45, 110, 171, 227, 277, 320, 357, 388, 413, 434, 451, 464, 474, 498 };
int16_t tms_k1_0280[ 32 ] = { -349, -328, -305, -280, -252, -223, -192, -158, -124, -88, -51, -14, 23, 60, 97, 133, 167, 199, 230, 259, 286, 310, 333, 354, 372, 389, 404, 417, 429, 439, 449, 506 };
int16_t tms_k2_0280[ 16 ] = { -397, -365, -327, -282, -229, -170, -104, -36, 35, 104, 169, 228, 281, 326, 364, 396 };
int16_t tms_k3_0280[ 16 ] = { -369, -334, -293, -245, -191, -131, -67, -1, 64, 128, 188, 243, 291, 332, 367, 397 };
int16_t tms_k4_0280[ 16 ] = { -319, -286, -250, -211, -168, -122, -74, -25, 24, 73, 121, 167, 210, 249, 285, 318 };
int16_t tms_k5_0280[ 16 ] = { -290, -252, -209, -163, -114, -62, -9, 44, 97, 147, 194, 238, 278, 313, 344, 371 };
int16_t tms_k6_0280[ 16 ] = { -291, -256, -216, -174, -128, -80, -31, 19, 69, 117, 163, 206, 246, 283, 316, 345 };
int16_t tms_k7_0280[ 8 ] = { -218, -133, -38, 59, 152, 235, 305, 361 };
int16_t tms_k8_0280[ 8 ] = { -226, -157, -82, -3, 76, 151, 220, 280 };
int16_t tms_k9_0280[ 8 ] = { -179, -122, -61, 1, 62, 123, 179, 231 };
//refer https://github.com/mamedev/mame/blob/master/src/devices/sound/tms5110r.hxx
//#define CHIRP_SIZE 41
//int8_t chirp[CHIRP_SIZE] = {0x00,0x2a,0xd4,0x32,0xb2,0x12,0x25,0x14,0x02,0xe1,0xc5,0x02,0x5f,0x5a,0x05,0x0f,0x26,0xfc,0xa5,0xa5,0xd6,0xdd,0xdc,0xfc,0x25,0x2b,0x22,0x21,0x0f,0xff,0xf8,0xee,0xed,0xef,0xf7,0xf6,0xfa,0x00,0x03,0x02,0x01};
#define CHIRP_SIZE_0280 50
//int8_t chirp_0280[ CHIRP_SIZE_0280 ] = { 0x00, 0x2a, 0xd4, 0x32, 0xb2, 0x12, 0x25, 0x14, 0x02, 0xe1, 0xc5, 0x02, 0x5f, 0x5a, 0x05, 0x0f, 0x26, 0xfc, 0xa5, 0xa5, 0xd6, 0xdd, 0xdc, 0xfc, 0x25, 0x2b, 0x22, 0x21, 0x0f, 0xff, 0xf8, 0xee, 0xed, 0xef, 0xf7, 0xf6, 0xfa, 0x00, 0x03, 0x02, 0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
int8_t chirp_0280[ CHIRP_SIZE_0280 + 2] = { 0, 42, 212, 50, 178, 18, 37, 20, 2, 225, 197, 2, 95, 90, 5, 15, 38, 252, 165, 165, 214, 221, 220, 252, 37, 43, 34, 33, 15, 255, 248, 238, 237, 239, 247, 246, 250, 0, 3, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int ichirp_size = CHIRP_SIZE_0280; //this will change if user modifies the chirp byte string in text edit
mystr tim1;
struct st_osc_params_tag //a pointer to this is stored in stuct passed to audio proc callback, see 'st_rtaud_arg_tag.usr_ptr'
{
float freq0;
float gain0;
float freq1;
float gain1;
} st_osc_params;
rtaud rta; //rtaudio
st_rtaud_arg_tag st_rta_arg; //this is used in audio proc callback to work out chan in/out counts
double theta0 = 0;
double theta1 = 0;
double theta0_inc;
double theta1_inc;
#define twopi (M_PI * 2)
int dbg_cnt = 0;
int addr_step_auto_state = 0; //0: stopped, 1: start sounding, 2: sounding, 3: sounding finished, 4: apply delay, 5: apply delta check addr valid - else goto stop, 6: goto step 1
int addr_step_auto_count = 0;
float addr_step_auto_val_delay = cn_timer_period;
int addr_step_auto_val_delta = 1;
float addr_step_auto_delay_sum = 0;
vector<int>vaddr_hist;
int addr_hist_pos = 0;
//----------------------------- Main Menu --------------------------
Fl_Menu_Item menuitems[] =
{
{ "&File", 0, 0, 0, FL_SUBMENU },
{ "&OpenFile...", FL_CTRL + 'o' , (Fl_Callback *)cb_open_file, 0 },
{ "&SaveFile...", FL_CTRL + 's' , (Fl_Callback *)cb_save_file, 0, FL_MENU_DIVIDER },
{ "E&xit", FL_CTRL + 'q' , (Fl_Callback *)cb_bt_quit, 0 },
{ 0 },
#ifndef compile_for_windows
{ "&Edit", 0, 0, 0, FL_SUBMENU },
// { "&Undo", FL_CTRL + 'z', (Fl_Callback *)cb_edit_undo},
// { "&Redo", FL_CTRL + 'y', (Fl_Callback *)cb_edit_redo, 0, FL_MENU_DIVIDER },
// { "Cu&t", FL_CTRL + 'x', (Fl_Callback *)cb_edit_cut },
// { "&Copy", FL_CTRL + 'c', (Fl_Callback *)cb_edit_copy },
// { "Past&e", FL_CTRL + 'v', (Fl_Callback *)cb_edit_paste, 0, FL_MENU_DIVIDER },
{ "&Preferences..", 0, (Fl_Callback *)cb_pref},
// { "&Font Pref..", 0, (Fl_Callback *)cb_font_pref},
{ 0 },
#endif
{ "&Help", 0, 0, 0, FL_SUBMENU },
{ "'help.txt'", 0 , (Fl_Callback *)cb_help, 0, FL_MENU_DIVIDER },
{ "&About", 0 , (Fl_Callback *)cb_btAbout, 0 },
{ 0 },
{ 0 }
};
//--------------------------------------------------------------------
//----------------------------------------------------------
mytexteditor::mytexteditor( int X, int Y, int W, int H, const char* l = 0 ) : Fl_Text_Editor( X, Y, W, H, l )
{
left_button = 0;
wstart = 0;
wend = 0;
id0 = 0;
}
int mytexteditor::handle( int e )
{
string s1;
mystr m1;
bool need_redraw = 0;
bool dont_pass_on = 0;
/*
if ( e == FL_MOVE)
{
// if( left_button )
{
if( ( wstart ) | ( wend ) )
{
buffer()->select( wstart, wend );
s1 = buffer()->selection_text();
double dd;
sscanf( s1.c_str(), "%lf", &dd );
printf("text num: '%s', num: %.17e\n", s1.c_str(), dd );
// ((mywnd*)parent())->paste_num( dd );
((mywnd*)parent())->paste_str_num( s1 );
need_redraw = 0;
dont_pass_on = 1;
}
}
}
*/
if ( e == FL_PUSH )
{
Fl_Text_Editor::handle( e ); //call base function now so it will process mouse click as below code needs it
if( Fl::event_button() == 1 )
{
left_button = 1;
need_redraw = 1;
// dont_pass_on = 1; //note base function already called above
}
if( Fl::event_button() == 3 )
{
wstart = 0;
wend = 0;
// buffer()->highlight( wstart, wend );
int start, end;
// buffer()->selection_position( &start, &end );
int cursor_pos = insert_position();
printf("te push: %d, %d, %d\n", start, end, cursor_pos );
char *sz = buffer()->line_text(cursor_pos);
m1 = sz;
m1.FindReplace( s1, "0x", "", 0);
m1 = s1;
m1.FindReplace( s1, "\r", "", 0);
m1 = s1;
m1.FindReplace( s1, "\n", "", 0);
printf("line: '%s'\n", s1.c_str() );
if( s1.find( ":" ) != string::npos ) //comment prefixed?
{
m1 = s1;
m1.cut_just_past_first_find_and_keep_right( s1, ":", 0 );
}
say_lpc_str( s1 );
need_redraw = 1;
// dont_pass_on = 1; //note base function already called above
}
}
if ( e == FL_RELEASE )
{
if( Fl::event_button() == 1 )
{
left_button = 0;
}
need_redraw = 1;
// dont_pass_on = 1;
}
if ( need_redraw ) redraw();
if( dont_pass_on ) return 1;
return Fl_Text_Editor::handle(e);
}
//----------------------------------------------------------
int addr_history_last = 0;
void addr_add_history( int addr )
{
if( addr_history_last == addr ) return;
addr_history_last = addr;
vaddr_hist.push_back( addr );
addr_hist_pos = vaddr_hist.size() - 1;
}
//----------------------------------------------------------
mytexteditor2::mytexteditor2( int X, int Y, int W, int H, const char* l = 0 ) : Fl_Text_Editor( X, Y, W, H, l )
{
left_button = 0;
wstart = 0;
wend = 0;
id0 = 0;
}
int mytexteditor2::handle( int e )
{
string s1, s_addr;
bool need_redraw = 0;
bool dont_pass_on = 0;
/*
if ( e == FL_MOVE)
{
// if( left_button )
{
if( ( wstart ) | ( wend ) )
{
buffer()->select( wstart, wend );
s1 = buffer()->selection_text();
double dd;
sscanf( s1.c_str(), "%lf", &dd );
printf("text num: '%s', num: %.17e\n", s1.c_str(), dd );
// ((mywnd*)parent())->paste_num( dd );
((mywnd*)parent())->paste_str_num( s1 );
need_redraw = 0;
dont_pass_on = 1;
}
}
}
*/
if ( e == FL_PUSH )
{
Fl_Text_Editor::handle( e ); //call base function now so it will process mouse click as below code needs it
if( Fl::event_button() == 1 )
{
left_button = 1;
}
if( Fl::event_button() == 3 )
{
wstart = 0;
wend = 0;
buffer()->highlight( wstart, wend );
int start, end;
// buffer()->selection_position( &start, &end );
int cursor_pos = insert_position();
printf("mytexteditor2::handle() - te push: %d, %d, %d\n", start, end, cursor_pos );
//mouse clicked, extract a rom address
unsigned int addr;
if( buffer()->length() > 0 )
{
char cc = buffer()->char_at( cursor_pos );
if( cc <= ' ' ) goto skip_num_extraction; //rule out as a possible number
if( cc == '\t' ) goto skip_num_extraction;
if( cc > 0x7f ) goto skip_num_extraction;
int ii = 0;
for( ii = cursor_pos; ii >= 0; ii-- )
{
cc = buffer()->char_at( ii );
if( cc == 'a' ) continue;
if( cc == 'A' ) continue;
if( cc == 'b' ) continue;
if( cc == 'B' ) continue;
if( cc == 'c' ) continue;
if( cc == 'C' ) continue;
if( cc == 'd' ) continue;
if( cc == 'D' ) continue;
if( cc == 'e' ) continue;
if( cc == 'E' ) continue;
if( cc == 'f' ) continue;
if( cc == 'F' ) continue;
if( ( cc >= '0' ) & ( cc <= '9' ) ) continue;
break;
}
ii += 1;
if( ii >= buffer()->length() ) ii = buffer()->length() - 1;
if( ii < 0 ) ii = 0;
wstart = ii;
wend = wstart + 1;
for( ii = cursor_pos; ii < buffer()->length(); ii++ )
{
cc = buffer()->char_at( ii );
// if( cc == '-' ) continue;
// if( cc == '+' ) continue;
// if( cc == '.' ) continue;
if( cc == 'a' ) continue;
if( cc == 'A' ) continue;
if( cc == 'b' ) continue;
if( cc == 'B' ) continue;
if( cc == 'c' ) continue;
if( cc == 'C' ) continue;
if( cc == 'd' ) continue;
if( cc == 'D' ) continue;
if( cc == 'e' ) continue;
if( cc == 'E' ) continue;
if( cc == 'f' ) continue;
if( cc == 'F' ) continue;
if( ( cc >= '0' ) & ( cc <= '9' ) ) continue;
break;
}
wend = ii;
printf("mytexteditor2::handle() - ws: %d, %d\n", wstart, wend );
// buffer()->highlight( wstart, wend );
buffer()->select( wstart, wend );
s1 = buffer()->selection_text();
s_addr = s1;
printf("mytexteditor2::handle() - str: '%s'\n", s1.c_str() );
sscanf( s1.c_str(), "%x", &addr );
printf("mytexteditor2::handle() - addr: %x\n", addr );
}
if( ( wstart ) || ( wend ) )
{
buffer()->select( wstart, wend );
s1 = buffer()->selection_text();
printf("mytexteditor2::handle() - num: '%s', num: %04x\n", s1.c_str(), addr );
printf("mytexteditor2::handle() - vaddr_hist.size() %d, addr %04x\n", vaddr_hist.size(), addr );
addr_add_history( addr );
talk.say_tmc0580( vsm, addr );
if( id0 == 1 ) //NOTE!!!!!!: id0 is set in fluid's gui, see eg: 'tb_wordlist = new Fl_Text_Buffer;' which is defined in fluid
{
fi_romaddr->value( s_addr.c_str() );
}
need_redraw = 0;
dont_pass_on = 1;
}
skip_num_extraction:
int ii = 123; //dummy
}
// need_redraw = 1;
// dont_pass_on = 1; //note base function already called above
}
if ( e == FL_RELEASE )
{
if( Fl::event_button() == 1 )
{
left_button = 0;
}
need_redraw = 1;
dont_pass_on = 1;
}
if ( need_redraw ) redraw();
if( dont_pass_on ) return 1;
return Fl_Text_Editor::handle(e);
}
//----------------------------------------------------------
//console printf(...) like function
//e.g. cslpf( "\nTesing int=%05d, float=%f str=%s\n",z,(float)4.567,"I was Here" );
string sdebug; //holds all cslpf output
void cslpf( const char *fmt,... )
{
string s1;
int buf_size = 10 * 1024 * 1024;
char* buf = new char[ buf_size ]; //create a data buffer
if( buf == 0 )
{
printf("cslpf() - no memory allocated!!!!!!!!!!!!!!!!!!!!!!!\n");
return;
}
string s;
va_list ap;
va_start( ap, fmt );
vsnprintf( buf, buf_size - 1, fmt, ap );
if( 1 )
{
printf( buf );
}
//prevent string growing anywhere near 'max_size()' and causing a std::__throw_length_error(char const*)
unsigned int len = sdebug.length();
unsigned int max = sdebug.max_size();
unsigned int limit = (double)max / 1.25;
//printf("cslpf() - culling %d\n", (int)limit );
if( len > limit )
{
s1 = sdebug.substr( max - limit, len - ( max - limit ) ); //cut off begining section of str
sdebug = s1;
printf("cslpf() - culling begining of str to avoid hitting string::max_size()\n");
}
sdebug += buf; //for diag
va_end(ap);
delete buf;
}
void set_new_srate( int sr )
{
if( (sr >= 2000 )&( sr <= 192000) ) srate = sr;
}
void set_new_srate_au( int sr )
{
if( (sr >= 2000 )&( sr <= 192000) ) srate_au = sr;
}
void stop_play()
{
mode = 0;
}
//returns 1 if addr still valid, else 0
bool modify_addr( int dir )
{
int ii;
bool ret = 1;
string s1 = fi_romaddr->value();
sscanf( s1.c_str(), "%x", &ii );
ii += dir;
if( ii < 0 )
{
ii = 0;
ret = 0;
}
if( ii >= rom_size_max )
{
ii = rom_size_max - 1;
ret = 0;
}
strpf( s1, "%04x", ii );
fi_romaddr->value( s1.c_str() );
last_say_offset = ii;
return ret;
}
//----------------------------------------------------------------------------------
//this is the callback that is called by buttons that specified is in -
//definition ....pref_wnd->sc.cb=(void*)cb_user;
//'*o' is the PrefWnd* ptr
//'row' is the row the control lives on, 0 is first row
//'ctrl' is the number of the controlon that row, 0 is first control
void cb_user1(void *o, int row,int ctrl)
{
PrefWnd *w = (PrefWnd *) o;
unsigned int id = w->ctrl_list[ row ][ ctrl ].uniq_id; //get user id for controll making this call
/*
if( id == 9 ) //first led control?
{
val[ 0 ][ 5 ]++;
if( val[ 0 ][ 5 ] >=3 ) val[ 0 ][ 5 ] = 0; //cycle led states
GCLed *o = (GCLed *)w->ctrl_ptrs[ row ][ ctrl ];
o->ChangeCol( val[ 0 ][ 5 ] ); //change led state
}
*/
printf("\ncb_user1() - Ping by Control on Row=%d at control count Ctrl=%d on this row, uniq_id: %d\n", row, ctrl, id );
}
void cb_pref_use_jack( void *o, int row, int ctrl )
{
PrefWnd *w = (PrefWnd *) o;
string s1;
unsigned int id = w->ctrl_list[ row ][ ctrl ].uniq_id; //get user id for controll making this call
if( id == 1 )
{
printf("pref_use_jack: %d\n", pref_use_jack );
if( b_use_jack == pref_use_jack )
{
if( !b_use_jack ) strpf( s1, "Already using alsa, nothing will be changed." );
else strpf( s1, "Already using jack, nothing will be changed." );
fl_alert( s1.c_str(), 0 );
return;
}
if( !pref_use_jack ) strpf( s1, "Will switch to alsa on restart of this app, you need to be sure system has alsa available." );
else strpf( s1, "Will switch to jack on restart of this app, you need to be sure system has jack available." );
fl_alert( s1.c_str(), 0 );
return;
}
}
void make_pref_wnd()
{
sControl sc;
if(pref_wnd==0)
{
pref_wnd = new PrefWnd(wndMain->x()+20,wndMain->y()+20,730,330,"Preferences","Settings","PrefWndPos");
}
else{
pref_wnd->Show(1);
return;
}
pref_wnd->ClearToDefCtrl(); //this will clear sc struct to safe default values
pref_wnd->sc.type=cnStaticTextPref;
pref_wnd->sc.x=200;
pref_wnd->sc.y=0;
pref_wnd->sc.w=150;
pref_wnd->sc.h=20;
pref_wnd->sc.label="Nothing added here as yet";
pref_wnd->sc.label_type = FL_NORMAL_LABEL; //label effects such a FL_EMBOSSED_LABEL, FL_ENGRAVED_LABEL, FL_SHADOW_LABEL
pref_wnd->sc.label_align = FL_ALIGN_LEFT;
pref_wnd->sc.tooltip=""; //tool tip
pref_wnd->sc.options=""; //menu button drop down options
pref_wnd->sc.labelfont=-1; //-1 means use fltk default
pref_wnd->sc.labelsize=-1; //-1 means use fltk default
pref_wnd->sc.textfont=-1;//fl_font();
pref_wnd->sc.textsize=-1;//fl_size();
pref_wnd->sc.section="Settings";
pref_wnd->sc.key="pref_static_text_dummy";
pref_wnd->sc.keypostfix=-1; //ini file Key post fix
pref_wnd->sc.def="0"; //default to use if ini value not avail
pref_wnd->sc.iretval=(int*)-1; //address of int to be modified, -1 means none
pref_wnd->sc.dretval=(double*)-1; //address of double to be modified, -1 means none
pref_wnd->sc.sretval=(string*)-1; //address of string to be modified, -1 means none
pref_wnd->sc.cb = cb_user1; //address of a callback if any, 0 means none
pref_wnd->sc.dynamic = 0; //allow immediate dynamic change of user var
pref_wnd->sc.uniq_id = 0; //allows identification of an actual control, rather that using its row and column values, don't use 0xffffffff
pref_wnd->AddControl();
pref_wnd->CreateRow(25); //specify optional row height
/*
pref_wnd->ClearToDefCtrl(); //this will clear sc struct to safe default values
pref_wnd->sc.type=cnMenuChoicePref;
pref_wnd->sc.x=140;
pref_wnd->sc.y=0;
pref_wnd->sc.w=150;
pref_wnd->sc.h=20;
pref_wnd->sc.label="Initial Execution:";
pref_wnd->sc.label_type = FL_NORMAL_LABEL; //label effects such a FL_EMBOSSED_LABEL, FL_ENGRAVED_LABEL, FL_SHADOW_LABEL
pref_wnd->sc.label_align = FL_ALIGN_LEFT;
pref_wnd->sc.tooltip=""; //tool tip
pref_wnd->sc.options="&None,&Step into main(...),&Run"; //menu button drop down options
pref_wnd->sc.labelfont=-1; //-1 means use fltk default
pref_wnd->sc.labelsize=-1; //-1 means use fltk default
pref_wnd->sc.textfont=-1;//fl_font();
pref_wnd->sc.textsize=-1;//fl_size();
pref_wnd->sc.section="Settings";
pref_wnd->sc.key="InitExec";