def pymt_plugin_activate(w, ctx): # A global duration of -1 will make the sound last forever ounk.setGlobalDuration(-1) # We create buses that we will use to send control data ounk.oscReceive(bus=['amp0','amp1','amp2','amp3','pitch0','pitch1','pitch2','pitch3'], address=['/amp0','/amp1','/amp2','/amp3','/pitch0','/pitch1','/pitch2','/pitch3'], port = 9005, portamento = 0.05) # We create 4 sines and associate pitch variation and amplitude variation with the corresponding buses. ounk.sine(pitch=[1,1,1,1], pitchVar=['pitch0','pitch1','pitch2','pitch3'], amplitudeVar=['amp0','amp1','amp2','amp3']) # Csound is started here ounk.startCsound() ctx.c = MTWidget() window_size = w.get_size() size = (50,350) sliders = [] buttons = [] for widget in range(4): sliders.append(MTSlider(min = 100, max = 1000, pos = (window_size[0]*((widget + 1)/5.) - size[0]/2., 90), size = size)) buttons.append(MTButton(label = '', pos = (window_size[0]*((widget + 1)/5.) - size[0]/2., 30), size = (size[0], size[0]))) ctx.c.add_widget(sliders[widget]) ctx.c.add_widget(buttons[widget]) s1,s2,s3,s4 = sliders b1,b2,b3,b4 = buttons # This function gets called when a slider moves, it sets the pitch of each sine. def on_value_change_callback(slider, value): ounk.sendOscControl(value, address='/pitch%d' % slider, port=9005) # We push the handlers and feed it with the slider number so the callback function knows which sine to work on. # The time.sleep seems necessary to let Csound the time to initialize itself. for s in range(4): sliders[s].push_handlers(on_value_change = curry(on_value_change_callback, s)) time.sleep(2) sliders[s].value = 300 # When the button is pressed, the amplitude is changed to 0.5 def on_press_callback(btn, *largs): ounk.sendOscControl(0.5, address='/amp%d' % btn, port=9005) #print('Button {0} pressed'.format(btn+1)) # When the button is released, the amplitude goes back to 0 def on_release_callback(btn, *largs): ounk.sendOscControl(0, address='/amp%d' % btn, port=9005) #print('Button {0} released'.format(btn+1)) # Handlers for the buttons are pushed here. for b in range(4): buttons[b].push_handlers(on_press = curry(on_press_callback, b)) buttons[b].push_handlers(on_release = curry(on_release_callback, b)) w.add_widget(ctx.c)
def init_ounk(): global tt1, proc, pit1 ounk.setGlobalDuration(-1) env = ounk.genAdsr(release=0.8) tt1 = ounk.genDataTable([1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]) pit1 = ounk.genDataTable( [1, 1, 1, 1, .5, 1, 1, 1, .25, 1, 1, 1, .125, 1, 1, 1]) ounk.oscReceive(bus='tempo', address='/tempo', port=9005, portamento=0.05) ounk.metro(bus='metro', tempo=200, tempoVar='tempo') # solo sequence ounk.beginSequencer(input='metro', table=tt1) ounk.sequencerPitchTable(pit1) notes = 10 pitchs = [random.randint(180, 190) * 2 for x in range(notes)] durs = [random.randint(1, 15) * .05 for x in range(notes)] ounk.readTable(bus='index2', table=env, duration=durs[0]) ounk.freqMod(pitch=pitchs, modulator=0.502, amplitude=.07, starttime=0, duration=durs, envelope=env, pan=[0, .25, .5, .75, 1], index=10, indexVar='index2') ounk.endSequencer() proc = ounk.startCsound() time.sleep(1) ounk.sendOscControl(0.8, address='/tempo', port=9005)
def init_ounk(): global tt1, proc, pit1 ounk.setGlobalDuration(-1) env = ounk.genAdsr(release=0.8) tt1 = ounk.genDataTable([1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0]) pit1 = ounk.genDataTable([1,1,1,1,.5,1,1,1,.25,1,1,1,.125,1,1,1]) ounk.oscReceive(bus='tempo', address='/tempo', port = 9005, portamento = 0.05) ounk.metro(bus='metro', tempo=200, tempoVar = 'tempo') # solo sequence ounk.beginSequencer(input='metro', table=tt1) ounk.sequencerPitchTable(pit1) notes = 10 pitchs = [random.randint(180,190)*2 for x in range(notes)] durs = [random.randint(1,15)*.05 for x in range(notes)] ounk.readTable(bus='index2', table=env, duration=durs[0]) ounk.freqMod(pitch=pitchs, modulator=0.502, amplitude=.07, starttime=0, duration=durs, envelope=env, pan=[0,.25,.5,.75,1], index=10,indexVar='index2') ounk.endSequencer() proc = ounk.startCsound() time.sleep(1) ounk.sendOscControl(0.8, address='/tempo', port=9005)