Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo code stale? 'sustain' is not an object, not an array #73

Closed
drone1 opened this issue May 21, 2019 · 7 comments
Closed

Demo code stale? 'sustain' is not an object, not an array #73

drone1 opened this issue May 21, 2019 · 7 comments

Comments

@drone1
Copy link

drone1 commented May 21, 2019

Hello and thanks for the cool project.

I'm parsing this file: https://www.dropbox.com/s/hecoqfrjok5fsjs/KICK1.mid?dl=1

Exported from Ableton 10 via "Export to MIDI file..." or whatever.

It's simple MIDI for a kick drum, all running on a single note w/ velocity changes, but nothing else, I believe.

In your demo code, you've got something like this:

	  //they are also aliased to the CC number's common name (if it has one)
	  track.controlChanges.sustain.forEach(cc => {
	    // cc.ticks, cc.value, cc.time
	  })

But for me, track.controlChanges.sustain is an object (empty, or {}), and not iterable via forEach().

I'm guessing the sample code is simply out of date, but you can inspect the MIDI file I've provided if you want, or feel free to let me know if I can provide more info.

track.notes is an array and forEach() works fine. I can print note data without issue.

Full code:

	const fullPath = ...
	const midiData = fs.readFileSync(fullPath);
	const Midi = require('@tonejs/midi');
	const midi = new Midi(midiData);

	//get the tracks
	midi.tracks.forEach(track => {
	  //tracks have notes and controlChanges

	  //notes are an array
	  const notes = track.notes
	  notes.forEach(note => {
	    //note.midi, note.time, note.duration, note.name
	    console.log(`note: ${json(note)}`);
	  })

	  //they are also aliased to the CC number's common name (if it has one)
	  track.controlChanges.sustain.forEach(cc => { // ** ERROR **
	    // cc.ticks, cc.value, cc.time
	  })

	  //the track also has a channel and instrument
	  console.log(`instrument name: ${track.instrument.name}`)
	})
@stale
Copy link

stale bot commented Nov 12, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Nov 12, 2019
@drone1
Copy link
Author

drone1 commented Nov 12, 2019

Hit me, @tambien.

@stale stale bot removed the wontfix label Nov 12, 2019
@tambien
Copy link
Contributor

tambien commented Nov 12, 2019

@drone1 is this still an issue? i think the examples have been updated since you originally posted this.

@drone1
Copy link
Author

drone1 commented Nov 15, 2019

"Basic example" from the README.md – the code has not changed:

  track.controlChanges.sustain.forEach(cc => {
    // cc.ticks, cc.value, cc.time
  })

I just tested the current repo with my same data. Now, instead of track.controlChanges.sustain being an empty object {} as I said in my original post, it's just undefined, and track.controlChanges is undefined this time.

I guess that makes sense if there is no control change data. So, expected?

Node v10.4.1. Thanks.

@drone1
Copy link
Author

drone1 commented Dec 19, 2019 via email

@stale
Copy link

stale bot commented Feb 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Feb 17, 2020
@stale stale bot closed this as completed Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
@tambien @drone1 and others