FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Midi Music
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Midi Music
Posted: Wed Apr 22, 2026 03:36 PM

I did some tests for polyphonic music,

We use this functions to play midi files

#include "fivewin.ch"

FUNCTION PlayMidi( cFile )

   LOCAL cAlias := "mymidi"

   // Open file MIDI
   mciSendString( "close all", 0, 0, 0 )
   mciSendString( "open " + cFile + " type sequencer alias " + cAlias, 0, 0, 0 )

   // Play
   mciSendString( "play " + cAlias, 0, 0, 0 )

RETURN NIL

By any chance, have any of you ever tried your hand at midi files? That is, recreating a midi file in FiveWin and playing it without using mciSendString?

I managed to recreate the sound of musical chords, that is, the simultaneous sound of three or four notes that create the musical chord, I found a way to simulate the drums all by looking at how it was on my old Commodore 64, it does not use the Tone() function of fwh because this makes a monophonic sound, I found a series of musical instruments using a DLL present in all Windows, on Win10 it seems to work well. I don't know if anyone in the community has ever created something similar.

Also make a function tò converte a file Midi in a CSV file the result Is this

0, 0, Header, 1, 2, 384
1, 0, Start_track
1, 0, Tempo, 500000
1, 1536, End_track
2, 0, Start_track
2, 0, Program_c, 0, 19
2, 384, Note_on_c, 0, 60, 100
2, 768, Note_off_c, 0, 60, 0
2, 768, Note_on_c, 0, 64, 110
2, 1152, Note_off_c, 0, 64, 0
2, 1152, End_track

Column Explanation (What the Numbers Mean)

Take the row:

2, 384, Note_on_c, 0, 60, 100

Column 1 (Track): 2
Indicates that this event belongs to track number 2 (often the melody).

Column 2 (Tempo/Tick): 384
This is the exact moment the event occurs. If the resolution is 384, this event occurs exactly at the beginning of the second beat of the first measure.

Column 3 (Event): Note_on_c
Tells the program what to do. In this case: "Turn on a note."

Column 4 (Channel): 0
The MIDI channel (0 to 15). Channel 9 is usually the drums.

Column 5 (Note/Parameter 1): 60
The MIDI note number. 60 corresponds to middle C (C4).

Column 6 (Volume/Parameter 2): 100
The velocity, or how hard the note is struck (from 0 to 127).

Other row types you'll find:.

Header: 0, 0, Header, Format, Tracks, Division

Indicates how many tracks there are and how many "ticks" make up a quarter note (essential for velocity).

Tempo: 1, 0, Tempo, 500000
Indicates the velocity in microseconds per quarter note (500,000 equals 120 BPM).

Program_c: 2, 0, Program_c, 0, 19
Change the instrument.

Here it says: "On channel 0, set instrument 19 (Organ)."

If I make the music myself, that is, I've created some functions to recreate a musical note and can even play the chords, it works and the music sounds good.

I made Also a drums set

I recreated by hand an 80's tune with the drum set, a Van Hallen opening, sapore di sale by Gino Paoli recently deceased, creating the call to the notes myself

If I use my function to convert a MIDI file to CSV, it does it as well as the online services on the internet, then if I want to play my CSV file, it plays badly.

I haven't been able to get the tempo right all morning.

For example, "Happy Birthday" sounds like it's being played by a child who doesn't know how to play and plays the notes detached as if he's waiting for who knows what...

The research to be continue.....

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 61
Joined: Wed Jul 26, 2023 12:08 PM
Re: Midi Music
Posted: Wed Apr 22, 2026 05:27 PM

Hi Silvio,

I can play all the audio/music files that Winamp can play. I have a library that I developed with cpp, thanks to Winamp's open source code. I have a solid sample archive. (Include .mid files)

Zenhiser loops are very useful when writing code.

If I'm on a difficult rescue mission, Diana Arkenstone's "Voice of Angel" plays in my earphone non-stop.

With HyperSpin and Launchbox, I can play all old games with the emulator.

My archive is open to everyone :)

Best regards,
Ertan,

ertan_ozturk@yahoo.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Midi Music
Posted: Wed Apr 22, 2026 07:15 PM
ertan wrote:

Hi Silvio,

I can play all the audio/music files that Winamp can play. I have a library that I developed with cpp, thanks to Winamp's open source code. I have a solid sample archive. (Include .mid files)

Zenhiser loops are very useful when writing code.

If I'm on a difficult rescue mission, Diana Arkenstone's "Voice of Angel" plays in my earphone non-stop.

With HyperSpin and Launchbox, I can play all old games with the emulator.

My archive is open to everyone :)

I would like to do it with Harbour and FWH

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Midi Music
Posted: Wed Apr 22, 2026 09:30 PM

a test to show track of a midi with Xbrowse ( I load only one track 3)

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Midi Music
Posted: Wed Apr 22, 2026 09:39 PM

Now I Ioad all tracks of HappyBirthday song ( midi file) there are 8 tracks asign one color for each track

Hi everyone,

I’ve been working on a MIDI Sequencer/Piano Roll interface using XBROWSE. The core challenge was mapping temporal MIDI "Ticks" to a spatial grid (Array columns). Here is the logic I used:

Grid Resolution: I defined each array column as 120 ticks (which equals a 1/16th note in a 480 PPQ file). This creates a musical "step" grid.

Mapping Formula: The column position is calculated as (CurrentTick / 120) + 2 (offsetting for the note-name column).

Multi-Track Visualization: Each cell stores the Track ID. Using the bClrStd block, the browser dynamically assigns a specific color to the cell background based on that ID, creating a professional DAW-like look.

Optimization: I used oBrw:nFreeze := 1 to keep note names visible and SetGroupHeader() every 8 columns to represent musical bars (measures).

The result is a high-performance, scrollable Piano Roll that automatically scales to the length of any CSV/MIDI file.

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 61
Joined: Wed Jul 26, 2023 12:08 PM
Re: Midi Music
Posted: Thu Apr 23, 2026 02:19 PM

Dear Silvio,

Forget about the .midi files. Let's build YBrowse. Young Browse :)

Best regards,
Ertan,

ertan_ozturk@yahoo.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Midi Music
Posted: Thu Apr 23, 2026 09:41 PM

What mean as Young Browser ? Another browser as xbrowse, tcbrowse, wbrowse, listbox , Tgrid, Dbrowse, ? No need

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Midi Music
Posted: Fri Apr 24, 2026 10:42 PM

I abandoned the idea of ​​using an xbrowse because the scroll is too slow especially if the positions are countless. I'm creating two classes, one to display the piano which you can see on the left working perfectly if you press it plays the corresponding note and on the right a Roll still in preparation as FL studio does.

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion