| Hello,
I am slowly discovering the power of CsoundQt Python possibilities and would like to share some experiences.
It is probably obvious for many members of this mailing list but perhaps for others it can turn out useful.
Of course, your CsoundQt has to be compiled with PythonQt support (see http://sourceforge.net/apps/mediawiki/qutecsound/index.php?title=Building_with_PythonQt for some hints) to use these features.
1) Simple score generation
Many people say that they use python for generating the score. With the python console and python scratchpad of CsoundQt it has become very comfortable.
Let's say that you want to play instrument 1 many times during a timespan, with random start time, duration and other parameters.
CsoundQt python interpreter has predefined object q that can access the methods of PyQcsObject and you can do various useful things with it (see "Python Scripting in Csound" by Andrés Cabrera http://www.incontri.hmtm-hannover.de/fileadmin/www.incontri/Csound_Conference/Cabrera.pdf )
For score generation there are two useful methods: insertText and setSco:
q.insertText(text,index=-1,section=-1)
By default (if you don't set the index and section parameter), you can insert given text at the position of the cursor in active document. Like
q.insertText("f 0 3600")
With the index you can control to which open document and which section the text will be inserted (I have not tried out the section feature yet myself)
OR
you can use
q.setSco(text,index=-1)
to replace the whole score section between and
So you can write python lines
from random import random,randint
count=100
span=10
for i in range(0,count):
begin =random()*span
dur = random()*5+0.5
amp = randint(-30,-10)
freq = randint(50,800)
rise = random()*0.5
decay = random()*0.5
line = "i 1 %.4f %.4f %d %d %.4f %.4f\n" % (begin, dur, amp,freq,rise,decay)
#print line
q.insertText(line) # insert in the current position of curor in the editor window
to python scratchpad or save as an indepentent python script to your scripts folder and run from the menu Scripts.
you can use also setSco. Add
score=""
before the 'for' statement
score+=line
in the 'for' block
and
q.setSco(score)
after 'for', so it it will replace the whole score part every time the code is run.
2) very simple gui with PyuthonQt
Suppose you need to generate such scorelines more than once and and it would be handy to input some of the variables to a user interface.
For the most simple example about using the PythonQt abilities, let'c create a small popup that asks how many lines you want to generate (the variable 'count' in the previous example).
You can access all Qt classes through PythonQt module (see http://pythonqt.sourceforge.net/index.html ).
For simple input there is a class called Qt.QInputDialog http://developer.qt.nokia.com/doc/qt-4.8/qinputdialog.html
Without going more into the details, you need to add lines something like:
from PythonQt.Qt import *
inpdia=QInputDialog()
count=inpdia.getInt(inpdia,"Instances","How many instances:")
If you want to hear the sounding result immediately after pressing Enter in the dialog box, you can add
q.play()
as last line in your script or scratchpad code.
The python script and csd with the instrument are attached to the email
----
I really encourage people to compile CsoundQt with PythonQt support, try it out and give feedback to Andres Cabréra. There is so much to explore!
In next post: more on creating GUIs with PythonQt (I am no expert, just sharing some experiences).
greetings,
tarmo
Send bugs reports to the Sourceforge bug tracker
https://sourceforge.net/tracker/?group_id=81968&atid=564599
Discussions of bugs and features can be posted here
To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe csound"
|