Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/common/Util/LoopSettings.py
blob: d672050d40a7e005c6c67e5705d48e9f776f3ab3 (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import os
from common.Util.ThemeWidgets import *
import common.Config as Config
import commands
Tooltips = Config.Tooltips()

class LoopSettings( gtk.VBox ):
    def __init__( self, popup, playFunction, setChannelFunction, doneLoopSettingsPopup ):
        gtk.VBox.__init__( self )
        self.tooltips = gtk.Tooltips()
        self.popup = popup
        self.playFunction = playFunction
        self.setChannel = setChannelFunction
        self.doneLoopSettingsPopup = doneLoopSettingsPopup
        self.loopedSound = False
        self.soundLength = 1.00
        self.start = 0
        self.end = 1.00
        self.dur = 0.01
        self.register = 0
        self.ok = True

        self.settingsBox = gtk.HBox()
        self.pack_start(self.settingsBox)

        self.fixed = gtk.Fixed()
        self.settingsBox.pack_start(self.fixed)

        self.mainBox = gtk.VBox()

        self.controlsBox = gtk.HBox()

        self.GUI = {}

        nameBox = gtk.VBox()
        self.nameEntry = gtk.Entry()
        self.nameEntry.set_text("name_of_the_sound")
        nameBox.pack_start(self.nameEntry)
        self.mainBox.pack_start(nameBox, False, False, 5)

        loopedBox = gtk.HBox()
        loopedLabel = gtk.Label("Looped sound: ")
        loopedBox.pack_start(loopedLabel)
        loopedToggle = ImageToggleButton(Config.IMAGE_ROOT+"checkOff.svg",Config.IMAGE_ROOT+"checkOn.svg")
        loopedToggle.connect('button-press-event', self.handleLooped )
        loopedBox.pack_start(loopedToggle)
        self.mainBox.pack_start(loopedBox, False, False, 5)

        categoryBox = gtk.HBox()
        categoryMenu = gtk.MenuBar()
        cmenu = gtk.Menu()
        for cat in Config.CATEGORIES:
            if cat != 'all':
                entry = gtk.MenuItem(cat)
                cmenu.append(entry)
                entry.connect("activate", self.handleCategory, cat)
                entry.show()
        self.categoryButton = gtk.Button("Category")
        self.categoryButton.connect_object("event", self.categoryBtnPress, cmenu)
        categoryBox.pack_end(self.categoryButton)
        #self.mainBox.pack_start(categoryBox, False, False, 5)

        registerBox = gtk.HBox()
        registerMenu = gtk.MenuBar()
        rmenu = gtk.Menu()
        self.registerList = ['LOW', 'MID', 'HIGH', 'PUNCH']
        for reg in self.registerList:
            entry = gtk.MenuItem(reg)
            rmenu.append(entry)
            entry.connect("activate", self.handleRegister, self.registerList.index(reg))
            entry.show()
        self.registerButton = gtk.Button("Register")
        self.registerButton.connect_object("event", self.registerBtnPress, rmenu)
        registerBox.pack_end(self.registerButton)
        self.mainBox.pack_start(registerBox, False, False, 5)

        startBox = gtk.VBox()
        self.startAdjust = gtk.Adjustment( 0.01, 0, 1., .001, .001, 0)
        self.GUI['startSlider'] = ImageVScale( Config.IMAGE_ROOT + "sliderEditVolume.png", self.startAdjust, 7 )
        self.startAdjust.connect("value-changed", self.handleStart)
        self.GUI['startSlider'].set_inverted(True)
        self.GUI['startSlider'].set_size_request(50, 200)
        self.startEntry = gtk.Entry()
        self.startEntry.set_width_chars(5)
        self.handleStart( self.startAdjust )
        startBox.pack_start(self.GUI['startSlider'], True, True, 5)
        startBox.pack_start(self.startEntry, True, True, 5)
        self.controlsBox.pack_start(startBox)

        endBox = gtk.VBox()
        self.endAdjust = gtk.Adjustment( 0.9, 0, 1, .001, .001, 0)
        self.GUI['endSlider'] = ImageVScale( Config.IMAGE_ROOT + "sliderEditVolume.png", self.endAdjust, 7 )
        self.endAdjust.connect("value-changed", self.handleEnd)
        self.GUI['endSlider'].set_inverted(True)
        self.GUI['endSlider'].set_size_request(50, 200)
        self.endEntry = gtk.Entry()
        self.endEntry.set_width_chars(5)
        self.handleEnd( self.endAdjust )
        endBox.pack_start(self.GUI['endSlider'], True, True, 5)
        endBox.pack_start(self.endEntry, True, True, 5)
        self.controlsBox.pack_start(endBox)

        durBox = gtk.VBox()
        self.durAdjust = gtk.Adjustment( 0.01, 0, 0.2, .001, .001, 0)
        self.GUI['durSlider'] = ImageVScale( Config.IMAGE_ROOT + "sliderEditVolume.png", self.durAdjust, 7 )
        self.durAdjust.connect("value-changed", self.handleDur)
        self.GUI['durSlider'].set_inverted(True)
        self.GUI['durSlider'].set_size_request(50, 200)
        self.durEntry = gtk.Entry()
        self.durEntry.set_width_chars(5)
        self.handleDur( self.durAdjust )
        durBox.pack_start(self.GUI['durSlider'], True, True, 5)
        durBox.pack_start(self.durEntry, True, True, 5)
        self.controlsBox.pack_start(durBox)

        self.mainBox.pack_start(self.controlsBox, False, False, 5)

        previewBox = gtk.VBox()
        self.playStopButton = ImageToggleButton(Config.IMAGE_ROOT + 'miniplay.png', Config.IMAGE_ROOT + 'stop.png')
        self.playStopButton.connect('button-press-event' , self.handlePlayButton)
        previewBox.pack_start(self.playStopButton)
        self.mainBox.pack_start(previewBox, False, False, 5)

        checkBox = gtk.VBox()
        checkButton = ImageButton(Config.IMAGE_ROOT + 'check.png')
        checkButton.connect('clicked' , self.handleCheck)
        checkBox.pack_start(checkButton)
        self.mainBox.pack_start(checkBox, False, False, 5)

        self.fixed.put( self.mainBox, 0, 0 )

        self.show_all()

    def handleCheck(self, widget):
        ofile = open(Config.DATA_DIR + "/sounds_settings", 'a')
        name = self.nameEntry.get_text()
        if self.loopedSound:
            tied = str(Config.INST_TIED)
        else:
            tied = str(Config.INST_SIMP)
        register = str(self.register)
        melo = 'melo'
        category = 'mysounds'
        start = str(self.start)
        end = str(self.end)
        dur = str(self.dur)

        ofile.write(name + ' ' + tied + ' ' + register + ' ' + melo + ' ' + category + ' ' + start + ' ' + end + ' ' + dur + '\n')

        ofile.close()
        (s,o) = commands.getstatusoutput('cp ' + Config.DATA_DIR + '/' + self.oldName + ' ' + Config.DATA_DIR + '/' + name)
        self.doneLoopSettingsPopup()

    def set_name(self, name):
        self.oldName = name
        self.nameEntry.set_text('_' + name)

    def set_values(self, soundLength):
        self.soundLength = soundLength
        self.handleStart(self.GUI['startSlider'])
        self.handleEnd(self.GUI['endSlider'])

    def handleLooped(self, widget, data=None):
        if widget.get_active() == True:
            self.loopedSound = False
        else:
            self.loopedSound = True

    def categoryBtnPress(self, widget, event):
        if event.type == gtk.gdk.BUTTON_PRESS:
            widget.popup(None, None, None, event.button, event.time)
            return True
        return False

    def handleCategory(self, widget, category):
        self.category = category
        self.categoryButton.set_label(self.category)

    def registerBtnPress(self, widget, event):
        if event.type == gtk.gdk.BUTTON_PRESS:
            widget.popup(None, None, None, event.button, event.time)
            return True
        return False

    def handleRegister(self, widget, register):
        self.register = register
        self.registerButton.set_label(self.registerList[self.register])

    def handleStart(self, widget, data=None):
        self.startSlider = self.startAdjust.value
        self.start = self.startSlider * self.soundLength
        if self.start > self.end:
            self.start = self.end
        self.startEntry.set_text(str(self.start))
        self.setChannel('lstart', self.start)

    def handleEnd(self, widget, data=None):
        self.endSlider = self.endAdjust.value
        self.end = self.endSlider * self.soundLength
        if self.end < self.start:
            self.end = self.start
        self.endEntry.set_text(str(self.end))
        self.setChannel('lend', self.end)

    def handleDur(self, widget, data=None):
        self.dur = self.durAdjust.value
        self.durEntry.set_text(str(self.dur))
        self.setChannel('ldur', self.dur)

    def handlePlayButton(self, widget, data=None):
        if self.ok:
            self.playFunction(widget.get_active(), self.loopedSound)
            if self.loopedSound == False and widget.get_active() == False:
                self.timeoutStop = gobject.timeout_add(int(self.soundLength * 1000)+500, self.playButtonState)

    def setButtonState(self):
        self.ok = False
        self.playStopButton.set_active(False)
        self.ok = True

    def playButtonState(self):
        self.ok = False
        self.playStopButton.set_active(False)
        gobject.source_remove(self.timeoutStop)
        self.ok = True