File: generator.py

package info (click to toggle)
snack 2.2.10.20090624%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,868 kB
  • sloc: ansic: 32,602; sh: 8,558; tcl: 1,086; python: 761; makefile: 578
file content (66 lines) | stat: -rwxr-xr-x 1,356 bytes parent folder | download | duplicates (5)
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
#! /usr/bin/env python

import sys
if sys.version_info[0] == 2:
    from Tkinter import *
else:
    from tkinter import *

from tkSnack import *

root = Tkinter.Tk()

initializeSnack(root)
"""AudioControllerSingleton().playLatency(100)"""

s = Sound()

filt = Filter('generator', 440.0)
        
def play():
   s.stop()
   s.play(filter=filt)
        
def stop():
   s.stop()        

def config(arg):
   type = var.get()
   if var.get() == "sine" :
      shape = 0.0
   elif var.get() == "rectangle" :
      shape = 0.5
   elif var.get() == "triangle" :
      shape = 0.5
   elif var.get() == "sawtooth" :
      type = "triangle"
      shape = 0.0
   else :
      shape = 0.0
   filt.configure(s1.get(), s2.get(), shape, type, -1)

f = Frame(root)
f.pack()

s1 = Scale(f, from_=4000, to=50, label="Frequency", length=200, command=config)
s1.pack(side='left')

s2 = Scale(f, from_=32767, to=0, label="Amplitude", length=200, command=config)
s2.pack(side='left')

s1.set(440.0)
s2.set(20000)

var  = StringVar()
var.set("sine")

menu = OptionMenu(root, var, "sine", "rectangle", "triangle", "sawtooth", "noise")
menu.pack()
root.bind_all("<Button1-ButtonRelease>", config)

fb = Frame(root)
fb.pack(side='bottom')
Button(fb, bitmap='snackPlay', command=play).pack(side='left')
Button(fb, bitmap='snackStop', command=stop).pack(side='left')

root.mainloop()