File: output.py

package info (click to toggle)
mididings 0~20120419~ds0-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 928 kB
  • sloc: python: 5,085; cpp: 3,454; ansic: 319; makefile: 8
file content (53 lines) | stat: -rw-r--r-- 1,468 bytes parent folder | download | duplicates (4)
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
#
# output.py - uses the Output() unit to simplify MIDI routing and sending
# program changes
#
# This script assumes that the folling sound sources are connected to
# mididings:
#
# - A sampler, connected to the first output port, listening on channel 1.
#   Program 1 is an acoustic piano sound, program 4 is a Rhodes piano.
#
# - A synthesizer, connected to the second output port. On channel 3, there's
#   an organ sound. On channel 4, there's a string sound.
#
# Program changes on channel 16 switch between scenes.
#

from mididings import *


config(
    # create two output ports
    out_ports = ['sampler', 'synth'],
)

piano   = Output('sampler', 1, 1)
rhodes  = Output('sampler', 1, 4)
organ   = Output('synth',   3)
strings = Output('synth',   4)


run(
    scenes = {
        # scene 1: play piano.
        # this will switch the sampler to program 1, then route all events
        # to it
        1:  piano,

        # scene 2: play organ, transposed one octave down
        2:  Transpose(-12) >> organ,

        # scene 3: split keyboard at C3, the lower part plays rhodes, the
        # upper part plays strings
        3:  KeySplit('c3', rhodes, strings),
    },

    # control patch: use program changes on channel 16 to switch between
    # scenes
    control = Filter(PROGRAM) >> ChannelFilter(16) >> SceneSwitch(),

    # preprocessing: filter out program changes, everything else is sent to
    # the current scene
    pre = ~Filter(PROGRAM),
)