[Csnd] how to play 2 loops *one after another* from a .py file
Date | 2013-09-23 00:06 |
From | Pablo Frank |
Subject | [Csnd] how to play 2 loops *one after another* from a .py file |
Attachments | MY_notes3.py My_test3.csd One_loop.py My_notes4.py |
using this .py file: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; import time import csnd cs = csnd.Csound() cs.Compile("My_test3.csd") perf = csnd.CsoundPerformanceThread(cs) execfile("My_notes3.py") perf.Play() perf.Join() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; with the files My_test3.csd and My_notes3.py the loop in My_notes3.py is listened. If written: execfile("My_notes3.py") execfile("My_notes4.py") the two loops are listened simultaneously. If written the loops in the 2 files My_notes3.py and My_notes4.py in one file, also the loops are listened together. Some other possibilities were tried without success. Anybody knows what's the code to play one loop **after** another? Thanks in advance. |
Date | 2013-09-23 19:08 |
From | Steven Yi |
Subject | Re: [Csnd] how to play 2 loops *one after another* from a .py file |
Hi Pablo, The issue is that the two scripts you are using to generate notes use the same start times for the generated notes. Some comments: 1. Modify My_notes4.py to use something like: for i in range(1,5): perf.InputMessage("i 1 %d 1 %d"% (i + 7,i*70)) so that the start times of the generated notes start at 8. 2. You might consider removing the use of execfile and instead write the code in My_notes3.py and My_notes4.py as functions, i.e.: def algo2(perf): for i in range(1,5): perf.InputMessage("i 1 %d 1 %d"% (i + 7,i*70)) >From your main script, you could then do: from My_notes4 import algo2 ... algo2(perf) 3. Further, you might modify the functions to return a String that represents the generated score, then use that from the calling code and call perf.ReadScore(generatedScore). There's a lot further to go along these lines to encapsulate and modify the design to make it easier to reuse code. Hope that helps! steven On Sun, Sep 22, 2013 at 7:06 PM, Pablo Frank |