[Qutecsound-users] CsoundQt examples 1: score generation, simplest gui

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Qutecsound-users] CsoundQt examples 1: score generation, simplest gui

tarmoj
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 <CsScore> and </CsScore>

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

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Qutecsound-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qutecsound-users

pluck.csd (5K) Download Attachment
simple-score-generation.py (583 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Qutecsound-users] CsoundQt examples 1: score generation, simplest gui

Andres Cabrera
Administrator
Hi Tarmo,

I'm very happy to hear this is being used and enjoyed, it was a lot of work!

Michael Gogins has built CsoundQt with python support, so Windows
users should be able to try this stuff without having to build
themselves. I hope to have an alpha version for OS X users very soon.

Some ideas:
The score generation can also be used in realtime if you send the text
as score events.

If you want to use Qt to build guis in CsoundQt, be sure to get the Qt
documentation. You might want to get the full SDK which contains the
documentation and QtAssistant, a standalone documentation browser.

Cheers,
Andrés

On Mon, Jan 9, 2012 at 8:21 AM, Tarmo Johannes <[hidden email]> wrote:

> 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 <CsScore> and </CsScore>
>
> 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
>
> ------------------------------------------------------------------------------
> Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
> infrastructure or vast IT resources to deliver seamless, secure access to
> virtual desktops. With this all-in-one solution, easily deploy virtual
> desktops for less than the cost of PCs and save 60% on VDI infrastructure
> costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
> _______________________________________________
> Qutecsound-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qutecsound-users
>

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Qutecsound-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qutecsound-users
Reply | Threaded
Open this post in threaded view
|

Re: [Qutecsound-users] CsoundQt examples 1: score generation, simplest gui

joachim-3
In reply to this post by tarmoj
hi tarmo -
thanks for the description. go on!
        joachim

Am 09.01.2012 09:21, schrieb Tarmo Johannes:

> 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 <CsScore> and </CsScore>
>
> 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
>
>
>
> ------------------------------------------------------------------------------
> Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
> infrastructure or vast IT resources to deliver seamless, secure access to
> virtual desktops. With this all-in-one solution, easily deploy virtual
> desktops for less than the cost of PCs and save 60% on VDI infrastructure
> costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
>
>
>
> _______________________________________________
> Qutecsound-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/qutecsound-users

------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Qutecsound-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qutecsound-users
Reply | Threaded
Open this post in threaded view
|

Re: [Qutecsound-users] CsoundQt examples 1: score generation, simplest gui

tarmoj
In reply to this post by Andres Cabrera
Thank you!

On Tuesday 10 January 2012 19:45:25 Andres Cabrera wrote:
> Some ideas:
> The score generation can also be used in realtime if you send the text
> as score events.


Right! if one would like to generate every time a different random music, it would make more sense not to write the score but send events with
q.sendEvent()

In this example once could add line
f 0 3600
to the score,

q.play()
to the beginning of the script and

q.sendEvent(line) to the body of the 'for' loop.

greetings,
tarmo

------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual
desktops for less than the cost of PCs and save 60% on VDI infrastructure
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Qutecsound-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/qutecsound-users