Commit 6c4f0154 authored by Tomáš Hübelbauer's avatar Tomáš Hübelbauer

Add basic note reading from the MIDI file

parent 8e807c10
.DS_Store
......@@ -6,12 +6,14 @@
- [OP-1 quick guide](https://www.teenageengineering.com/guides/op-1/quick-guide)
- [OP-1 guide](https://www.teenageengineering.com/guides/op-1)
- [OP-1 firmware hacking](https://www.operator-1.com/index.php?p=/discussion/2232/custom-firmware-on-the-op-1)
- [OP-1 Hacks on GitHub](https://github.com/op1hacks)
- [OP-1 Hacks on GitHub](https://github.com/op1hacks)
- [Chords and their notes](http://www.pianochord.com/)
- [Midifi](https://github.com/midifi/midifi) - an open source Synthesia alternative
## App idea
[Here](app)
- Use [titl1981's MIDI files](http://tilt.000webhostapp.com/)
- Use [`smfplayer`'s SMF parser](https://github.com/ryoyakawai/smfplayer/blob/master/js/smfParser.js) (BSD-3-Clause)
- Do Synthesia-like bars falling onto the musical keyboard timing effect
......
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<title>Music App</title>
<script src="ryoyakawai/smfplayer/smfParser.js"></script>
<script src="index.js"></script>
</head>
<body>
<input accept="audio/midi" id="fileInput" type="file" />
<h1 id="nameH1"></h1>
</body>
</html>
window.addEventListener('load', async _ => {
const fileInput = document.getElementById('fileInput');
const nameH1 = document.getElementById('nameH1');
fileInput.addEventListener('change', _ => {
const file = fileInput.files[0];
nameH1.textContent = file.name;
const fileReader = new FileReader();
fileReader.addEventListener('load', _ => {
const data = new SmfParser().parse(fileReader.result);
// Deadmau5 - Strobe from tilt1981 uses 2 channels
//console.log('channels[0]', data.channels[0]);
//console.log('channels[1]', data.channels[1]);
// TODO: What is this?
//console.log('systems', data.systems); // timeSignature & endOfTracks & setTempo's
//^ same as tracks[0] and tracks[1]
// Deadmau5 - Strobe from tilt1981 uses 4 tracks
//console.log('tracks[0]', data.tracks[0]); // timeSignature & endOfTracks
//console.log('tracks[1]', data.tracks[1]); // setTempo's
//console.log('tracks[2]', data.tracks[2]); // same as channels[0] + author meta & endOfTracks
//console.log('tracks[3]', data.tracks[3]); // same as channels[1] + author meta & endOfTracks
// TODO: User channels to generate objects in this format:
// { note: number, startPosition: number, endPosition: number }
const boxes = [];
const notes = data.channels[0].filter(note => note.subtype === 'noteOn' || note.subtype === 'noteOff');
let time = 0;
let pressed = [];
for (const note of notes) {
switch (note.subtype) {
case 'noteOn': {
// TODO: Check if unpressed - should never happen if pressed
pressed.push(note.noteNumber);
break;
}
case 'noteOff': {
// TODO: Make box with timeFrom, timeTo and noteNo
break;
}
}
}
console.log(notes);
});
fileReader.readAsBinaryString(file);
});
});
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment