Does anyone know how to play an already made midi file in QBasic? I have downloaded several peoples programs but they do not seem to work. Does anyone know of any code to play a midi file?
Thanks
TP :mrgreen:

Dani AI

Generated

Short summary and practical routes for playing a .MID from QBasic (historical context: posts by , , , and point in the same directions). Plain MS QBasic’s built‑ins (PLAY/SOUND) are for the PC speaker and do not parse or stream standard MIDI files. Playing a .MID requires either (A) software that speaks to a MIDI device/driver (Sound Blaster/MPU‑401 era) under real DOS, or (B) running a BASIC dialect on a host OS that can call the OS multimedia APIs or launch an external player.

Recommended approaches (practical, ordered by effort and reliability)

  1. Modern BASIC (lowest friction): use a QB‑compatible modern compiler/interpreter (QB64 or FreeBASIC). These can call the Windows multimedia interface and launch/play a MIDI file from code. Conceptual example (MCI commands shown; exact DECLARE/interop varies by dialect):
' Conceptual example (QB64/FreeBASIC style)
mciSendString("open ""C:\music\song.mid"" alias mymid")
mciSendString("play mymid")
' later:
mciSendString("stop mymid")
mciSendString("close mymid")
  1. Keep classic QBasic under DOS: locate a QB MIDI library/driver (historical QB libraries exist that talk to Sound Blaster/MPU-401 or provide a TSR player). Run under DOSBox on modern hardware and enable SB/MPU emulation; the library + DOSBox usually gives authentic MIDI playback (echoes and ).

  2. Minimal workaround: have QBasic launch an external MIDI player with SHELL (or the host OS command). This keeps QBasic simple and delegates playback.

Troubleshooting / notes

  • Absolute paths and proper quoting matter when opening files.
  • Under Windows the system MIDI mapper/device must be present (drivers or a software synth).
  • When targeting authentic DOS behavior, expect IRQ/DMA/port configuration for Sound Blaster in DOSBox or real hardware.
  • The route with QB64/FreeBASIC is recommended for fast, maintainable results while preserving BASIC-style coding.

Recommended Answers

All 5 Replies

helllooooooo? Does anyone know the answer to this mysterious and magical question? I have tried several programs to do this but none seem to work!!! Is there just a few lines of code I can use? Any ideas?
Thanks for your time even if you don't know the answer,
Pilky

helllooooooo? Does anyone know the answer to this mysterious and magical question? I have tried several programs to do this but none seem to work!!! Is there just a few lines of code I can use? Any ideas?
Thanks for your time even if you don't know the answer,
Pilky

It's been AGES since I've even messed with QBasic.... I am pretty sure there is a sound function (sound, snd, something like that) it might PLAY, but I don't remember. Anyway, you pass the function a value, a number of some kind, and it will play the sound. This has only worked through the PC Speaker for me, but it might work through real speakers. I'm guessing you might want to try something like... reading in the midi as binary, and passing those values to the function, in some kind of loop. I'm in Linux... so actually testing these out are ... well... you know.

Tom,
sorry couldn't do it in qbasic. Take a look at:
http://www.daniweb.com/code/snippet224.html
This short code is written in a more modern basic dialect called BCX-basic which makes it easy to write Windows GUI programs.

It is possible, and I've seen it before. But that was years ago on those big QB sites back in the 90's. and others. Not a clue which websites for QB are still around. But the code you want is out there.

If I remember correctly, the sound drivers written to handle everything were only for the sound blaster cards.

here is a file that plays midi in qb in the background, along w/ documentation. may take some tweaking. I've used this exact code in programs back in the day, so i know i got it to work somehow. If you're using anything but true dos, run under dosbox.

as for old school qb sites, check this 1999 mirror from the internet archive of qbasic.com:
http://web.archive.org/web/19990127152700/qbasic.com/qbindex.shtml

-gummo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.