Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #135233

Re: Back & Forth - It still sounds MID.. [7b]

From Hans Bezemer <the.beez.speaks@gmail.com>
Newsgroups comp.lang.forth
Subject Re: Back & Forth - It still sounds MID.. [7b]
Date 2026-07-11 18:21 +0200
Organization A noiseless patient Spider
Message-ID <112tqhd$266vb$1@dont-email.me> (permalink)
References <10t2opl$1jcba$1@dont-email.me> <nnd$2614b7c3$5709f7e4@2048be628611cce3>

Show all headers | View raw


On 11-07-2026 17:09, albert@SPENARNC.XS4ALL.NL wrote:
> Hans Bezemer <the.beez.speaks@gmail.com> wrote:
>> Now on YT:  https://youtu.be/ExDbY0X7Cvg
>>
>> Hans Bezemer
> I hate that you don't mention what it is all about.
> It is about midi. It invites me to type ExDbYo(or 0) in the newsreader
> cause the newsreader don't support cut and place. So I followed
> up, my editor does it better.
> We are at it, This is the rosetta challenge to play a scale.
> A regular speaker required! MAKE-ACCESSABLE is not needed for MSDOS.
> In linux you want XOS generic OS access, e.g. in ciforth.
> 
> ---------------------------------------
> "$-PREFIX" WANTED  "-scripting-" WANTED
> : MAKE-ACCESSABLE   ( n-) 1 1 $65 XOS
>     DUP IF ." You cannot access i/o ports, become root" CR THROW THEN ;
>     : MAKE-SPEAKER-ACCESSABLE ( - )
>     $42 MAKE-ACCESSABLE   $43 MAKE-ACCESSABLE   $61 MAKE-ACCESSABLE ;
>     : SET-FREQUENCY  ( n - )  $B6 $43 PC!   DUP $42 PC!   8 RSHIFT $42 PC! ;
>     : SPEAKER-ON  ( - )  $61 PC@    3  OR $61 PC! ;
>     : SILENT-SPEAKER  ( -) $61 PC@  $FC AND $61 PC! ;
>     : secunde 17843 18904 */ ;
>     CREATE _notes   35613 ( C2) 12 0 DO DUP , secunde LOOP DROP
>     : >timing    ( n - n) 24 - 12 /MOD SWAP   CELLS _notes + @   SWAP RSHIFT ;
>     : NOTE-ON  ( n-)  >timing SET-FREQUENCY SPEAKER-ON ;
>     : NOTE-OFF ( n-)  DROP SILENT-SPEAKER ;
>     : PLAY-NOTE ( n n -)  OVER NOTE-ON MS NOTE-OFF ;
>     : .. ( n - ) 1000 PLAY-NOTE ;
>     \ Play a scale starting at the keyhole c.
>     : PLAY-SCALE
>     \ c'  d'    e'    f'    g'    a'    b'    c''
>     60 .. 62 .. 64 .. 65 .. 67 .. 69 .. 71 .. 72 ..
>     3000 MS ;
>     MAKE-SPEAKER-ACCESSABLE PLAY-SCALE
> ---------------------------------------
> 
> The same scale played on mswindows. (Assuming WINMM.DLL is present
> in SYSTEM32. a multimedia library.)
> openmidi sendmidi closemidi are wrappers around dll calls.
> They are slightly more than wrappers, because if you
> do
>      wina -c midi.frt
> a midi.exe is generated that you can transport accross
> windows systems (i.e. no Forth system needs to be present).
> 
> ---------------------------------------
> \ $Id: midi.frt,v 1.7 2015/04/15 02:04:17 albert Exp albert $
> \ Copyright (2012): Albert van der Horst {by GNU Public License}
> \ Uses MIDI facility to play a simple melody.
> \ vrij naar Jones jonesforth
> 
> WANT sendmidi    ( and openmidi closemid )
> WANT CASE-INSENSITIVE     CASE-INSENSITIVE
> 1 CONSTANT 'Grand_Piano'
> 
> VARIABLE instrument
> 
> : midi-errors
> "
>        2001 : Failed to open MIDI output device
>        2002 : Failed to close MIDI output device
>        2003 : Failed to send to MIDI output device
> " TYPE ;
> 
> : -i   SHIFT-ARGS 1 ARG[] EVALUATE instrument ! SHIFT-ARGS ;
> 
> : -h midi-errors
> "
> -h this help
> -i <instr> : install instrument to play on
> " ETYPE
> BYE ;
> 
> HEX
> \ Send a midi start message for NOTE
> : StartNote 8 LSHIFT 7F0090 OR sendmidi ;
> 
> \ Send a midi stop message for NOTE
> : StopNote 8 LSHIFT 80 OR sendmidi ;
> 
> \ Send a midi select message for VOICE
> : SetInstrument 8 LSHIFT 7F00C0 OR sendmidi ;
> DECIMAL
> 
> \ Play a NOTE for TIME milliseconds.
> : PlayNote OVER StartNote MS StopNote ;
> 
> 
> : handle-args  ARGC 1 > IF 1 ARG[] EVALUATE THEN ;
> 
> : play
>    instrument @ SetInstrument
>    70 500 PlayNote
>    72 500 PlayNote
>    68 500 PlayNote
>    56 500 PlayNote
>    63 1000 PlayNote
>    1000 MS
> ;
> 
> : doit   openmidi handle-args play closemidi ;
> ---------------------------------------
> 
> A midiplayer for actual midi files is easy given WINMM.DLL,
> but the margin is too small to contain it.
> 
> Groetjes Albert

I have no idea what your beef is. If I wonder what's it all about in YT, 
I pull up the description, which in this case says:

"Last time, we learned how to create Midi files using Forth. We were 
able to convert old ZX BASIC programs to the library we created - and 
replicate these melodies without too much effort.

In this second part, we say goodbye to the Midi piano and learn how to 
use different instruments. We will see how we can encode musical notes - 
and even raw frequencies."

I have no idea what you want with "playing a scale". Because that's 
trivial in the lib I wrote, since you can reference the notes themselves 
by their name.

I can't remember the last time I used the beeper -- since PCs come with 
sound cards since the turn of the century. But don't let me keep you 
from having fun. If that wets your taste for nostalgia, let it be.

I have no idea whether there is an actual MIDI device in my current 
soundcard -- and frankly I don't care. I tend to use timidity - and that 
works with files.

If I wanna use a Midi sample, I'll pass it through LAME and I got an MP3 
which works just fine with Kdenlive.

The latter example was just fun. I converted it to the library and this 
came out:

include lib/midi-w.4th

---8<---
s" ce3k.mid" MIDopen abort" Can't open Midi file"

Bright_Acoustic_Piano m.Use

  50  10 m.Beep
  50  12 m.Beep
  50   8 m.Beep
  50  -4 m.Beep
100   3 m.Beep

MIDclose
---8<---

This was the first time I created a "beep" file from a MIDI file. Note 
that this format was derived from the ZX Spectrum. So I fired up Fuse 
and typed:

10 BEEP 0.5,10: BEEP 0.5,12: BEEP 0.5,8: BEEP 0.5,-4: BEEP 1,3

And then ran it. Perfect rendition! Written in 4tH, transcribed to BASIC 
and ported to the ZX Spectrum.

You know: we all have our nostalgia weaknesses! :-)

Hans Bezemer

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Back & Forth - It still sounds MID.. [7b] Hans Bezemer <the.beez.speaks@gmail.com> - 2026-05-01 19:44 +0200
  Re: Back & Forth - It still sounds MID.. [7b] marcel hendrix <mhx@iae.nl> - 2026-07-03 15:24 +0200
    Re: Back & Forth - It still sounds MID.. [7b] dxf <dxforth@gmail.com> - 2026-07-05 18:33 +1000
    Re: Back & Forth - It still sounds MID.. [7b] Hans Bezemer <the.beez.speaks@gmail.com> - 2026-07-05 19:08 +0200
    Re: Back & Forth - It still sounds MID.. [7b] Hans Bezemer <the.beez.speaks@gmail.com> - 2026-07-09 18:18 +0200
      Re: Back & Forth - It still sounds MID.. [7b] Hans Bezemer <the.beez.speaks@gmail.com> - 2026-07-10 14:43 +0200
  Re: Back & Forth - It still sounds MID.. [7b] albert@SPENARNC.XS4ALL.NL - 2026-07-11 17:09 +0200
    Re: Back & Forth - It still sounds MID.. [7b] Hans Bezemer <the.beez.speaks@gmail.com> - 2026-07-11 18:21 +0200
      Re: Back & Forth - It still sounds MID.. [7b] dxf <dxforth@gmail.com> - 2026-07-12 15:02 +1000
        Re: Back & Forth - It still sounds MID.. [7b] Hans Bezemer <the.beez.speaks@gmail.com> - 2026-07-12 16:15 +0200
    Re: Back & Forth - It still sounds MID.. [7b] Hans Bezemer <the.beez.speaks@gmail.com> - 2026-07-11 18:49 +0200

csiph-web