When using Scratchpad as a script editor, the run features are hidden. (They don't work correctly for user scripts; reload the page to rerun the script.) ( #1771 ) Script updates will detect Coral CDN failures and use direct checks instead.
- Interact Scratchpad 1.0.5 For Windows 7
- Interact Scratchpad 1.0.5 2
- Interact Scratchpad 1.0.5 Apk
- Interact Scratchpad 1.0.5 For Pc
- Interact Scratchpad 1.0.5 For Windows 10
- Dec 31, 2016 1.1.3.0 (9 September 2019) Maintenance Update ADDED Variable exports for left, standby, and right altimeter setting FIXED An issue causing valid legs to be incorrectly identified as duplicates and removed.This issue is responsible for the.
- Interact Scratchpad 1.0.5 (macOS) Interact Scratchpad 1.0.4 (Mac OS X) RocketStock - Carnage: 296 Blood Video Effects for Gory & Horror Scenes; RocketStock - Lucent Precise: 110 Blue-Hued Lens Flares.
ul'>
(This page has been taken from chapter 12C in the Csound FLOSS Manual.)
If CsoundQt is built with PythonQt support, it enables a lot of new possibilities, mostly in three main fields: interaction with the CsoundQt interface, interaction with widgets and using classes from Qt libraries to build custom interfaces in python.
If you start CsoundQt and can open the panels 'Python Console' and 'Python Scratch Pad', you are ready to go.
The CsoundQt Python Object
As CsoundQt has formerly been called QuteCsound, this name can still be found in the sources. The QuteCsound object (called PyQcsObject in the sources) is the interface for scripting CsoundQt. All declarations of the class can be found in the file pyqcsobject.h in the sources.
Interact Scratchpad 1.0.5 For Windows 7
It enables the control of a large part of CsoundQt's possibilities from the python interpreter, the python scratchpad, from scripts or from inside of a running Csound file via Csound's python opcodes.
By default, a PyQcsObject is already available in the python interpreter of CsoundQt called “q”. To use any of its methods, use form like
q.stopAll()
The methods can be divided into four groups:
- access CsoundQt's interface (open or close files, start or stop performance etc)
- edit Csound files which has already been opened as tabs in CsoundQt
- manage CsoundQt's widgets
- interface with the running Csound engine
File and Control Access
If you have CsoundQt running on your computer, you should type the following code examples in the Python Console (if only one line) or the Python Scratch Pad (if more than one line of code).
Create or Load a csd File
Type
q.newDocument('cs_floss_1.csd')
in your Python Console and hit the Return key. This will create a new csd file named 'cs_floss_1.csd' in your working directory. And it also returns an integer (in the screenshot below: 3) as index for this file. Pixelstyle photo editor 3.6.1. PixelStyle Photo Editor 3.6.1 – Design alternative to PhotoShop.Size: 21.13 MBPixelStyle, full-featured graphic-design app, offers an alternative to PhotoShop. It includes all the essential tools you need for professional photo editing.
If you close this file and then execute the line
q.loadDocument('cs_floss_1.csd')
, you should see the file again as tab in CsoundQt.Let us have a look how these two methods
newDocument
and loadDocument
are described in the sources:The method
newDocument
needs a name as string ('QString') as argument, and returns an integer. The method loadDocument
also takes a name as input string and returns an integer as index for this csd. The additional argument runNow
is optional. It expects a boolean value (True/False or 1/0). The default is 'false' which means 'do not run immediately after loading'. So if you type instead q.loadDocument('cs_floss_1.csd', True)
or q.loadDocument('cs_floss_1.csd', 1)
, the csd file should start immediately. Run, Pause or Stop a csd File
For the next methods, we first need some more code in our csd. So let your 'cs_floss_1.csd' look like this:
This instrument performs a simple pitch glissando from 500 to 1000 Hz in ten seconds. Now make sure that this csd is the currently active tab in CsoundQt, and execute this:
This starts the performance. If you do nothing, the performance will stop after ten seconds. If you type instead after some seconds
the performance will pause. The same task
q.pause()
will resume the performance. Note that this is different from executing q.play()
after q.pause()
; this will start a new performance. Withyou can stop the current performance.
Access to Different csd Tabs via Indices
The
play()
, pause()
and stop()
method, as well as other methods in CsoundQt's integrated Python, allow also to access csd file tabs which are not currently active. As we saw in the creation of a new csd file by q.newDocument('cs_floss_1.csd')
, each of them gets an index. This index allows universal access to all csd files in a running CsoundQt instance.First, create a new file 'cs_floss_2.csd', for instance with this code:
Now get the index of these two tabs in executing
q.getDocument('cs_floss_1.csd')
resp. q.getDocument('cs_floss_2.csd')
. This will show something like this:So in my case the indices are 3 and 4.5 Now you can start, pause and stop any of these files with tasks like these:
If you have checked 'Allow simultaneous play' in CsoundQt's Configure->General ..
. you should be able to run both csds simultaneously. To stop all running files, use:
To set a csd as active, use
setDocument(index)
. This will have the same effect as clicking on the tab.Send Score Events
Now comment out the score line in the file 'cs_floss_2.csd', or simply remove it. When you now start Csound, this tab should run. Now execute this command:
This should trigger instrument 1 for two seconds.
Query File Name or Path
In case you need to know the name or the path of a csd file, you have these functions:
Calling the method without any arguments, it refers to the currently active csd. An index as argument links to a specific tab. Here is a Python code snippet which returns indices, file names and file paths of all tabs in CsoundQt:
Which returns for instance:
index = 0 File Name = /home/jh/Joachim/Stuecke/30Carin/csound/130328.csd File Path = /home/jh/Joachim/Stuecke/30Carin/csound index = 1 File Name = /home/jh/src/csoundmanual/examples/transegr.csd File Path = /home/jh/src/csoundmanual/examples index = 2 File Name = /home/jh/Arbeitsfläche/test.csd File Path = /home/jh/Arbeitsfläche index = 3 File Name = /home/jh/Joachim/Csound/FLOSS/Release03/Chapter_12C_PythonInCsoundQt/cs_floss_1.csd File Path = /home/jh/Joachim/Csound/FLOSS/Release03/Chapter_12C_PythonInCsoundQt index = 4 File Name = /home/jh/Joachim/Csound/FLOSS/Release03/Chapter_12C_PythonInCsoundQt/cs_floss_2.csd File Path = /home/jh/Joachim/Csound/FLOSS/Release03/Chapter_12C_PythonInCsoundQt
index = 0 File Name = /home/jh/Joachim/Stuecke/30Carin/csound/130328.csd File Path = /home/jh/Joachim/Stuecke/30Carin/csound index = 1 File Name = /home/jh/src/csoundmanual/examples/transegr.csd File Path = /home/jh/src/csoundmanual/examples index = 2 File Name = /home/jh/Arbeitsfläche/test.csd File Path = /home/jh/Arbeitsfläche index = 3 File Name = /home/jh/Joachim/Csound/FLOSS/Release03/Chapter_12C_PythonInCsoundQt/cs_floss_1.csd File Path = /home/jh/Joachim/Csound/FLOSS/Release03/Chapter_12C_PythonInCsoundQt index = 4 File Name = /home/jh/Joachim/Csound/FLOSS/Release03/Chapter_12C_PythonInCsoundQt/cs_floss_2.csd File Path = /home/jh/Joachim/Csound/FLOSS/Release03/Chapter_12C_PythonInCsoundQt
Get and Set csd Text
One of the main features of Python scripting in CsoundQt is the ability to edit any section of a csd file. There are several 'get' functions, to query text, and also 'set' functions to change or insert text.
Get Text from a csd File
Make sure your 'cs_floss_2.csd' is the active tab, and execute the following python code lines:
The
q.getOrc()
task should return this:The u'..' indicates that a unicode string is returned. As usual in format expressions, newlines are indicated with the 'n' formatter.
Interact Scratchpad 1.0.5 2
You can also get the text for the CsOptions, the text for CsoundQt's widgets and presets, or the full text of this csd:
If you select some text or some widgets, you will get the selection with these commands:
As usual, you can specify any of the loaded csds via its index. So calling
q.getOrc(3)
instead of q.getOrc()
will return the orc text of the csd with index 3, instead of the orc text of the currently active csd. Set Text in a csd File
Set the cursor anywhere in your active csd, and execute the following line in the Python Console:
You will see your nice insertion in the csd file. In case you do not like it, you can choose Edit->Undo. It does not make a difference for the CsoundQt editor whether the text has been typed by hand, or by the internal Python script facility.
Text can also be inserted to individual sections using the functions:
Note that the whole section will be overwritten with the string text.
Opcode Exists
You can ask whether a string is an opcode name, or not, with the function opcodeExtists, for instance:
Example: Score Generation
A typical application for setting text in a csd is to generate a score. There have been numerous tools and programs to do this, and it can be very pleasant to use CsoundQt's Python scripting for this task. Let us modify our previous instrument first to make it more flexible:
The following code will now insert 30 score events in the score section:
This generates a texture with either falling or rising gliding pitches. The durations are set in a way that shorter durations are more frequently than larger ones. The volume and pitch ranges allow many variations in the simple shape.
Widgets
Creating a Label
Click on the 'Widgets' button to see the widgets panel. Then execute this command in the Python Console:
The properties dialog of the label pops up. Type 'Hello Label!' or something like this as text.
When you click 'Ok', you will see the label widget in the panel, and a strange unicode string as return value in the Python Console:
The string u'{3a171aa2-4cf8-4f05-9f30-172863909f56}' is a 'universally unique identifier' (uuid). Each widget can be accessed by this ID.
Specifying the Common Properties as Arguments
Instead of having a live talk with the properties dialog, we can specify all properties as arguments for the createNewLabel method:
This should be the result:
A new label has been created—without opening the properties dialog—at position x=200 y=1008 with the name 'second_label'. If you want to create a widget not in the active document, but in another tab, you can also specify the tab index. This command will create a widget at the same position and with the same name in the first tab:
Setting the Specific Properties
Each widget has a xy position and a channel name. But the other properties depend on the type of widget. A Display has name, width and height, but no resolution like a SpinBox. The function setWidgetProperty refers to a widget via its ID and sets a property. Let us try this for a Display widget. This command creates a Display widget with channel name 'disp_chan_01' at position x=50 y=150:
And this sets the text to a new string:
The
setWidgetProperty
method needs the ID of a widget first. This can be expressed either as channel name ('disp_chan_01') as in the command above, or as uuid. As I got the string u'{a71c0c67-3d54-4d4a-88e6-8df40070a7f5}' as uuid, I can also write:For humans, referring to the channel name as ID is probably preferable .. - But as the
createNew..
method returns the uuid, you can use it implicitely, for instance in this command:Getting the Property Names and Values
You may have asked how to know that the visible text of a Display widget is called 'QCS_label' and the fontsize 'QCS_fontsize'. If you do not know the name of a property, ask CsoundQt for it via the function
listWidgetProperties
:As you see, listWidgetProperties returns all properties in a tuple. You can query the value of a single property with the function getWidgetProperty, which takes the uuid and the property as inputs, and returns the property value. So this code snippet asks for all property values of our Display widget:
Returns: QCS_x = 50 QCS_y = 150 QCS_uuid = {a71c0c67-3d54-4d4a-88e6-8df40070a7f5} QCS_visible = True QCS_midichan = 0 QCS_midicc = -3 QCS_label = Hey Joeboe! QCS_alignment = left QCS_precision = 3 QCS_font = Arial QCS_fontsize = 10 QCS_bgcolor = #ffffff QCS_bgcolormode = False QCS_color = #000000 QCS_bordermode = border QCS_borderradius = 1 QCS_borderwidth = 1 QCS_width = 80 QCS_height = 25 QCS_objectName = disp_chan_01
Get the UUIDs of all Widgets
For getting the uuid strings of all widgets in the active csd tab, type
As always, the uuid strings of other csd tabs can be accessed via the index.
Some Examples for Creating and Modifying Widgets
Create a new slider with the channel name 'level' at position 10,10 in the (already open but not necessarily active) document 'test.csd':
Create ten knobs with the channel names 'partial_1', 'partial_2' etc, and the according labels 'amp_part_1', 'amp_part_2' etc in the currently active document:
Alternatively, you can store the uuid strings while creating:
The variables knobs and labels now contain the IDs:
Move the first knob 200 pixels downwards:
Modify the maximum of each knob so that the higher partials have less amplitude range (set maximum to 1, 0.9, 0.8, .., 0.1):
Deleting widgets
You can delete a widget using the method destroyWidget. You have to pass the widget's ID, again either as channel name or (better) as uuid string. This will remove the first knob in the example above:
This will delete all knobs:
And this will delete all widgets of the active document:
Interact Scratchpad 1.0.5 Apk
Getting and Setting Channel Names and Values
After this cruel act of destruction, let us again create a slider and a display:
Now we will ask for the values of these widgets with the methods getChannelValue and getChannelString:
Interact Scratchpad 1.0.5 For Pc
As you see, it depends on the type of the widget whether to query its value by getChannelValue or getChannelString. Although CsoundQt will not return an error, it makes no sense to ask a slider for its string (as its value is a number), and a display for its number (as its value is a string).
With the methods
setChannelValue
and setChannelString
we can change the main content of a widget very easily:This is much more handy than the general method using setWidgetProperty:
Presets
Now right-click in the widget panel and choose Store Preset -> New Preset:
You can (but need not) enter a name for the preset. The important thing here is the number of the preset (here 0). - Now change the value of the slider and the text of the display widget. Save again as preset, now being preset 1. - Now execute this:
You will see the content of the widgets reloaded to the first preset. Again, with
you can switch to the second one.
Like all python scripting functions in CsoundQt, you can not only use these methods from the Python Console or the Python Cratch Pad, but also from inside any csd. This is an example how to switch all the widgets to other predefined states, in this case controlled by the score. You will see the widgets for the first three seconds in Preset 0, then for the next three seconds in Preset 1, and finally again in Preset 0:
Csound Functions
Several functions can interact with the Csound engine, for example to query information about it. Note that the functions
getSampleRate
, getKsmps
, getNumChannels
and getCurrentCsound
refer to a running instance of Csound.With
getCsChannel
, getCsStringChannel
and setCsChannel
you can access csound channels directly, independently from widgets. They are useful when testing a csd for use with the Csound API (in another application, a csLapdsa or Cabbage plugin, Android application) or similar. These are some examples, executed on a running csd instance:If you have a function table in your running Csound instance which has for instance been created with the line
giSine ftgen 1, 0, 1024, 10, 1
, you can query getTableArray like this: Finally, you can register a Python function as a callback to be executed in between processing blocks for Csound. The first argument should be the text that should be called on every pass. It can include arguments or variables which will be evaluated every time. You can also set a number of periods to skip to avoid.
You can register the python text to be executed on every Csound control block callback, so you can execute a block of code, or call any function which is already defined.
Creating Own GUIs with PythonQt
One of the very powerful features of using Python inside CsoundQt is the ability to build own GUIs. This is done via the PythonQt library which gives you access to the Qt toolkit via Python. We will show some examples here. Have a look in the 'Scripts' menu in CsoundQt to find much more (you will find the code in the 'Editor' submenu).
Dialog Box
Sometimes it is practical to ask from user just one question - number or name of something and then execute the rest of the code (it can be done also inside a csd with python opcodes). In Qt, the class to create a dialog for one question is called QInputDialog.
To use this or any other Qt classes, it is necessary to import the PythonQt and its Qt submodules. In most cases it is enough to add this line:
or
At first an object of QInputDialog must be defined, then you can use its methods getInt, getDouble, getItem or getText to read the input in the form you need. This is a basic example:
Note that the variable myInt is now set to a value which remains in your Python interpreter. Your Python Console may look like this when executing the code above, and then ask for the value of myInt:
Depending on the value of myInt, you can do funny or serious things. This code re-creates the Dialog Box whenever the user enters the number 1:
This is a simple example showing how you can embed an own GUI in your Csound code. Here, Csound waits for the user input, and the prints out the entered value as the Csound variable giNumber:
Simple GUI with Buttons
The next example takes the user input (as a string) and transforms it to a sounding sequence of notes. First, make sure that the following csd is your active tab in CsoundQt:
Now copy this Python code into your Python Scratch Pad and evaluate it. Then type anything in the 'type here' box and push the 'insert' button. After pushing 'play', the string will be played. You can also send the string as real-time event, to different instruments, in different durations.
Another nice example of Tarmo Johannes, color-controller.py, is included in the CsoundQt application.