How to create music in C++ from scratch (MIDI file format) / C++11 variadic templates example
Автор: Bisqwit
Загружено: 21 окт. 2010 г.
Просмотров: 92 479 просмотров
In this tool-assisted education video, I demonstrate how to write a program that creates a MIDI file from scratch. Some basics on how to write music in a computer program are shown. You see me type every line.
Twitter: / realbisqwit
Patreon: / bisqwit (alternatives at https://iki.fi/bisqwit/donate.html)
Twitch: / realbisqwit
Homepage: https://iki.fi/bisqwit/
MIDI is described in detail in Wikipedia, but put very shortly (and not entirely accurately), its best analogy is in sheet music rather than in an mp3 file. To play MIDI files, you need a synthesizer. There are computer synthesizer programs for various operating systems. In this video, I used an AdLib synthesizer for DOS that I wrote once -- apologies about that -- because I still could not figure out how to record audio from Linux synced to DOSBox's speed, or how to hook TiMidity++ into DOSBox, and DOSBox does not yet even emulate MPU-401 to begin with.
The loopBegin and loopEnd tags are only supported by two MIDI players that I know: FMDRV, which I have created (seen in this video), and Final Fantasy VII by Square Enix. I hold it in a standard's esteem.
Also, as a peculiar quirk, I happen to be running Linux under DOS in this video. I wrote a Linux emulator for DOS using Borland C++ ;-)
Actually, what I wrote is just a (very fast and accurate) terminal emulator; the "simulated" Linux is actually the host computer under which the DOSBox instance runs.
The MHz/GHz rating at the bottom of the screen is the speed by which the CPU emulated by DOSBox runs. I adjust it occasionally during the recording (to make it possible for me to type a long piece of text in a very short time), and the rating is updated in real time.
Also, it is only faintly seen, but I launch a FreeDOS shell at one point. It is why you see two different kind of "DIR" responses in the video.
My editor of choice is neither Vi nor Emacs, but Joseph Allen's Joe. Normally I use 256-color xterm, but here I am running under 16-color DOS and VGA text mode, so the 256-colorness is only emulated by dynamically remapping the palette on demand.
As another peculiar quirk, my Linux "emulator" sets up a 51-line text mode by adding one extra line of text to the screen. Incidentally, I discovered, this mode has a screen resolution of 720x408, which makes it very close to the aspect ratio of 16:9 with square pixels. Hence I set the video aspect ratio to 16:9 rather than VGA's actual ratio, 4:3.
This is the first programming example for which I did not print a script beforehand. I planned and created this entirely in one evening. Therefore there is no PDF to download. But you can download the MIDI file produced by the program, here: https://bisqwit.iki.fi/jutut/kuvat/pr... (it is my original composition).
The source code that I typed in this video can be downloaded here:
https://bisqwit.iki.fi/jutut/kuvat/pr...
You can find the DOSBox Linux terminal hack here:
-- https://bisqwit.iki.fi/src/patch-dosb... -- This patch must be applied into DOSBox.
-- https://bisqwit.iki.fi/src/linux_for_... -- This is the terminal program that is run in DOSBox. Note that it uses hard-coded Finnish keyboard layout. It requires that DOSBox is patched using the above patch.

Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: