Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TamTam.py
blob: 6b4e7789c7dc4dfebf13ccf9599151274fd2ad1c (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import signal , time , sys , os, shutil
import pygtk
pygtk.require( '2.0' )
import gtk

import Config
import Util.CSoundClient as CSoundClient
from   Util.Profiler import TP
from   Player.StandalonePlayer import StandAlonePlayer
from   Edit.MainWindow import MainWindow
from Util.Clooper.SClient import *

try :
    from sugar.activity.Activity import Activity
except ImportError:
    print "No Sugar for you"

def init_csound():
    #csnd = CSoundClient.CSoundClientSocket( Config.SERVER_ADDRESS, Config.SERVER_PORT, os.getpid() )
    #csnd = CSoundClient.CSoundClientPerf( '/usr/share/olpc-csound-server/univorc.csd' )
    #csnd = CSoundClient.CSoundClientPerf( Config.TAM_TAM_ROOT + '/Resources/univorc.csd' )
    csnd = CSoundClient.CSoundClientPlugin( Config.TAM_TAM_ROOT + '/Resources/univorc.csd' )
    csnd.connect(True)
    csnd.setMasterVolume(100.0)
    CSoundClient.CSoundClient = csnd   #Dodgy move: TODO: remove this global variable.
    return csnd

if not os.path.isdir(Config.PREF_DIR):
    os.mkdir(Config.PREF_DIR)
    os.system('chmod 0777 ' + Config.PREF_DIR + ' &')
    for snd in ['mic1','mic2','mic3','mic4','lab1','lab2','lab3','lab4']:
        shutil.copyfile(Config.SOUNDS_DIR + '/' + snd , Config.PREF_DIR + '/' + snd)
        os.system('chmod 0777 ' + Config.PREF_DIR + '/' + snd + ' &')

if __name__ == "__main__":     
    csnd = init_csound()

    def run_non_sugar_mode():
        tamtam = StandAlonePlayer(csnd)
        mainwin = gtk.Window(gtk.WINDOW_TOPLEVEL)
        color = gtk.gdk.color_parse('#FFFFFF')
        mainwin.modify_bg(gtk.STATE_NORMAL, color)
        #mainwin.set_size_request(1200,700)
        mainwin.set_title('miniTamTam')
        mainwin.set_resizable(False)
        mainwin.connect('destroy' , gtk.main_quit )
        mainwin.connect( "key-press-event", tamtam.keyboardStandAlone.onKeyPress )
        mainwin.connect( "key-release-event", tamtam.keyboardStandAlone.onKeyRelease )
        mainwin.add(tamtam)
        tamtam.show()
        mainwin.show()
        csnd.load_instruments()
        gtk.main()

    def run_edit_mode():
        tamtam = MainWindow(csnd)
        mainwin = gtk.Window(gtk.WINDOW_TOPLEVEL)
        mainwin.set_title('TamTam Player')
        mainwin.set_geometry_hints( None, 1200, 900, 1200, 900, 1200, 900 )
        #mainwin.fullscreen() # don't need to specify full screen, it seem to sit properly anyway
        mainwin.set_resizable(False)
        mainwin.connect('destroy' , tamtam.destroy )
        #mainwin.connect( "configure-event", tamtam.handleConfigureEvent )
        mainwin.connect( "key-press-event", tamtam.onKeyPress )
        mainwin.connect( "key-release-event", tamtam.onKeyRelease )
        mainwin.connect( "delete_event", tamtam.delete_event )
        mainwin.add(tamtam)
        tamtam.show()
        mainwin.show()
        csnd.load_instruments()
        gtk.main()

    if len(sys.argv) > 1 and sys.argv[1] == 'edit':
        if False:
            import hotshot
            prof = hotshot.Profile("some_stats")
            prof.runcall(run_edit_mode)
            prof.close()
        else:
            run_edit_mode()
    else:
        run_non_sugar_mode()
    
    csnd.connect(False)
    csnd.destroy()
    sys.exit(0)

class TamTam(Activity):
    def __init__(self):
        Activity.__init__(self)
        
        color = gtk.gdk.color_parse('#FFFFFF')
        self.modify_bg(gtk.STATE_NORMAL, color)
        
        self.csnd = init_csound()
        self.tamtam = StandAlonePlayer(self.csnd)
        self.connect('focus_in_event',self.handleFocusIn)
        self.connect('focus_out_event',self.handleFocusOut)
        self.connect('destroy', self.do_quit)
        self.add(self.tamtam)
        self.tamtam.show()
        self.csnd.load_instruments()
        self.set_title('TamTam')
        self.set_resizable(False)
        self.connect( "key-press-event", self.tamtam.keyboardStandAlone.onKeyPress )
        self.connect( "key-release-event", self.tamtam.keyboardStandAlone.onKeyRelease )

    def handleFocusIn(self, event, data=None):
        self.csnd.connect(True)
        self.csnd.load_instruments()
    
    def handleFocusOut(self, event, data=None):
        if self.tamtam.synthLabWindowOpen(): 
            return
        self.csnd.connect(False)

    def do_quit(self, arg2):
        os.system('rm ' + Config.PREF_DIR + '/synthTemp*')
        self.csnd.destroy()
        del self.tamtam