Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/filemixauto.py
blob: e0005299487168ec5742e3a2248f8ba45d26223f (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
# FILEMIXAUTO - Audio File Looper/Mixer/Processor for Children (2011)
# Art Hunkins (www.arthunkins.com)
#   
#    FileMixAuto is licensed under the Creative Commons Attribution-Share
#    Alike 3.0 Unported License. To view a copy of this license, visit
#    http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to
#    Creative Commons, 171 Second Street, Suite 300, San Francisco,
#    California, 94105, USA.
#
#    It is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# version 3  Changes:
#    Record Activity compatibility updated.


import csndsugui
import gobject
from sugar.activity import activity
from sugar.graphics.objectchooser import ObjectChooser
from sugar import mime
import gtk
import os

class FileMixAuto(activity.Activity):

 def __init__(self, handle):
  
   activity.Activity.__init__(self, handle)

   red = (0xDDDD, 0, 0)
   brown = (0x6600, 0, 0)
   green = (0, 0x5500, 0)
   self.path1 = "0"
   self.path2 = "0"
   self.path3 = "0"
   self.path4 = "0"
   self.jobject1 = None
   self.jobject2 = None
   self.jobject3 = None
   self.jobject4 = None

   win = csndsugui.CsoundGUI(self)
   width = gtk.gdk.screen_width()
   height = gtk.gdk.screen_height()
   if os.path.exists("/etc/olpc-release") or os.path.exists("/sys/power/olpc-pm"):
     adjust = 78
   else:
     adjust = 57
   screen = win.box()
   screen.set_size_request(width, height - adjust)
   scrolled = gtk.ScrolledWindow()
   scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
   screen.pack_start(scrolled)
   all = gtk.VBox()
   all.show()
   scrolled.add_with_viewport(all)
   scrolled.show()

   win.text("<big><b><big><u>FILEMIXAUTO</u> - Audio File Looper/Mixer/Processor \
for Children (2011)</big></b>\n\
\t\t\t\t    Art Hunkins (www.arthunkins.com)</big>", all)

   win.text("Loop and process 1 to 4 mono/stereo files; \
wav and ogg vorbis formats only (no ogg vorbis on Sugar 0.84).\n\
  User sound files must be placed in Journal (Record activity \
does this). <b>No user files on Sugar 0.82</b> (original XO-1).\n\
  The default files are abbreviated versions of those from the author's \
<b>DUSK AT ST. FRANCIS SPRINGS</b>.\n\
You are urged to create your own sound files suitable for looping, for example, \
with the Record activity - \n  especially nature soundscapes - to set a mood \
or accompany movement, drama, pantomime, etc.", all, brown)

   self.b2box = win.box(False, all)
   bbox = win.box(False, all)
   self.bb = bbox
   self.w = win
   self.r = red
   self.g = green
   self.br = brown
   self.p = False

   try:
     from jarabe import config
     version = [int(i) for i in config.version.split('.')][:2]
   except ImportError:
     version = [0, 82]
   if version >= [0, 84]:
     boxa = win.box(False, self.b2box)
     boxb = win.box(False, self.b2box)
     boxc = win.box(True, boxb)
     boxd = win.box(False, boxc)
     boxe = win.box(True, boxc)
     win.text("\t\tOptionally, select your own <b>audio</b> file(s) from the Journal.\n\
\t\tDeselect a file by choosing another, or by closing Journal.\n\
\t\tSuggestion: create files with Record v86, v90 or Audacity.       ", boxa, green)
     win.text("Select File(s):", boxd, brown)
     but5 = win.cbbutton(boxd, self.choose1, " 1 ")
     but5.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0x6600, 0, 0))
     but5.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0x6600, 0, 0))
     but6 = win.cbbutton(boxd, self.choose2, " 2 ")
     but6.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0x6600, 0, 0))
     but6.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0x6600, 0, 0))
     but7 = win.cbbutton(boxd, self.choose3, " 3 ")
     but7.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0x6600, 0, 0))
     but7.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0x6600, 0, 0))
     but8 = win.cbbutton(boxd, self.choose4, " 4 ")
     but8.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0x6600, 0, 0))
     but8.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0x6600, 0, 0))
     but9 = win.cbbutton(boxe, self.auto, " CLICK when selections made ")
     but9.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0x7700, 0))
     but9.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0, 0x7700, 0))
   else:
     self.auto(self)

 def choose1(self, widget):
   chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
   result = chooser.run()
   if result == gtk.RESPONSE_ACCEPT:
     self.jobject1 = chooser.get_selected_object()
     self.path1 = str(self.jobject1.get_file_path())
   else:
     self.jobject1 = None
     self.path1 = "0"

 def choose2(self, widget):
   chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
   result = chooser.run()
   if result == gtk.RESPONSE_ACCEPT:
     self.jobject2 = chooser.get_selected_object()
     self.path2 = str(self.jobject2.get_file_path())
   else:
     self.jobject2 = None
     self.path2 = "0"

 def choose3(self, widget):
   chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
   result = chooser.run()
   if result == gtk.RESPONSE_ACCEPT:
     self.jobject3 = chooser.get_selected_object()
     self.path3 = str(self.jobject3.get_file_path())
   else:
     self.jobject3 = None
     self.path3 = "0"

 def choose4(self, widget):
   chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
   result = chooser.run()
   if result == gtk.RESPONSE_ACCEPT:
     self.jobject4 = chooser.get_selected_object()
     self.path4 = str(self.jobject4.get_file_path())
   else:
     self.jobject4 = None
     self.path4 = "0"

 def send_data(self):  
   self.w.set_filechannel("file1", self.path1)
   self.w.set_filechannel("file2", self.path2)
   self.w.set_filechannel("file3", self.path3)
   self.w.set_filechannel("file4", self.path4)

 def playcsd(self, widget):
   def start(self):
     self.p = True
     self.w.play()
     gobject.timeout_add(500, checkstat)
     self.but.child.set_label("STOP !")
     self.but.child.set_use_markup(True)
     self.but.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0xFFFF, 0, 0))
     self.but.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0xFFFF, 0, 0))
   def stop(self):
     self.p = False
     self.w.recompile()
     self.w.channels_reinit()
     self.send_data()
     self.but.child.set_label("START !")
     self.but.child.set_use_markup(True)
     self.but.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0x7700, 0))
     self.but.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0, 0x7700, 0))
   def checkstat():
     if self.w.perf.GetStatus() == 2:
       stop(self)
     return True
   if self.p == False:
     start(self)
   else:
     stop(self)
 
 def auto(self, widget):
   self.b2box.destroy()
   self.box1 = self.w.box(True, self.bb)
   self.w.text("       ", self.box1)
   self.box2 = self.w.box(True, self.bb)
   self.f = self.w.framebox(" <b>FileMixAuto</b> - <i>Select Options First</i> ",\
False, self.box2, self.r)
   self.b1 = self.w.box(True, self.f)
   self.b2 = self.w.box(True, self.f)
   self.b3 = self.w.box(True, self.f)
   self.b4 = self.w.box(True, self.f)
   self.b5 = self.w.box(True, self.f)
   self.b6 = self.w.box(True, self.f)
   self.b7 = self.w.box(True, self.f)
   self.w.csd("FileMixAuto.csd")
   self.w.spin(4, 1, 4, 1, 1, self.b1, 0, "Files", "# of Files")
   self.w.spin(0, 0, 50, 1, 5, self.b1, 0, "RandRate", "Random Rate\n\
[0=no change]")
   self.w.spin(10, 0, 10, 1, 1, self.b2, 0, "MaxVol1", "Max Vol/File1 ")
   self.w.spin(10, 0, 10, 1, 1, self.b2, 0, "MaxVol2", "Max Vol/File2 \n\
   Random Vol") 
   self.w.spin(10, 0, 10, 1, 1, self.b3, 0, "MaxVol3", "Max Vol/File3 ")
   self.w.spin(10, 0, 10, 1, 1, self.b3, 0, "MaxVol4", " Max Vol/File4 \n\
is < Max Vol")
   self.w.spin(0, 0, 10, 1, 1, self.b4, 0, "RandVol", "Random Volume")
   self.w.spin(0, 0, 10, 1, 1, self.b4, 0, "RandPtch", "Random Pitch\n\
[+/- 10% max]")
   self.w.spin(0, 0, 10, 1, 1, self.b5, 0, "RandPeak", "Random Peak")
   self.w.spin(0, 0, 10, 1, 1, self.b5, 0, "RandFilt", "Random Filter")
   self.w.spin(0, -10, 10, 1, 1, self.b6, 0, "FiltShft", "Filter Center +/-")
   self.w.spin(5, -10, 60, 1, 10, self.b6, 0, "FadeDur", "   Fade Duration\n\
[+ = secs;- = mins]")
   self.dur = self.w.spin(1, -24, 60, 1, 10, self.b7, 0, "TotalDur",\
"  Total Duration\n[+ = mins;- = hrs;\n    0 = 30 secs]")
   self.send_data() 
   self.but = self.w.cbbutton(self.b7, self.playcsd, "START !")
   self.but.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0x7700, 0))
   self.but.modify_bg(gtk.STATE_PRELIGHT, gtk.gdk.Color(0, 0x7700, 0))