Accessing Timidity config

I’ve been building a snap of CorsixTH - a re-implementation of the old DOS game Theme Hospital. One of the greatest games of all time, and made even better by the CorsixTH developers :slight_smile:

Unfortunately I’ve hit a stumbling block and wondered if someone was able to help my post-Christmas brain out.

The game works perfectly, but without audio, because the lua scripting system uses timidity to play midi files, and the configuration for the timidity midi system is over in /etc/timidity, which the snap can’t access. Am I gonna have to build Timidity from source, and coerce the config file location, or is there some better way?

Here’s the console output when you run corsixth in a terminal.

An error has occurred!
Almost anything can be the cause, but the detailed information below can help the developers find the source of the error.
Running: The callback handler.
A stack trace is included below, and the handler has been disconnected.
/snap/corsixth/x8/CorsixTH/Lua/audio.lua:580: Could not load music file 'Sound/Midi/MEND.XMI' (/etc/timidity/freepats.cfg: Permission denied)
stack traceback:
	[C]: in function 'yield'
	/snap/corsixth/x8/CorsixTH/Lua/app.lua:915: in function </snap/corsixth/x8/CorsixTH/Lua/app.lua:910>

The yaml I’m using to build trunk is below. To test this you’ll need the original Theme Hospital game, which is excellent, and available DRM-free on GOG (currently on sale for only £1.19, which is an absolute bargain for this much fun. The GOG download contains the old DOS version (packaged for Windows and OSX) which works fine under DOSBox on Linux - or - eventually - with this snap :wink:

name: corsixth
version: v0.61
summary: Open source clone of Theme Hospital
description: ''

grade: stable
confinement: strict

apps:
  corsixth:
    command: desktop-launch $SNAP/CorsixTH/CorsixTH
    environment:
      LUA_CPATH: '$SNAP/usr/lib/x86_64-linux-gnu/lua/5.2/?.so;;'
    plugs:
    - network
    - network-bind
    - unity7
    - opengl
    - home
    - pulseaudio

parts:
  corsixth:
    after: [desktop-gtk2]
    plugin: cmake
    source: .
    build-packages:
      - build-essential
      - cmake
      - liblua5.2-0
      - liblua5.2-dev
      - libsdl2-dev
      - libsdl2-mixer-dev
      - timidity
      - libfreetype6-dev
      - lua-filesystem-dev
      - lua-lpeg
      - doxygen
      - libavcodec-dev
      - libavformat-dev 
      - libavresample-dev 
      - libavutil-dev
      - libavdevice-dev 
      - libswscale-dev
      - libpostproc-dev
      - libswresample-dev
      - libavfilter-dev
    stage-packages:
      - lua-filesystem
      - lua-lpeg
      - freepats

I’ve just spent some time trekking through the code of SDL and Timidity… Unfortunately it doesn’t look like there’s any way to override the configuration file with an environment variable. You could try copying the timidity.cfg into the snap’s $HOME directory as it appears that timidity will look for a user-level config there. Looks like it expects to find it at $HOME/.timidity.cfg. (Line 2541 in https://sourceforge.net/p/timidity/git/ci/master/tree/timidity/timidity.c)

Well spotted. I tried putting one in ~/snap/corsixth/current with:-

dir /snap/corsixth/current/usr/share/timidity/freepats
source ~/snap/corsixth/current/freepats.cfg

And the ~/snap/corsixth/current/freepats.cfg to make sure has this as the first line

dir /snap/corsixth/current/usr/share/midi/freepats

Sadly the error is the same. :frowning:

Whilst timidity might be a problem, using your snapcraft.yaml I don’t get any sound in the intro videos either. I don’t think timidity is involved there. Perhaps there is a deeper error affecting all sound?

Ah, you’re right. I only have audio in the initial intro video and sound effects if I install in devmode. Midi music never works. Next step is strace it to see why I guess.

do any of our audio interfaces (alsa/pulse) even have midi support at all yet ? IIRC that requires special device access … (but that should also show denials in syslog)

A quick FYI, sound (but not MIDI) works with the addition of the joystick and process-control plugs, if the user manually connects them after install.

name: corsixth
version: v0.61
summary: Open source clone of Theme Hospital
description: ''

grade: stable
confinement: strict

apps:
  corsixth:
    command: desktop-launch $SNAP/CorsixTH/CorsixTH
    environment:
      LUA_CPATH: '$SNAP/usr/lib/x86_64-linux-gnu/lua/5.2/?.so;;'
    plugs:
    - network
    - network-bind
    - unity7
    - opengl
    - home
    - pulseaudio
    - joystick
    - process-control

parts:

  corsixth:
    after: [desktop-gtk2]
    plugin: cmake
    source: .
    build-packages:
      - build-essential
      - cmake
      - liblua5.2-0
      - liblua5.2-dev
      - libsdl2-dev
      - libsdl2-mixer-dev
      - timidity
      - libfreetype6-dev
      - lua-filesystem-dev
      - lua-lpeg
      - doxygen
      - libavcodec-dev
      - libavformat-dev 
      - libavresample-dev 
      - libavutil-dev
      - libavdevice-dev 
      - libswscale-dev
      - libpostproc-dev
      - libswresample-dev
      - libavfilter-dev
    stage-packages:
      - lua-filesystem
      - lua-lpeg
      - freepats
1 Like

There’s a TIMIDITY_CFG environment variable which can be used for the custom timidity.cfg path. This suppresses the Could not load music file 'Sound/Midi/MEND.XMI' (/etc/timidity/freepats.cfg: Permission denied) error messages but I still can’t get any actual midi sound. Harrumph.

Success! Pointing TIMIDITY_CFG to this timidity.cfg file seems to make midi audio work:

dir /snap/corsixth/current/usr/share/midi/freepats

drumset 0

 25	Drum_000/025_Snare_Roll.pat 
 26	Drum_000/026_Snap.pat 
 27	Drum_000/027_High_Q.pat 
 31	Drum_000/031_Sticks.pat 
 32	Drum_000/032_Square_Click.pat 
 33	Drum_000/033_Metronome_Click.pat 
 34	Drum_000/034_Metronome_Bell.pat 
 35	Drum_000/035_Kick_1.pat amp=100
 36	Drum_000/036_Kick_2.pat amp=100
 37	Drum_000/037_Stick_Rim.pat 
 38	Drum_000/038_Snare_1.pat 
 39	Drum_000/039_Clap_Hand.pat amp=100
 40	Drum_000/040_Snare_2.pat 
 41	Drum_000/041_Tom_Low_2.pat amp=100
 42	Drum_000/042_Hi-Hat_Closed.pat 
 43	Drum_000/043_Tom_Low_1.pat amp=100
 44	Drum_000/044_Hi-Hat_Pedal.pat 
 45	Drum_000/045_Tom_Mid_2.pat amp=100
 46	Drum_000/046_Hi-Hat_Open.pat 
 47	Drum_000/047_Tom_Mid_1.pat amp=100
 48	Drum_000/048_Tom_High_2.pat amp=100
 49	Drum_000/049_Cymbal_Crash_1.pat 
 50	Drum_000/050_Tom_High_1.pat amp=100
 51	Drum_000/051_Cymbal_Ride_1.pat 
 52	Drum_000/052_Cymbal_Chinese.pat 
 53	Drum_000/053_Cymbal_Ride_Bell.pat amp=100
 54	Drum_000/054_Tombourine.pat 
 55	Drum_000/055_Cymbal_Splash.pat 
 56	Drum_000/056_Cow_Bell.pat 
 57	Drum_000/057_Cymbal_Crash_2.pat 
 58	Drum_000/058_Vibra-Slap.pat 
 59	Drum_000/059_Cymbal_Ride_2.pat 
 60	Drum_000/060_Bongo_High.pat 
 61	Drum_000/061_Bongo_Low.pat 
 62	Drum_000/062_Conga_High_1_Mute.pat 
 63	Drum_000/063_Conga_High_2_Open.pat 
 64	Drum_000/064_Conga_Low.pat 
 65	Drum_000/065_Timbale_High.pat 
 66	Drum_000/066_Timbale_Low.pat 
 67	Drum_000/067_Agogo_High.pat 
 68	Drum_000/068_Agogo_Low.pat 
 69	Drum_000/069_Cabasa.pat amp=100
 70	Drum_000/070_Maracas.pat 
 71	Drum_000/071_Whistle_1_High_Short.pat 
 72	Drum_000/072_Whistle_2_Low_Long.pat 
 73	Drum_000/073_Guiro_1_Short.pat 
 74	Drum_000/074_Guiro_2_Long.pat 
 75	Drum_000/075_Claves.pat amp=100
 76	Drum_000/076_Wood_Block_1_High.pat 
 77	Drum_000/077_Wood_Block_2_Low.pat 
 78	Drum_000/078_Cuica_1_Mute.pat amp=100
 79	Drum_000/079_Cuica_2_Open.pat amp=100
 80	Drum_000/080_Triangle_1_Mute.pat 
 81	Drum_000/081_Triangle_2_Open.pat 
 82	Drum_000/082_Shaker.pat 
 84	Drum_000/084_Belltree.pat 

bank 0

 0	Tone_000/000_Acoustic_Grand_Piano.pat amp=120 pan=center
 1	Tone_000/001_Acoustic_Brite_Piano.pat 
 2	Tone_000/002_Electric_Grand_Piano.pat 
 4	Tone_000/004_Electric_Piano_1_Rhodes.pat 
 5	Tone_000/005_Electric_Piano_2_Chorused_Yamaha_DX.pat 
 6	Tone_000/006_Harpsichord.pat 
 7	Tone_000/007_Clavinet.pat 
 8	Tone_000/008_Celesta.pat 
 9	Tone_000/009_Glockenspiel.pat 
 13	Tone_000/013_Xylophone.pat 
 14	Tone_000/014_Tubular_Bells.pat 
 15	Tone_000/015_Dulcimer.pat 
 16	Tone_000/016_Hammond_Organ.pat 
 19	Tone_000/019_Church_Organ.pat 
 21	Tone_000/021_Accordion.pat 
 23	Tone_000/023_Tango_Accordion.pat 
 24	Tone_000/024_Nylon_Guitar.pat 
 25	Tone_000/025_Steel_Guitar.pat 
 26	Tone_000/026_Jazz_Guitar.pat 
 27	Tone_000/027_Clean_Electric_Guitar.pat 
 28	Tone_000/028_Muted_Electric_Guitar.pat 
 29	Tone_000/029_Overdriven_Guitar.pat 
 30	Tone_000/030_Distortion_Guitar.pat 
 32	Tone_000/032_Acoustic_Bass.pat 
 33	Tone_000/033_Finger_Bass.pat 
 34	Tone_000/034_Pick_Bass.pat 
 35	Tone_000/035_Fretless_Bass.pat 
 36	Tone_000/036_Slap_Bass_1.pat 
 37	Tone_000/037_Slap_Bass_2.pat 
 38	Tone_000/038_Synth_Bass_1.pat 
 40	Tone_000/040_Violin.pat 
 42	Tone_000/042_Cello.pat 
 44	Tone_000/044_Tremolo_Strings.pat 
 45	Tone_000/045_Pizzicato_Strings.pat 
 46	Tone_000/046_Harp.pat 
 47	Tone_000/047_Timpani.pat 
 48	Tone_000/048_String_Ensemble_1_Marcato.pat 
 53	Tone_000/053_Voice_Oohs.pat 
 56	Tone_000/056_Trumpet.pat 
 57	Tone_000/057_Trombone.pat 
 58	Tone_000/058_Tuba.pat 
 59	Tone_000/059_Muted_Trumpet.pat 
 60	Tone_000/060_French_Horn.pat 
 61	Tone_000/061_Brass_Section.pat 
 64	Tone_000/064_Soprano_Sax.pat 
 65	Tone_000/065_Alto_Sax.pat 
 66	Tone_000/066_Tenor_Sax.pat 
 67	Tone_000/067_Baritone_Sax.pat 
 68	Tone_000/068_Oboe.pat 
 69	Tone_000/069_English_Horn.pat 
 70	Tone_000/070_Bassoon.pat 
 71	Tone_000/071_Clarinet.pat 
 72	Tone_000/072_Piccolo.pat 
 73	Tone_000/073_Flute.pat 
 74	Tone_000/074_Recorder.pat 
 75	Tone_000/075_Pan_Flute.pat 
 76	Tone_000/076_Bottle_Blow.pat 
 79	Tone_000/079_Ocarina.pat 
 80	Tone_000/080_Square_Wave.pat 
 84	Tone_000/084_Charang.pat 
 88	Tone_000/088_New_Age.pat 
 94	Tone_000/094_Halo_Pad.pat 
 95	Tone_000/095_Sweep_Pad.pat 
 98	Tone_000/098_Crystal.pat 
 101	Tone_000/101_Goblins--Unicorn.pat 
 102	Tone_000/102_Echo_Voice.pat 
 104	Tone_000/104_Sitar.pat 
 114	Tone_000/114_Steel_Drums.pat 
 115	Tone_000/115_Wood_Block.pat 
 120	Tone_000/120_Guitar_Fret_Noise.pat 
 122	Tone_000/122_Seashore.pat 
 125	Tone_000/125_Helicopter.pat 

I hope to see your snap in the store at the earliest opportunity :slight_smile: