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

How to get MIDI Type #68

Open
rualark opened this issue May 29, 2019 · 2 comments
Open

How to get MIDI Type #68

rualark opened this issue May 29, 2019 · 2 comments

Comments

@rualark
Copy link

rualark commented May 29, 2019

Hi!

How can MIDI Type be detected (0, 1, 2)?
Like midifile.GetMIDIType()

I see that it is loaded in MidiFile::read, but seems that it is not stored as class member variable. Possible solution is to convert type variable to a member variable.

// Header parameter #1: format type
int type;
shortdata = readLittleEndian2Bytes(input);
switch (shortdata) {
	case 0:
		type = 0;
		break;
	case 1:
		type = 1;
		break;
	case 2:
		// Type-2 MIDI files should probably be allowed as well,
		// but I have never seen one in the wild to test with.
	default:
		est.Format("Error: cannot handle a type-%hu MIDI file.", shortdata);
		m_rwstatus = false; return m_rwstatus;
}

// Header parameter #2: track count
int tracks;
shortdata = readLittleEndian2Bytes(input);
if (type == 0 && shortdata != 1) {
	est.Format("Error: Type 0 MIDI file can only contain one track. Instead track count is: %hu", shortdata);
	m_rwstatus = false; return m_rwstatus;
} else {
	tracks = shortdata;
}
@craigsapp
Copy link
Owner

A good idea would be to add a function called MidiFile::getOriginalType(). Otherwise, the MIDI type is handled automatically by the MIDI class: if there is one track then it is type-0 and if there are two or more tracks it considered type-1 (and MIDI files are written according to the track count as well).

@zhangyufei49
Copy link

Hi!

How can MIDI Type be detected (0, 1, 2)?
Like midifile.GetMIDIType()

I see that it is loaded in MidiFile::read, but seems that it is not stored as class member variable. Possible solution is to convert type variable to a member variable.

// Header parameter #1: format type
int type;
shortdata = readLittleEndian2Bytes(input);
switch (shortdata) {
	case 0:
		type = 0;
		break;
	case 1:
		type = 1;
		break;
	case 2:
		// Type-2 MIDI files should probably be allowed as well,
		// but I have never seen one in the wild to test with.
	default:
		est.Format("Error: cannot handle a type-%hu MIDI file.", shortdata);
		m_rwstatus = false; return m_rwstatus;
}

// Header parameter #2: track count
int tracks;
shortdata = readLittleEndian2Bytes(input);
if (type == 0 && shortdata != 1) {
	est.Format("Error: Type 0 MIDI file can only contain one track. Instead track count is: %hu", shortdata);
	m_rwstatus = false; return m_rwstatus;
} else {
	tracks = shortdata;
}
  • Type 0 means all event in a single track
  • 1 means multi tracks shared tempo and time-sign meta events
  • 2 means multi tracks don't shared tempo and time-sign info

Type 1 is most common used.
Imagine a piano music score has 2 voices with different tempo at the same time point.
Your left hand need to play 90BPM and right 120.
Human can't play it properly. That's why format 2 is so rare

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

No branches or pull requests

3 participants