@@ -111,6 +111,7 @@ function updateFlatJsonNotes(flatJson, newMeasures) {
111111 note [ "rest" ] = { } ;
112112 note [ "voice" ] = "1" ;
113113 note [ "staff" ] = "1" ;
114+ // Duration is number, type is word
114115 note [ "duration" ] = durationMapping [ newNoteData . duration ] ;
115116 note [ "$adagio-location" ] = {
116117 "timePos" : 0
@@ -122,7 +123,8 @@ function updateFlatJsonNotes(flatJson, newMeasures) {
122123 octave : newNoteData . octave ,
123124 step : newNoteData . step
124125 } ;
125- note [ "duration" ] = newNoteData . duration ;
126+ // Duration is number, type is word
127+ note [ "duration" ] = durationMapping [ newNoteData . duration ] ;
126128 note [ "voice" ] = "1" ;
127129 note [ "staff" ] = "1" ;
128130 note [ "$adagio-location" ] = {
@@ -138,4 +140,29 @@ function updateFlatJsonNotes(flatJson, newMeasures) {
138140 return updatedFlatJson ;
139141}
140142
141- export { generateBlocklyJson , convertFlatJsonToMeasures , updateFlatJsonNotes } ;
143+ function parseBlocklyJSON ( blocklyJSON ) {
144+ const measures = [ ] ;
145+
146+ let currentBlock = blocklyJSON . blocks . blocks [ 0 ] ; // Start from the first measure
147+
148+ while ( currentBlock ) {
149+ if ( currentBlock . type === "measure" && currentBlock . inputs && currentBlock . inputs . NOTES ) {
150+ const noteBlock = currentBlock . inputs . NOTES . block ;
151+ if ( noteBlock && noteBlock . type === "play_sound" ) {
152+ measures . push ( [
153+ {
154+ "duration" : noteBlock . fields . DURATION ,
155+ "step" : noteBlock . fields . STEP ,
156+ "octave" : noteBlock . fields . OCTAVE
157+ }
158+ ] ) ;
159+ }
160+ }
161+ currentBlock = currentBlock . next ? currentBlock . next . block : null ;
162+ }
163+
164+ return measures ;
165+ }
166+
167+
168+ export { generateBlocklyJson , convertFlatJsonToMeasures , updateFlatJsonNotes , parseBlocklyJSON } ;
0 commit comments