Paste: Example MIDI thing, Factor C FFI ver.

Author: Serre
Mode: factor
Date: Mon, 13 Jul 2026 02:08:50
Plain Text |
! Copyright (C) 2026 Serre
! See https://factorcode.org/license.txt for BSD license.
USING: windows.types ;
IN: midi.windows

! === Streamed MIDI output via Windows winmm.lib MIDI API

CONSTANT: note-on  "1001"
CONSTANT: note-off "1000"

: on-channel ( on? ch. -- byte )
               [ note-on note-off ? ] 
   [ 15 min >bin 4 CHAR: 0 pad-tail ] bi* append bin> ;

CONSTANT: default-vel 127

: dial-note-bytes ( note on? ch. -- byte-array )
   on-channel swap 127 min default-vel 
   spin 3array >byte-array ;

! == C Bindings

LIBRARY: winmm
TYPEDEF: uint MMRESULT

FUNCTION: MMRESULT midiOutOpen (
  PVOID*     phmo,
  UINT       uDeviceID,
  DWORD_PTR  dwCallback,
  DWORD_PTR  dwInstance,
  DWORD      fdwOpen
)

FUNCTION: MMRESULT midiOutClose (
  HANDLE hmo
)

FUNCTION: MMRESULT midiOutMessage (
  HANDLE    hmo,
  UINT      uMsg,
  DWORD_PTR dw1,
  DWORD_PTR dw2
)

Annotation: Edit

Author: Serre
Mode: factor
Date: Mon, 13 Jul 2026 02:37:58
Plain Text |
! Am I stupid? I wanted midiOut__Short___Msg!
! Oh well, just add:
FUNCTION: MMRESULT midiOutShortMsg (
  HANDLE hmo,
  DWORD dwMsg
)
! To the end

New Annotation

Summary:
Author:
Mode:
Body: