forked from csound/csoundAPI_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample11.py
More file actions
77 lines (61 loc) · 2.24 KB
/
example11.py
File metadata and controls
77 lines (61 loc) · 2.24 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Example 11 - Graphical User Interfaces
# Author: Steven Yi <stevenyi@gmail.com>
# 2013.10.28
#
# This example demonstrates a minimal Graphical User Interface application.
# The setup of Csound and starting of the CsoundPerformanceThread is done in
# the global scripting space. Afterwards, a Tkinter GUI is created that has
# one button. The button's callback (the command action) routes to a function
# that just sends an event to Csound.
#
# For this example, since there is no need to synchronize continous channel data
# changes with Csound, it is more efficient to use the CsoundPerformanceThread,
# as it is a native thread. We use the CsoundPerformanceThread's InputMessage()
# function to ensure that the message is processed in a thread-safe manner.
from Tkinter import *
import csnd6
from random import randint, random
###############################
# Our Orchestra for our project
orc = """
sr=44100
ksmps=32
nchnls=2
0dbfs=1
instr 1
kenv linsegr 0, .05, 1, .05, .9, .8, 0
aout vco2 p4 * kenv, p5
aout moogladder aout, 2000, p6
outs aout, aout
endin"""
c = csnd6.Csound() # create an instance of Csound
c.SetOption("-odac") # Set option for Csound
c.SetOption("-m7") # Set option for Csound
c.CompileOrc(orc) # Compile Orchestra from String
c.Start() # When compiling from strings, this call is necessary before doing any performing
perfThread = csnd6.CsoundPerformanceThread(c)
perfThread.Play()
class Application(Frame):
def __init__(self,master=None):
master.title("Csound API GUI Example")
self.items = []
self.notes = []
Frame.__init__(self,master)
self.pack()
self.createUI()
self.master.protocol("WM_DELETE_WINDOW", self.quit)
def createUI(self):
self.size = 600
self.canvas = Canvas(self,height=self.size,width=self.size,bg="darkgray")
self.canvas.pack()
# create button and setup the playNote() callback
self.button = Button(self.canvas, text='Play Note', command=self.playNote)
self.button.pack()
def playNote(self):
perfThread.InputMessage("i1 0 2 .5 400 .25")
def quit(self):
self.master.destroy()
perfThread.Stop()
perfThread.Join()
app = Application(Tk())
app.mainloop()