-
Notifications
You must be signed in to change notification settings - Fork 3
/
DTW.Java
1926 lines (1355 loc) · 57.3 KB
/
DTW.Java
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
public
class DTW {
private
double[] horizontalInput;
private
double[] verticalInput;
public
DTW(double[] horizontalInput, double[] verticalInput) {
this.horizontalInput = horizontalInput;
this.verticalInput = verticalInput;
}
/*
Finds the minimum cost path to reach current value
*/
private
static double min(MatrixTriplet matrixTriplet) {
return Math.min(Math.min(matrixTriplet.left, matrixTriplet.bottom),
matrixTriplet.bottomLeft);
}
/*
This finds the squared difference of the matrix points
Generates a 2D array and returns the symmetrical distance measure
*/
private
double[][] buildDistanceMatrix() {
int rows = verticalInput.length;
int cols = horizontalInput.length;
double[][] matrix = new double[rows + 1][cols + 1];
for (int i = 1; i < matrix[0].length; ++i) {
matrix[0][i] = horizontalInput[i - 1];
}
for (int i = 1; i < matrix.length; ++i) {
matrix[i][0] = verticalInput[i - 1];
}
for (int row = 1; row <= rows; ++row) {
for (int col = 1; col <= cols; ++col) {
matrix[row][col] = (int)Math.pow(matrix[0][col] - matrix[row][0], 2);
}
}
return matrix;
}
/*
Finds the left and bottom initial cost values. Initialization phase
*/
private
static MatrixTriplet[][] buildTripleMatrixWithLeftAndBottomValues(
double[][] distanceMatrix) {
int rows = distanceMatrix.length;
int cols = distanceMatrix[0].length;
MatrixTriplet[][] leftAndBottomMatrix = new MatrixTriplet[rows][cols];
for (int row = 0; row < rows; ++row) {
for (int col = 0; col < cols; ++col) {
leftAndBottomMatrix[row][col] =
new MatrixTriplet(distanceMatrix[row][col]);
}
}
leftAndBottomMatrix[1][1].left = distanceMatrix[1][1];
for (int col = 2; col < cols; ++col) {
leftAndBottomMatrix[1][col].left = leftAndBottomMatrix[1][col - 1].left
+ distanceMatrix[1][col];
leftAndBottomMatrix[1][col].bottom = leftAndBottomMatrix[1][col].left;
}
leftAndBottomMatrix[1][1].bottom = distanceMatrix[1][1];
for (int row = 2; row < rows; ++row) {
leftAndBottomMatrix[row][1].bottom =
leftAndBottomMatrix[row - 1][1].bottom
+ distanceMatrix[row][1];
leftAndBottomMatrix[row][1].left = leftAndBottomMatrix[row][1].bottom;
}
return leftAndBottomMatrix;
}
/*
Finds the left/bottom/bottomleft cost values
*/
private
static MatrixTriplet[][] buildFinalMatrix(
MatrixTriplet[][] leftAndBottomMatrix) {
int rows = leftAndBottomMatrix.length;
int cols = leftAndBottomMatrix.length;
MatrixTriplet[][] finalMatrix = new MatrixTriplet[rows][cols];
for (int row = 0; row < rows; ++row) {
for (int col = 0; col < cols; ++col) {
finalMatrix[row][col] = new
MatrixTriplet(leftAndBottomMatrix[row][col].initial,
leftAndBottomMatrix[row][col].left,
leftAndBottomMatrix[row][col].bottom,
leftAndBottomMatrix[row][col].bottomLeft);
}
}
for (int row = 2; row < rows; ++row) {
for (int col = 2; col < cols; ++col) {
finalMatrix[row][col].left = min(finalMatrix[row][col - 1])
+ finalMatrix[row][col].initial;
finalMatrix[row][col].bottom = min(finalMatrix[row - 1][col])
+ finalMatrix[row][col].initial;
finalMatrix[row][col].bottomLeft = min(finalMatrix[row - 1][col - 1])
+ finalMatrix[row][col].initial;
}
}
return finalMatrix;
}
private
double compute() {
double[][] distanceMatrix = buildDistanceMatrix();
MatrixTriplet[][] leftAndBottomValuesTripletMatrix =
buildTripleMatrixWithLeftAndBottomValues(distanceMatrix);
MatrixTriplet[][] finalMatrix =
buildFinalMatrix(leftAndBottomValuesTripletMatrix);
return min(finalMatrix[verticalInput.length][horizontalInput.length]);
}
private
static class MatrixTriplet {
double initial = Double.POSITIVE_INFINITY;
double left = Double.POSITIVE_INFINITY;
double bottom = Double.POSITIVE_INFINITY;
double bottomLeft = Double.POSITIVE_INFINITY;
MatrixTriplet(double initial, double left, double bottom,
double bottomLeft) {
this.initial = initial;
this.left = left;
this.bottom = bottom;
this.bottomLeft = bottomLeft;
}
MatrixTriplet(double initial) { this.initial = initial; }
}
public static void
main(String[] args) {
// double [] horizontalInput1 = {1.0, 1.0, 2.0, 3.0, 2.0, 0.0};
// double [] verticalInput1 = {0.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0};
// DTW similarInputs = new DTW(horizontalInput1, verticalInput1);
// double result = similarInputs.compute();
double[] horizontalInput2 = {0.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0};
double[] verticalInput2 = {0.0, 1.0, 1.0, 2.0, 3.0, 2.0, 1.0};
DTW sameInputs = new DTW(horizontalInput2, verticalInput2);
double result2 = sameInputs.compute();
System.out.println("Least cost path of Test 1: " + result2);
double[] horizontalInput3 = {1.0, 1.0, 2.0, 3.0, 2.0, 0.0};
double[] verticalInput3 = {0.0, 0.0, 1.0, 2.0, 1.0, -1.0};
DTW sameInputsOutPhase = new DTW(horizontalInput3, verticalInput3);
double result3 = sameInputsOutPhase.compute();
System.out.println("Least cost path of Test 2: " + result3);
// double [] horizontalInput4 = {1.0, 2.0, 3.0, 4.0, 2.0, 1.0};
// double [] verticalInput4 = {5.0, 0.0, 1.0, 4.0, 2.0, 0.0, 3.0};
// DTW differentInputs = new DTW(horizontalInput4, verticalInput4);
// double result4 = differentInputs.compute();
// System.out.println("Least cost path of Test 4: " + result4);
}
}
Dynamic Time Warping PD Object C code :
#include "m_pd.h"
#include < math.h >
#include < stdio.h >
#include < stdlib.h >
#include < stdio.h >
#include < time.h >
#include < windows.h >
#define SIZE_ARRAY 300
#define TEST_SIZE 300
static t_class *dynamicTW_class; // handle for the class
float recording_array[SIZE_ARRAY] = {0};
int arr_position = SIZE_ARRAY - 1;
float saveValue = 0.0;
int triggerGlobal = 0;
float delayTime = 0.0;
/* struct to hold cost of arrival from left, bottom, and diagonal */
typedef struct _leftbottom {
float left;
float bottom;
float diag;
} leftBD; // typedef name
typedef struct _dynamicTW {
t_object x_obj;
int flag; // differentiates if how result of lcp is stored
int match; // if 0 signal does not match else matches
float testArray[TEST_SIZE];
float storedSignalOne[SIZE_ARRAY];
float storedSignalTwo[SIZE_ARRAY];
t_inlet *in_mod_A, *in_mod_B;
t_outlet *out_A;
float signal[SIZE_ARRAY];
float lcpValue;
float compareValue;
float initMatrix[SIZE_ARRAY][SIZE_ARRAY];
leftBD costValues[SIZE_ARRAY - 1][SIZE_ARRAY - 1];
} t_dynamicTW; // typedef name
void checkStorage(t_dynamicTW *x) { // check if values being stored correctly
int i;
post("in check storage");
for (i = 0; i < TEST_SIZE; i++) {
post("Signal 1: %f", x - > storedSignalOne[i]);
post("Signal 2: %f", x - > storedSignalTwo[i]);
}
}
void signalMatch(t_dynamicTW *x) {
float tenup = saveValue + (.05 * saveValue);
float zeroValue = 0.00;
FILE *fp1;
FILE *fp2;
FILE *fp3;
int j;
if (x - > compareValue <= tenup && x - > compareValue >= zeroValue) {
Sleep(delayTime * 1000); // how long to delay bang in seconds;
outlet_bang(x - > out_A);
x - > match = 1;
/* add code to trigger effect */
post("Incoming Signal Matches Stored Signal. compareValue is %f and "
"lcpValue is %f",
x - > compareValue, saveValue);
post("delay time: %f", delayTime);
fp1 = fopen("C:\\Users\\Raki\\Documents\\GitHub\\dynamicTW\\TB\\save1.txt",
"w");
fp2 = fopen("C:\\Users\\Raki\\Documents\\GitHub\\dynamicTW\\TB\\save2.txt",
"w");
fp3 = fopen("C:\\Users\\Raki\\Documents\\GitHub\\dynamicTW\\TB\\save3.txt",
"w");
post("saving");
for (j = 0; j < SIZE_ARRAY; j++) {
fprintf(fp1, "%f\n", x - > storedSignalOne[j]);
fprintf(fp2, "%f\n", x - > storedSignalTwo[j]);
fprintf(fp3, "%f\n", x - > initMatrix[0][j]);
}
post("finish saving");
fclose(fp1);
fclose(fp2);
fclose(fp3);
}
else {
x - > match = 0;
post("Signal NO Match. compareVal is %f while lcpVal is %f\n",
x - > compareValue, saveValue);
}
}
float findMin(t_dynamicTW *x, int row, int column) {
float temp, min;
float checkLeft = x - > costValues[row][column].left;
float checkBottom = x - > costValues[row][column].bottom;
float checkDiagonal = x - > costValues[row][column].diag;
temp = (checkLeft < checkBottom) ? checkLeft : checkBottom;
min = (checkDiagonal < temp) ? checkDiagonal : temp;
return min;
}
void reverseArray(t_dynamicTW *x) {
int i, j;
i = SIZE_ARRAY - 1;
j = 0;
while (i > j) {
float temp = x - > storedSignalTwo[i];
x - > storedSignalTwo[i] = x - > storedSignalTwo[j];
x - > storedSignalTwo[j] = temp;
i--;
j++;
}
}
void fileReader1(t_dynamicTW *x, char *path) {
// char const* const fileName =
// "C:\\Users\\Raki\\Documents\\GitHub\\dynamicTW\\TB\\input.txt" ;/* should
// check that argc > 1 */
FILE *file = fopen(path, "r");
/* should check the result */
char line[256];
int i = 0;
while (fgets(line, sizeof(line), file)) {
// post("file1: value at line %d is %s", i, line);
x - > storedSignalOne[i] = atof(line); // !!!!!!!!!!!!!!!!!!!!! REMOVE 1000
i++;
}
fclose(file);
}
void fileReader2(t_dynamicTW *x, char *path) {
// char const* const fileName =
// "C:\\Users\\Raki\\Documents\\GitHub\\dynamicTW\\TB\\input.txt" ;/* should
// check that argc > 1 */
FILE *file = fopen(path, "r");
/* should check the result */
char line[256];
int i = 0;
while (fgets(line, sizeof(line), file)) {
// post("file2: value at line %d is %s", i, line);
x - > storedSignalTwo[i] =
atof(line); // !!!!!!!!!!!!!!!!!!!!!!!!!!! REMOVE 1000
i++;
}
fclose(file);
}
void replaceSignal2(t_dynamicTW *x) {
int i;
for (i = 0; i < SIZE_ARRAY; i++) {
x - > storedSignalTwo[i] = x - > signal[i];
}
}
/*
1. Create a 2d array for our matrix
2. fill in the left column and bottom row with our 2 signals
3. Populate the rest of the matrix
4. calculate least cost path
*/
void leastCostPath(t_dynamicTW *x) {
float temp, min;
float result = 0;
int i = SIZE_ARRAY - 2;
int j = SIZE_ARRAY - 2;
// post("starting point value left is %f", x->costValues[i][j].left);
// post("starting point value bottom is %f", x->costValues[i][j].bottom);
// post("starting point value diag is %f", x->costValues[i][j].diag);
while (i >= 0 && j >= 0) {
float checkLeft = x - > costValues[i][j].left;
float checkBottom = x - > costValues[i][j].bottom;
float checkDiagonal = x - > costValues[i][j].diag;
temp = (checkLeft < checkBottom) ? checkLeft : checkBottom;
min = (checkDiagonal < temp) ? checkDiagonal : temp;
result += min;
/* Changes cell location after finding min */
if (min == checkDiagonal) {
if (i - 1 < 0 && j - 1 < 0) {
break;
}
else if (i - 1 < 0) {
j--;
}
else if (j - 1 < 0) {
i--;
}
else {
i--;
j--;
}
}
else if (min == checkLeft) {
if (j - 1 < 0) {
break;
}
else {
j--;
}
}
else {
if (i - 1 < 0) {
break;
}
else {
i--;
}
}
}
if (x - > flag == 0) {
saveValue += result;
post("storing to saveValue: current saveValue is %f", saveValue);
}
else if (x - > flag == 1) {
x - > compareValue = result;
post("compareValue: least cost path is %f", x - > compareValue);
}
}
void dtw_genMatrix(t_dynamicTW *x) {
int i;
for (i = 0; i < SIZE_ARRAY; i++) {
x - > initMatrix[i][0] =
x - > storedSignalOne[i]; // populate the first column with signal 1
// data points
x - > initMatrix[0][i] =
x - >
storedSignalTwo[i]; // populate the last row with signal 2 data points
}
/* Calculates the Symmetrical distance for each matrix cell */
int z, y;
for (z = 1; z < SIZE_ARRAY; z++) {
for (y = 1; y < SIZE_ARRAY; y++) {
float difference = x - > storedSignalOne[z] - x - > storedSignalTwo[y];
x - > initMatrix[z][y] =
(float)pow(difference, 2); // finding the symmetrical distance
}
}
// initializing the costValues matrix
int ci, cj;
for (ci = 0; ci < SIZE_ARRAY - 1; ci++) {
for (cj = 0; cj < SIZE_ARRAY - 1; cj++) {
x - > costValues[ci][cj].left = 0;
x - > costValues[ci][cj].bottom = 0;
x - > costValues[ci][cj].diag = 0;
}
}
/* Calculates the cost of arrival from left, bottom, and diagonal */
int q, r;
for (q = 0; q < SIZE_ARRAY - 1; q++) {
for (r = 0; r < SIZE_ARRAY - 1; r++) {
// no left, bottom, or diagonal values //========READ
// ME!!!!!==============change to init matrix + 1?
if (q == 0 && r == 0) {
x - > costValues[q][r].left = x - > initMatrix[q + 1][r + 1];
x - > costValues[q][r].bottom = x - > initMatrix[q + 1][r + 1];
x - > costValues[q][r].diag = x - > initMatrix[q + 1][r + 1];
}
// if row is bottom there cant be any bottom values or diagonal so set
// left values only
else if (q == 0) {
if (r == 0) { //======READ | change to init matrix + 1 again
x - > costValues[q][r].left =
x - > initMatrix[q + 1][r + 1]; // no possible left values
}
else {
x - > costValues[q][r].left =
x - >
initMatrix[q + 1][r + 1] +
findMin(
x, q,
(r - 1)); //=========change to cost of current cell init
//matrix + min of cost values of left cell
}
x - > costValues[q][r].bottom = 1000 * 1000;
x - > costValues[q][r].diag = 1000 * 1000;
}
// if column is left there cant be any left values or diagonal so set
// bottom values only
else if (r == 0) {
if (q == 0) {
x - > costValues[q][r].bottom =
x - >
initMatrix[q + 1]
[r + 1]; //======READ | change to init matrix + 1 again
}
else {
x - > costValues[q][r].bottom =
x - >
initMatrix[q + 1][r + 1] +
findMin(x, (q - 1),
r); //=========change to cost of current cell init
//matrix + min of cost values of left cell
}
x - > costValues[q][r].left = 1000 * 1000;
x - > costValues[q][r].diag = 1000 * 1000;
}
// must have left, bottom, and diagonal values
else {
x - > costValues[q][r].left =
x - >
initMatrix[q + 1][r + 1] +
findMin(x, q, (r - 1)); // do current initMatrix value + min
x - > costValues[q][r].bottom =
x - > initMatrix[q + 1][r + 1] + findMin(x, (q - 1), r);
x - > costValues[q][r].diag =
(.5 * x - > initMatrix[q + 1][r + 1]) +
findMin(x, (q - 1),
(r - 1)); // diagonal movement needs to be favored
}
}
}
// int qq, rr;
// for(qq = 0; qq<SIZE_ARRAY-1; qq++){
// for(rr= 0; rr<SIZE_ARRAY-1; rr++){
// post("index q:%d and r:%d", qq, rr);
// post("left: %f", x->costValues[qq][rr].left);
// post("bottom: %f", x->costValues[qq][rr].bottom);
// post("bottomLeft: %f\n", x->costValues[qq][rr].diag);
// }
// }
leastCostPath(x); // finds least cost path
}
/* Function for when a bang is received
* - Calculates the least cost path between input 1 and againts the other 3
signals
* - It is then averaged together and changes the flag value */
void dtw_onBangMsg(t_dynamicTW *x) {
x - > match = 0;
x - > flag = 0; // makes so that lcp value gets stored in lcpValue
saveValue = 0.0;
arr_position = SIZE_ARRAY - 1;
fileReader1(
x, "C:\\Users\\Raki\\Documents\\GitHub\\dynamicTW\\TB\\input1.txt"); // read
// signal
// 1
fileReader2(
x, "C:\\Users\\Raki\\Documents\\GitHub\\dynamicTW\\TB\\input2.txt"); // read
// signal
// 2
dtw_genMatrix(x); // perform DTW
fileReader2(x,
"C:\\Users\\Raki\\Documents\\GitHub\\dynamicTW\\TB\\input3.txt");
dtw_genMatrix(x);
fileReader2(x,
"C:\\Users\\Raki\\Documents\\GitHub\\dynamicTW\\TB\\input4.txt");
dtw_genMatrix(x);
saveValue = saveValue / 3;
post("saveValue: Least Cost Path is %f", saveValue);
triggerGlobal = 1;
}
void dtw_free(t_dynamicTW *x) {
inlet_free(x - > in_mod_A);
inlet_free(x - > in_mod_B);
outlet_free(x - > out_A);
}
void dtw_onSet_A(t_dynamicTW *x, t_floatarg f) {
/*function that gets called when an input is received */
clock_t t;
if (triggerGlobal == 0) {
/*do nothing*/
}
// Sleep(2);
post("Number A: %f sending to array. Arr_position is %d", f, arr_position);
post("Delay Time: %f", delayTime);
if (x - > match == 1) {
post("Match has been detected. Freezing Program!");
}
else if (x - > match == 0) {
if (arr_position >= 0) { // checks if array is filled. If not then store
// incoming value to next index
x - > signal[arr_position] = f;
arr_position--;
}
else { // If array is filled shift all values by 1 index and store at
// beginning of array
t = clock();
int i;
x - > flag = 1; // makes it so that LCP result is stored in compared
// Value;
for (i = SIZE_ARRAY - 1; i > 0; i--) {
x - > signal[i] = x - > signal[i - 1];
}
x - > signal[0] = f;
replaceSignal2(x); // replaces the value in signal 2
reverseArray(x);
dtw_genMatrix(x); // performs dtw
t = clock() - t;
double time_taken = ((double)t) / CLOCKS_PER_SEC; // in seconds
post("DTW took %f seconds to execute", time_taken);
signalMatch(x); // checks is the signal is correct if it is trigger effect
// if(time_taken == .002){
// Sleep(8);
// }
// else if (time_taken == .001){
// Sleep(9);
// }
}
}
}
void dtw_onSet_B(t_dynamicTW *x, t_floatarg f) { delayTime = f; }
// initializer for the class
void *dynamicTW_new(t_floatarg f1,
t_floatarg f2) { // parenth contains creation arg. temp
// stuff will replaced with arrays
t_dynamicTW *x =
(t_dynamicTW *)pd_new(dynamicTW_class); // initialize struct of type dtw
x - > in_mod_A =
inlet_new(&x - > x_obj, &x - > x_obj.ob_pd, &s_float, gensym("ratio_A"));
x - > in_mod_B =
inlet_new(&x - > x_obj, &x - > x_obj.ob_pd, &s_float, gensym("ratio_B"));
x - > out_A = outlet_new(&x - > x_obj, &s_bang);
return (void *)x;
}
// function to set up the class and call initializer
void dynamicTW_setup(void) {
/*class_new(t_symbol *name, t_newmethod newmethod,
t_method freemethod, size_t size, int flags, t_atomtype arg1, ...); */
dynamicTW_class =
class_new(gensym("dynamicTW"), // defines the symbol in puredata
(t_newmethod)dynamicTW_new, // inializing method
(t_method)dtw_free,
sizeof(t_dynamicTW),
CLASS_DEFAULT, // makes the box
A_DEFFLOAT,
A_DEFFLOAT,
0);
class_addbang(dynamicTW_class, (t_method)dtw_onBangMsg);
class_addmethod(dynamicTW_class,
(t_method)dtw_onSet_A,
gensym("ratio_A"),
A_DEFFLOAT,
0);
class_addmethod(dynamicTW_class,
(t_method)dtw_onSet_B,
gensym("ratio_B"),