
MIDISynth module implementation details
---------------------------------------
v0.23 03/12/25

Implementation is as the Acorn MIDI spec except as follows.

Currently the synth reports one active port but will respond to
and play data to all 4 ports.

The synth converts midi commands to audio, it is an output device
and cannot send data so Receive SWI's have no effect.

SWI's:
------

 These always return a fixed value.
 &404C1 MIDI_SetMode:       r0 = 1, r1 = &101
 &404C5 MIDI_InqBufferSize: r0 = 512
 &404C6 MIDI_InqError:      r0 = 0
 &404C7 MIDI_RxByte:        r0 = 0
 &404C8 MIDI_RxCommand:     r0 = 0
  
 These are not implemented and return with registers unchanged.
 &404C0 MIDI_SoundEnable:
 &404C3 MIDI_SetTxActiveSensing:
 &404DF MIDI_IgnoreTiming:
 &404E0 MIDI_SynchSoundScheduler:
 &404E3 MIDI_SetBufferSize:
 &404E4 MIDI_Interface:
  
 Additional swi:

 &404ED MIDI_SynthControl
  r0 = 0, Turn off all generator gates
  r0 = 1. r1 = Number of generators (polyphony), 4 to 64, default 32
  r0 = 2, r1 = Mono/Stereo audio, 0 = stereo, 1 = mono, default 0
  r0 = 3, r1 = Swap L/R audio channels, 0 = normal, 1 = swapped, default 0
  r0 = 4, r1 = Glide time scale factor, 0 to 1000, default 100
  r0 = 5, r1 = Sleep timeout in seconds, 0 to 3600, 0 = disable, default 10
  r0 = 6, r1 = variation banks,  0 = disable, 1 = allowed, default 0
  r0 = 7, r1 = variation kits,  0 = disable, 1 = allowed, default 0
  r0 = 8, r1 = bank override,  0 to 127, 0 = disable, default 0
  r0 = 9, r1 = kit override,  0 to 127, 0 = disable, default 0

Commands:
---------

 These are not implemented and have no effect.
 MidiSound:
 MidiTouch:
 MidiChannel:
 MidiMode:
 MidiStart:
 MidiStop:
 MidiContinue:

 Additional command:

 MidiSynth:

  Syntax: MidiSynth [-option [-option ...]]

  Options:
   -r reset the synthesiser
   -s stereo audio (default)
   -m mono audio
   -w swap L/R audio channels
   -n<x> x = number of generators (polyphony), 4 to 64, default 32
   -g<x> x = glide time, scale factor, 0 to 1000, 0 = disable, default 100 
   -t<x> x = sleep timeout in seconds, 0 to 3600, 0 = disable, default 10
   -v<x> variation banks, x = 0 disable, x = 1 allowed, default 0
   -a<x> variation kits, x = 0 disable, x = 1 allowed, default 0
   -k<x> x = kit override, 0 to 127, 0 = disable, default 0 
   -b<x> x = bank override, 0 to 127, 0 = disable, default 0 
   -i display information
   -i+ as -i with additional information

  Following options are used for testing
   -o open log file in the current directory
   -c close log file
   -d<x> x = the sum of the following values
    1 = log swi calls
    2 = log midi messages
    4 = log ticker callbacks
    8 = log scheduler calls
   
Notes:
------

Reset:

 To reset the synth and do nothing else, use either the swi
 &404DE MIDI_TxSystemReset or the command MidiSynth -r

 The SWI &404E2 MIDI_Init resets the synth but also resets the
 Fast Clock status. 

 Changing the polyphony resets the synth.

 Resetting the synth will instantly mute all notes and all
 instruments will become Accoustic Grand Pianos.
 
Volume:

 The synth supports the system volume via shared sound and the
 MIDI system exclusive master volume command.
 
Sound Sets:

 The synth starts with a default sound set. It will then try to
 load a sound set file from the <MIDISynthChoices$Dir> that is
 usually  $.!Boot.Choices.MIDISynth.
 
 Instrument banks other than bank 0 may contain variations of bank
 0. If this is a problem, variation banks can be disabled using
 the swi or command.
 
Changes
-------
  0.22 07/10/25: Inactive generators are not processed, to reduce cpu load.
                 Maximum Polphony increased to 128. 
 
 

