Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Player/StandalonePlayerOld.py
blob: cc03ab47e7a1c7be7a4a66b9f2efb19a969d0847 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import pygtk
pygtk.require( '2.0' )
import gtk
import os

from Framework.Constants import Constants
from Framework.CSound.CSoundClient import CSoundClient
from Framework.CSound.CSoundConstants import CSoundConstants
from Player.KeyboardStandAlone import KeyboardStandAlone
from Player.NoteStdAlone import NoteStdAlone

class StandAlonePlayer( gtk.Window ):
    
    def __init__(self):
        gtk.Window.__init__( self, gtk.WINDOW_TOPLEVEL )
        self.set_title('TamTam Player')
        self.set_resizable(False)
        
        self.instrument = self.getInstrumentList()[0]
        #self.setInstrument(self.instrument)
        
        CSoundClient.initialize()
        CSoundClient.setMasterVolume(100)
        
        self.connect( "destroy" , self.destroy )
        self.mainWindowBox = gtk.VBox()
        self.add(self.mainWindowBox)
       
        self.enableKeyboard()
        self.drawMainInstrumentButton()
        self.drawMicButton()
        self.drawReverb()
        self.drawInstrumentWindow()
       
        self.show_all()      
        
    def drawMicButton( self ):
        micButtonImg = gtk.Image()
        micButtonImg.set_from_file(Constants.TAM_TAM_ROOT + '/GUI/Core/images/record.png')
        
        self.micButton = gtk.Button()
        self.micButton.set_image(micButtonImg)
        self.micButton.connect('clicked' , self.handleMicButtonClick)
        self.mainWindowBox.add(self.micButton)
        self.micButton.set_no_show_all(True)
        self.micButton.hide()        
    
    def drawReverb( self ):
        reverbAdjustment = gtk.Adjustment(value=0, lower=0, upper=1, step_incr=0.1, page_incr=0, page_size=0)
        reverbSlider = gtk.HScale(adjustment = reverbAdjustment)
        reverbSlider.set_draw_value(False)
        reverbAdjustment.connect("value_changed" , self.setReverb)
        
        reverbLabel = gtk.Label("Reverb")
        self.mainWindowBox.add(reverbSlider)
        self.mainWindowBox.add(reverbLabel)
        
    def drawMainInstrumentButton(self):
        self.mainInstrumentButtonImg = gtk.Image()
        self.mainInstrumentButtonImg.set_from_file(Constants.TAM_TAM_ROOT + '/GUI/Core/images/' + self.getInstrumentList()[0] + '.png')
        instrumentButton = gtk.Button(label=None)
        instrumentButton.set_image(self.mainInstrumentButtonImg)
        instrumentButton.connect('clicked' , self.handleMainInstrumentButton, 'clicked')
        self.mainWindowBox.add(instrumentButton)
        
    def drawInstrumentWindow(self):
        ROW_LEN = 4
        self.instrumentWindow = gtk.Window()
        self.instrumentWindow.set_decorated(False)
        self.instrumentWindow.set_keep_above(True)
           
        vBox = gtk.VBox()
        
        intrumentNum = len(self.getInstrumentList())
        rows = ( intrumentNum / ROW_LEN )
        if intrumentNum % ROW_LEN is not 0:    #S'il y a un reste
            rows = rows + 1
                    
        for row in range(rows):
            hBox = gtk.HBox()
            for instrument in self.getInstrumentList()[row*ROW_LEN:(row+1)*ROW_LEN]:
                instImage = gtk.Image()
                instButton = gtk.Button(label=None)
                instImage.set_from_file(Constants.TAM_TAM_ROOT + '/GUI/Core/images/' + instrument + '.png')
                instButton.set_image(instImage)
                #instButton.set_relief(gtk.RELIEF_NONE)
                instButton.connect('clicked' , self.handleWindowButtonsClick , instrument)
                instButton.connect('enter' , self.handleWindowButtonsEnter , instrument)
                hBox.add(instButton)
            vBox.add(hBox)
        self.instrumentWindow.add(vBox)
        
    def handleMainInstrumentButton(self , widget , data):
        if self.instrumentWindow.get_property('visible') is True:
            if self.instrument[0:3] is not 'mic':
                self.micButton.hide()
            self.instrumentWindow.hide()
            return        
        pos = self.get_position()
        self.instrumentWindow.move(pos[0] + 68 , pos[1] + 24)
        self.instrumentWindow.show_all()
   
    def handleWindowButtonsClick(self , widget , instrument):
        if instrument[0:3] == 'mic':
            self.micButton.show()
        else:
            self.micButton.hide()
        self.instrumentWindow.hide()
            
        
    def handleWindowButtonsEnter(self , widget , instrument):
        self.mainInstrumentButtonImg.set_from_file(Constants.TAM_TAM_ROOT + '/GUI/Core/images/' + instrument + '.png')
        self.setInstrument(instrument)
        self.playInstrumentNote(instrument)

    def handleMicButtonClick(self , widget , data = None):
        if self.instrument == 'mic1':
            CSoundClient.micRecording(7)
        elif self.instrument == 'mic2':
            CSoundClient.micRecording(8)
        elif self.instrument == 'mic3':
            CSoundClient.micRecording(9)
        elif self.instrument == 'mic4':
            CSoundClient.micRecording(10)
        else:
            print 'Bad instrument'        
            
    def enableKeyboard( self ):
        self.keyboardStandAlone = KeyboardStandAlone()
        
        self.add_events(gtk.gdk.BUTTON_PRESS_MASK)
        self.connect( "key-press-event", self.keyboardStandAlone.onKeyPress )
        self.connect( "key-release-event", self.keyboardStandAlone.onKeyRelease )
        #self.connect( "button-press-event", self.button )
    
    def setInstrument( self , instrument ):
        self.instrument = instrument
        self.keyboardStandAlone.setInstrument(instrument)
        
    def setReverb(self,adj):
        self.keyboardStandAlone.setReverb(adj.value)
        
    def playInstrumentNote(self , instrument):
        note = NoteStdAlone( onset = 0, 
                             pitch = 36, 
                             amplitude = 1, 
                             pan = 0.5, 
                             duration = 20, 
                             trackID = 1, 
                             fullDuration = False, 
                             instrument = instrument, 
                             instrumentFlag = instrument,
                             reverbSend = 0)
        note.play()
  
    def getInstrumentList(self):
        CSoundInstruments = CSoundConstants.INSTRUMENTS.keys()
        cleanInstrumentList = []
        for instrumentName in CSoundInstruments:
            if not instrumentName[0: 4] == 'drum' and not instrumentName[0: 3] == 'mic':
               cleanInstrumentList.append( instrumentName )
        cleanInstrumentList.append('drum1kit')
        cleanInstrumentList.append('drum2kit')
        cleanInstrumentList.append('drum3kit')
        cleanInstrumentList.sort()
        for n in range(4):
            cleanInstrumentList.append('mic' + str(n+1))
        return cleanInstrumentList
    
    def destroy( self, widget ):
        gtk.main_quit()

if __name__ == "__main__": 
    standAlonePlayer = StandAlonePlayer()
    #start the gtk event loop
    gtk.main()