@@ -164,15 +164,28 @@ function generateMidi() {
164164 return notes ;
165165}
166166
167+ function getTrackPath ( ) {
168+ var path = "this_device canonical_parent" ;
169+ var parent = new LiveAPI ( path ) ;
170+
171+ while ( parent . type !== "Track" ) {
172+ path = path + " canonical_parent" ;
173+ parent = new LiveAPI ( path ) ;
174+ }
175+
176+ return path ;
177+ }
178+
167179function clip ( ) {
168- var track = new LiveAPI ( "this_device canonical_parent" ) ;
180+ var trackPath = getTrackPath ( ) ;
181+ var track = new LiveAPI ( trackPath ) ;
169182 var clipSlots = track . getcount ( "clip_slots" ) ;
170183 var clipSlot ;
171184
172185 var firstClip = null ;
173186
174187 for ( var clipSlotNum = 0 ; clipSlotNum < clipSlots ; clipSlotNum ++ ) {
175- clipSlot = new LiveAPI ( "this_device canonical_parent clip_slots " + clipSlotNum ) ;
188+ clipSlot = new LiveAPI ( trackPath + " clip_slots " + clipSlotNum ) ;
176189 var hasClip = clipSlot . get ( "has_clip" ) . toString ( ) !== "0" ;
177190 if ( ! hasClip ) break ;
178191 }
@@ -181,12 +194,12 @@ function clip() {
181194 // have to create new clip slot (scene)
182195 var set = new LiveAPI ( "live_set" ) ;
183196 set . call ( "create_scene" , - 1 ) ;
184- clipSlot = new LiveAPI ( "this_device canonical_parent clip_slots " + clipSlotNum ) ;
197+ clipSlot = new LiveAPI ( trackPath + " clip_slots " + clipSlotNum ) ;
185198 }
186199
187200 var beats = Math . ceil ( patternLength / 4 ) ;
188201 clipSlot . call ( "create_clip" , beats ) ;
189- var clip = new LiveAPI ( "this_device canonical_parent clip_slots " + clipSlotNum + " clip" ) ;
202+ var clip = new LiveAPI ( trackPath + " clip_slots " + clipSlotNum + " clip" ) ;
190203 var notes = generateMidi ( ) ;
191204
192205 setNotes ( clip , notes ) ;
0 commit comments