File: GeneralMidi.py

package info (click to toggle)
csound 1%3A6.08.0~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 46,084 kB
  • sloc: ansic: 179,873; cpp: 58,415; python: 11,289; lisp: 4,046; xml: 1,302; objc: 1,198; yacc: 1,197; perl: 635; java: 618; sh: 608; tcl: 341; lex: 209; makefile: 168
file content (58 lines) | stat: -rw-r--r-- 1,859 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python

# Copyright (c) 2003 by Michael Gogins
# Shows how to render an ordinary MIDI sequence
# using a SoundFont

import CsoundAC

# Load the MIDI sequence into the score.
model = CsoundAC.MusicModel()
model.setCppSound(csound)
score = model.getScore()
score.load("c:/WINDOWS/Media/town.mid")
print("Score length = ", len(score))
csound.setOrchestra('''
sr = 44100
ksmps = 100
nchnls = 2
0dbfs = 1

gSfont                  =                       "../../samples/sf_GMbank.sf2"

giFluid                 fluidEngine
giSFont                 fluidLoad               gSfont, giFluid, 1

ichn                    =                       1
lp01:
ibank                   =                       (ichn != 10 ? 0 : 128)
ipreset                 =                       (ichn != 10 ? (ichn - 1) * 8 : 0)
                        fluidProgramSelect      giFluid, ichn - 1, giSFont, ibank, ipreset
                        loop_le                 ichn, 1, 16, lp01

                        event_i                 "i", 90, 0, -1

instr 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 ; FluidSynth General MIDI
; INITIALIZATION
; Channel, bank, and program determine the preset, that is, the actual sound.
ichannel                =                       p1
ikey                    =                       p4
ivelocity               =                       p5
ijunk11                 =                       p11
; AUDIO
                        print                   ichannel, ikey, ivelocity
                        fluidNote               giFluid, ichannel - 1, ikey, ivelocity
endin

instr 90
aL, aR                  fluidOut                giFluid
                        outs                    aL, aR
endin

''')

csound.setScore(score.getCsoundScore())
csound.setCommand("csound -RWdfo town.wav ./temp.orc ./temp.sco")
csound.exportForPerformance()
model.perform()