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

Reading MIDI track labels as String #22

Open
jochemstoel opened this issue Apr 18, 2017 · 2 comments
Open

Reading MIDI track labels as String #22

jochemstoel opened this issue Apr 18, 2017 · 2 comments
Labels

Comments

@jochemstoel
Copy link

Thank you for creating NPM package midifile. I read the 'documentation' and had a quick browse through the code but did not find an answer there.

How do I read the names of separate tracks of the MIDI file as a String? By names I mean the optional label assigned to the track by the creator of the file. For example drums or acoustic guitar one or vocals.

Thanks in advance.

@nfroidure
Copy link
Owner

@jochemstoel I don't think it is doable out of the box right now. Any PR allowing to do so would be merged.

@ritz078
Copy link

ritz078 commented Aug 13, 2019

Here is how I read that. Currently, the event with a subtype of EVENT_META_TRACK_NAME has the data property. Just need to convert it to a string.

import MidiEvents from "midievents";
import UTF8 from "utf-8";
import MidiFile from "midifile";

const midi = new MidiFile(this.arrayBuffer);
const events = midi.getEvents();
events.forEach(event => {
 if (event.subtype === MidiEvents.EVENT_META_TRACK_NAME) {
	const text = UTF8.getStringFromBytes(event.data, 0, event.length, true);
      	this.song.header.name.push(text);
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants