@@ -18,14 +18,32 @@ ast.body.forEach(node => {
1818 method . type === 'MethodDefinition' &&
1919 included_methods . includes ( method . key . name )
2020 ) {
21- const methodStart = method . start ;
22- const methodEnd = method . end ;
23- let methodCode = facetPatternContent . slice ( methodStart , methodEnd ) ;
21+ let methodCode ;
2422
25- // replace instances of this.getWholeNoteNumSamples() with SAMPLE_RATE
26- methodCode = methodCode . replace ( / t h i s \. g e t W h o l e N o t e N u m S a m p l e s \( \) / g, 'SAMPLE_RATE' ) ;
27- // replace instances of Scale.get with Tonal.Scale.get
28- methodCode = methodCode . replace ( / \b S c a l e \. g e t \b / g, 'Tonal.Scale.get' ) ;
23+ // special handling for sample() method which is different in wax
24+ if ( method . key . name === 'sample' ) {
25+ methodCode = `sample(name) {
26+ if (!name.endsWith('.wav')) {
27+ name += '.wav';
28+ }
29+ let audioBuffer = audioBuffers[name];
30+ if (audioBuffer) {
31+ this.data = audioBuffer;
32+ } else {
33+ throw \`No buffer found with the name \${name}\`;
34+ }
35+ return this;
36+ }` ;
37+ } else {
38+ const methodStart = method . start ;
39+ const methodEnd = method . end ;
40+ methodCode = facetPatternContent . slice ( methodStart , methodEnd ) ;
41+
42+ // replace instances of this.getWholeNoteNumSamples() with SAMPLE_RATE
43+ methodCode = methodCode . replace ( / t h i s \. g e t W h o l e N o t e N u m S a m p l e s \( \) / g, 'SAMPLE_RATE' ) ;
44+ // replace instances of Scale.get with Tonal.Scale.get
45+ methodCode = methodCode . replace ( / \b S c a l e \. g e t \b / g, 'Tonal.Scale.get' ) ;
46+ }
2947
3048 extractedMethods . push ( methodCode ) ;
3149 }
0 commit comments