Csound Csound-dev Csound-tekno Search About

[Csnd-dev] Ctypes python wrapper to the Csound API

Date2016-03-02 20:06
FromFrancois PINOT
Subject[Csnd-dev] Ctypes python wrapper to the Csound API
I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound

It can work with python2 and python3 as well.

It's pure python and does not need any C compilation.

I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.

If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.

I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.

Francois

Date2016-03-02 20:23
FromMichael Gogins
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API

Thanks,  I will look at this, add it to the windows release if it looks good, perhaps suggest some changes.

Thanks,
Mike

On Mar 2, 2016 3:06 PM, "Francois PINOT" <fggpinot@gmail.com> wrote:
I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound

It can work with python2 and python3 as well.

It's pure python and does not need any C compilation.

I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.

If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.

I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.

Francois

Date2016-03-02 20:38
FromFrancois PINOT
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
I forgot an information: ctcsound.py depends on numpy. But you don't have do distribute numpy with it. numpy has just to be installed on the host computer, through anaconda or ipython for example.

2016-03-02 21:23 GMT+01:00 Michael Gogins <michael.gogins@gmail.com>:

Thanks,  I will look at this, add it to the windows release if it looks good, perhaps suggest some changes.

Thanks,
Mike

On Mar 2, 2016 3:06 PM, "Francois PINOT" <fggpinot@gmail.com> wrote:
I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound

It can work with python2 and python3 as well.

It's pure python and does not need any C compilation.

I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.

If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.

I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.

Francois


Date2016-03-02 20:59
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
I will try.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 2 Mar 2016, at 20:06, Francois PINOT  wrote:
> 
> I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> 
> It can work with python2 and python3 as well.
> 
> It's pure python and does not need any C compilation.
> 
> I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> 
> If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> 
> I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> 

Date2016-03-02 21:06
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
out the test. This is what I get

ligeti:ctcsound victor$ python test_ctcsound.py 
time resolution is 1000.000 ns
virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
.resetting Csound instance
end of score.		   overall amps:      0.0
	   overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
signalflowgraph: csoundModuleDestroy(0x1021ca800)
virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
UnifiedCSD:  analogSynth01.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: PortAudio module enabled ... 
using callback interface
rtmidi: PortMIDI module enabled
sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
sorting score ...
	... done
--Csound version 6.07 beta (double samples) Jan 26 2016
displays suppressed
0dBFS level = 1.0
orch now loaded
audio buffered in 1024 sample-frame blocks
PortAudio V19-devel (built Feb 12 2010 09:42:54)
   0: dac0 (AirPlay)
   1: dac1 (Built-in Output)
   2: dac2 (Soundflower (2ch))
   3: dac3 (Soundflower (64ch))
   4: dac4 (Aggregate Device)
PortAudio: selected output device 'Built-in Output'
writing 2048 sample blks of 64-bit floats to dac 
SECTION 1:
.virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
..virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
..virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
Module 0:pa_bl (audio)

Module 1:pa_cb (audio)

Module 2:jack (audio)

Module 3:auhal (audio)

Module 4:portmidi (midi)

Module 5:coremidi (midi)

.
----------------------------------------------------------------------
Ran 7 tests in 0.404s

OK
end of score.		   overall amps:      0.0
	   overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
inactive allocs returned to freespace
end of score.		   overall amps:  0.00000  0.00000
	   overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
end of score.		   overall amps:      0.0
	   overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
inactive allocs returned to freespace
end of score.		   overall amps:  0.00000  0.00000
	   overall samples out of range:        0        0
0 errors in performance
closing device
0 2048 sample blks of 64-bit floats written to dac
=============

Does it look correct to you?


========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 2 Mar 2016, at 20:06, Francois PINOT  wrote:
> 
> I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> 
> It can work with python2 and python3 as well.
> 
> It's pure python and does not need any C compilation.
> 
> I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> 
> If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> 
> I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> 

Date2016-03-02 21:11
FromFrancois PINOT
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?

2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
out the test. This is what I get

ligeti:ctcsound victor$ python test_ctcsound.py
time resolution is 1000.000 ns
virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
.resetting Csound instance
end of score.              overall amps:      0.0
           overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
signalflowgraph: csoundModuleDestroy(0x1021ca800)
virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
UnifiedCSD:  analogSynth01.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: PortAudio module enabled ...
using callback interface
rtmidi: PortMIDI module enabled
sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
sorting score ...
        ... done
--Csound version 6.07 beta (double samples) Jan 26 2016
displays suppressed
0dBFS level = 1.0
orch now loaded
audio buffered in 1024 sample-frame blocks
PortAudio V19-devel (built Feb 12 2010 09:42:54)
   0: dac0 (AirPlay)
   1: dac1 (Built-in Output)
   2: dac2 (Soundflower (2ch))
   3: dac3 (Soundflower (64ch))
   4: dac4 (Aggregate Device)
PortAudio: selected output device 'Built-in Output'
writing 2048 sample blks of 64-bit floats to dac
SECTION 1:
.virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
..virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
..virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
Module 0:pa_bl (audio)

Module 1:pa_cb (audio)

Module 2:jack (audio)

Module 3:auhal (audio)

Module 4:portmidi (midi)

Module 5:coremidi (midi)

.
----------------------------------------------------------------------
Ran 7 tests in 0.404s

OK
end of score.              overall amps:      0.0
           overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
inactive allocs returned to freespace
end of score.              overall amps:  0.00000  0.00000
           overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
end of score.              overall amps:      0.0
           overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
inactive allocs returned to freespace
end of score.              overall amps:  0.00000  0.00000
           overall samples out of range:        0        0
0 errors in performance
closing device
0 2048 sample blks of 64-bit floats written to dac
=============

Does it look correct to you?


========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
>
> I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
>
> It can work with python2 and python3 as well.
>
> It's pure python and does not need any C compilation.
>
> I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
>
> If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
>
> I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
>
> Francois


Date2016-03-02 21:26
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
That's what I have to work out. The library is installed in the CsoundLib64.framework, but the framework can be in different places if we build  it from sources or installing binaries. 

Not sure if dlopen() looks for it in standard places or not. I will try to find out

Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland

On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:

Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?

2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
out the test. This is what I get

ligeti:ctcsound victor$ python test_ctcsound.py
time resolution is 1000.000 ns
virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
.resetting Csound instance
end of score.              overall amps:      0.0
           overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
signalflowgraph: csoundModuleDestroy(0x1021ca800)
virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
UnifiedCSD:  analogSynth01.csd
STARTING FILE
Creating options
Creating orchestra
Creating score
rtaudio: PortAudio module enabled ...
using callback interface
rtmidi: PortMIDI module enabled
sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
sorting score ...
        ... done
--Csound version 6.07 beta (double samples) Jan 26 2016
displays suppressed
0dBFS level = 1.0
orch now loaded
audio buffered in 1024 sample-frame blocks
PortAudio V19-devel (built Feb 12 2010 09:42:54)
   0: dac0 (AirPlay)
   1: dac1 (Built-in Output)
   2: dac2 (Soundflower (2ch))
   3: dac3 (Soundflower (64ch))
   4: dac4 (Aggregate Device)
PortAudio: selected output device 'Built-in Output'
writing 2048 sample blks of 64-bit floats to dac
SECTION 1:
.virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
..virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
..virtual_keyboard real time MIDI plugin for Csound
WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
(points to rawwaves directory) to use STK opcodes.
0dBFS level = 32768.0
Csound version 6.07 beta (double samples) Jan 26 2016
libsndfile-1.0.21
Module 0:pa_bl (audio)

Module 1:pa_cb (audio)

Module 2:jack (audio)

Module 3:auhal (audio)

Module 4:portmidi (midi)

Module 5:coremidi (midi)

.
----------------------------------------------------------------------
Ran 7 tests in 0.404s

OK
end of score.              overall amps:      0.0
           overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
inactive allocs returned to freespace
end of score.              overall amps:  0.00000  0.00000
           overall samples out of range:        0        0
0 errors in performance
Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
end of score.              overall amps:      0.0
           overall samples out of range:        0
0 errors in performance
Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
inactive allocs returned to freespace
end of score.              overall amps:  0.00000  0.00000
           overall samples out of range:        0        0
0 errors in performance
closing device
0 2048 sample blks of 64-bit floats written to dac
=============

Does it look correct to you?


========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
>
> I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
>
> It can work with python2 and python3 as well.
>
> It's pure python and does not need any C compilation.
>
> I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
>
> If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
>
> I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
>
> Francois


Date2016-03-02 21:32
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
Just tested it and python CDLL seems to look for the framework correctly.
So this works

elif sys.platform.startswith('darwin'):
    libcsound = CDLL("CsoundLib64.framework/CsoundLib64")

Great job, François. This is excellent. 
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 2 Mar 2016, at 21:26, Victor Lazzarini  wrote:
> 
> That's what I have to work out. The library is installed in the CsoundLib64.framework, but the framework can be in different places if we build  it from sources or installing binaries. 
> 
> Not sure if dlopen() looks for it in standard places or not. I will try to find out
> 
> Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy
> Maynooth University
> Ireland
> 
> On 2 Mar 2016, at 21:11, Francois PINOT  wrote:
> 
>> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>> 
>> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini :
>> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
>> out the test. This is what I get
>> 
>> ligeti:ctcsound victor$ python test_ctcsound.py
>> time resolution is 1000.000 ns
>> virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> .resetting Csound instance
>> end of score.              overall amps:      0.0
>>            overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
>> signalflowgraph: csoundModuleDestroy(0x1021ca800)
>> virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> UnifiedCSD:  analogSynth01.csd
>> STARTING FILE
>> Creating options
>> Creating orchestra
>> Creating score
>> rtaudio: PortAudio module enabled ...
>> using callback interface
>> rtmidi: PortMIDI module enabled
>> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
>> sorting score ...
>>         ... done
>> --Csound version 6.07 beta (double samples) Jan 26 2016
>> displays suppressed
>> 0dBFS level = 1.0
>> orch now loaded
>> audio buffered in 1024 sample-frame blocks
>> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>>    0: dac0 (AirPlay)
>>    1: dac1 (Built-in Output)
>>    2: dac2 (Soundflower (2ch))
>>    3: dac3 (Soundflower (64ch))
>>    4: dac4 (Aggregate Device)
>> PortAudio: selected output device 'Built-in Output'
>> writing 2048 sample blks of 64-bit floats to dac
>> SECTION 1:
>> .virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> ..virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> ..virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> Module 0:pa_bl (audio)
>> 
>> Module 1:pa_cb (audio)
>> 
>> Module 2:jack (audio)
>> 
>> Module 3:auhal (audio)
>> 
>> Module 4:portmidi (midi)
>> 
>> Module 5:coremidi (midi)
>> 
>> .
>> ----------------------------------------------------------------------
>> Ran 7 tests in 0.404s
>> 
>> OK
>> end of score.              overall amps:      0.0
>>            overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
>> inactive allocs returned to freespace
>> end of score.              overall amps:  0.00000  0.00000
>>            overall samples out of range:        0        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
>> end of score.              overall amps:      0.0
>>            overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
>> inactive allocs returned to freespace
>> end of score.              overall amps:  0.00000  0.00000
>>            overall samples out of range:        0        0
>> 0 errors in performance
>> closing device
>> 0 2048 sample blks of 64-bit floats written to dac
>> =============
>> 
>> Does it look correct to you?
>> 
>> 
>> ========================
>> Dr Victor Lazzarini
>> Dean of Arts, Celtic Studies and Philosophy,
>> Maynooth University,
>> Maynooth, Co Kildare, Ireland
>> Tel: 00 353 7086936
>> Fax: 00 353 1 7086952
>> 
>> > On 2 Mar 2016, at 20:06, Francois PINOT  wrote:
>> >
>> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
>> >
>> > It can work with python2 and python3 as well.
>> >
>> > It's pure python and does not need any C compilation.
>> >
>> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
>> >
>> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
>> >
>> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
>> >
>> > Francois

Date2016-03-02 21:34
FromVictor Lazzarini
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
By the way, it would be useful to wrap the CsoundPerformanceThread class as well, so we have
a means to do processing in a separate thread without getting caught up by the GIL.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952 

> On 2 Mar 2016, at 21:11, Francois PINOT  wrote:
> 
> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
> 
> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini :
> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
> out the test. This is what I get
> 
> ligeti:ctcsound victor$ python test_ctcsound.py
> time resolution is 1000.000 ns
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> .resetting Csound instance
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
> signalflowgraph: csoundModuleDestroy(0x1021ca800)
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> UnifiedCSD:  analogSynth01.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> rtaudio: PortAudio module enabled ...
> using callback interface
> rtmidi: PortMIDI module enabled
> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
> sorting score ...
>         ... done
> --Csound version 6.07 beta (double samples) Jan 26 2016
> displays suppressed
> 0dBFS level = 1.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>    0: dac0 (AirPlay)
>    1: dac1 (Built-in Output)
>    2: dac2 (Soundflower (2ch))
>    3: dac3 (Soundflower (64ch))
>    4: dac4 (Aggregate Device)
> PortAudio: selected output device 'Built-in Output'
> writing 2048 sample blks of 64-bit floats to dac
> SECTION 1:
> .virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> Module 0:pa_bl (audio)
> 
> Module 1:pa_cb (audio)
> 
> Module 2:jack (audio)
> 
> Module 3:auhal (audio)
> 
> Module 4:portmidi (midi)
> 
> Module 5:coremidi (midi)
> 
> .
> ----------------------------------------------------------------------
> Ran 7 tests in 0.404s
> 
> OK
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> closing device
> 0 2048 sample blks of 64-bit floats written to dac
> =============
> 
> Does it look correct to you?
> 
> 
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
> 
> > On 2 Mar 2016, at 20:06, Francois PINOT  wrote:
> >
> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> >
> > It can work with python2 and python3 as well.
> >
> > It's pure python and does not need any C compilation.
> >
> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> >
> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> >
> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> >
> > Francois

Date2016-03-02 21:35
FromFrancois PINOT
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
Thanks, Victor. I updated the github source accordingly.

2016-03-02 22:32 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
Just tested it and python CDLL seems to look for the framework correctly.
So this works

elif sys.platform.startswith('darwin'):
    libcsound = CDLL("CsoundLib64.framework/CsoundLib64")

Great job, François. This is excellent.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:26, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
>
> That's what I have to work out. The library is installed in the CsoundLib64.framework, but the framework can be in different places if we build  it from sources or installing binaries.
>
> Not sure if dlopen() looks for it in standard places or not. I will try to find out
>
> Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy
> Maynooth University
> Ireland
>
> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
>> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>>
>> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
>> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
>> out the test. This is what I get
>>
>> ligeti:ctcsound victor$ python test_ctcsound.py
>> time resolution is 1000.000 ns
>> virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> .resetting Csound instance
>> end of score.              overall amps:      0.0
>>            overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
>> signalflowgraph: csoundModuleDestroy(0x1021ca800)
>> virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> UnifiedCSD:  analogSynth01.csd
>> STARTING FILE
>> Creating options
>> Creating orchestra
>> Creating score
>> rtaudio: PortAudio module enabled ...
>> using callback interface
>> rtmidi: PortMIDI module enabled
>> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
>> sorting score ...
>>         ... done
>> --Csound version 6.07 beta (double samples) Jan 26 2016
>> displays suppressed
>> 0dBFS level = 1.0
>> orch now loaded
>> audio buffered in 1024 sample-frame blocks
>> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>>    0: dac0 (AirPlay)
>>    1: dac1 (Built-in Output)
>>    2: dac2 (Soundflower (2ch))
>>    3: dac3 (Soundflower (64ch))
>>    4: dac4 (Aggregate Device)
>> PortAudio: selected output device 'Built-in Output'
>> writing 2048 sample blks of 64-bit floats to dac
>> SECTION 1:
>> .virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> ..virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> ..virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> Module 0:pa_bl (audio)
>>
>> Module 1:pa_cb (audio)
>>
>> Module 2:jack (audio)
>>
>> Module 3:auhal (audio)
>>
>> Module 4:portmidi (midi)
>>
>> Module 5:coremidi (midi)
>>
>> .
>> ----------------------------------------------------------------------
>> Ran 7 tests in 0.404s
>>
>> OK
>> end of score.              overall amps:      0.0
>>            overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
>> inactive allocs returned to freespace
>> end of score.              overall amps:  0.00000  0.00000
>>            overall samples out of range:        0        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
>> end of score.              overall amps:      0.0
>>            overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
>> inactive allocs returned to freespace
>> end of score.              overall amps:  0.00000  0.00000
>>            overall samples out of range:        0        0
>> 0 errors in performance
>> closing device
>> 0 2048 sample blks of 64-bit floats written to dac
>> =============
>>
>> Does it look correct to you?
>>
>>
>> ========================
>> Dr Victor Lazzarini
>> Dean of Arts, Celtic Studies and Philosophy,
>> Maynooth University,
>> Maynooth, Co Kildare, Ireland
>> Tel: 00 353 7086936
>> Fax: 00 353 1 7086952
>>
>> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
>> >
>> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
>> >
>> > It can work with python2 and python3 as well.
>> >
>> > It's pure python and does not need any C compilation.
>> >
>> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
>> >
>> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
>> >
>> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
>> >
>> > Francois
>>


Date2016-03-02 21:37
FromAndres Cabrera
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
Hi Francois,

I've done some of the wrapping of the CsoundPerformanceThread in icsound.py (some of it is based on your previous work).

Cheers,
Andrés

On Wed, Mar 2, 2016 at 1:35 PM, Francois PINOT <fggpinot@gmail.com> wrote:
Thanks, Victor. I updated the github source accordingly.

2016-03-02 22:32 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
Just tested it and python CDLL seems to look for the framework correctly.
So this works

elif sys.platform.startswith('darwin'):
    libcsound = CDLL("CsoundLib64.framework/CsoundLib64")

Great job, François. This is excellent.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:26, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
>
> That's what I have to work out. The library is installed in the CsoundLib64.framework, but the framework can be in different places if we build  it from sources or installing binaries.
>
> Not sure if dlopen() looks for it in standard places or not. I will try to find out
>
> Victor Lazzarini
> Dean of Arts, Celtic Studies, and Philosophy
> Maynooth University
> Ireland
>
> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
>> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>>
>> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
>> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
>> out the test. This is what I get
>>
>> ligeti:ctcsound victor$ python test_ctcsound.py
>> time resolution is 1000.000 ns
>> virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> .resetting Csound instance
>> end of score.              overall amps:      0.0
>>            overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
>> signalflowgraph: csoundModuleDestroy(0x1021ca800)
>> virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> UnifiedCSD:  analogSynth01.csd
>> STARTING FILE
>> Creating options
>> Creating orchestra
>> Creating score
>> rtaudio: PortAudio module enabled ...
>> using callback interface
>> rtmidi: PortMIDI module enabled
>> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
>> sorting score ...
>>         ... done
>> --Csound version 6.07 beta (double samples) Jan 26 2016
>> displays suppressed
>> 0dBFS level = 1.0
>> orch now loaded
>> audio buffered in 1024 sample-frame blocks
>> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>>    0: dac0 (AirPlay)
>>    1: dac1 (Built-in Output)
>>    2: dac2 (Soundflower (2ch))
>>    3: dac3 (Soundflower (64ch))
>>    4: dac4 (Aggregate Device)
>> PortAudio: selected output device 'Built-in Output'
>> writing 2048 sample blks of 64-bit floats to dac
>> SECTION 1:
>> .virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> ..virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> ..virtual_keyboard real time MIDI plugin for Csound
>> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
>> (points to rawwaves directory) to use STK opcodes.
>> 0dBFS level = 32768.0
>> Csound version 6.07 beta (double samples) Jan 26 2016
>> libsndfile-1.0.21
>> Module 0:pa_bl (audio)
>>
>> Module 1:pa_cb (audio)
>>
>> Module 2:jack (audio)
>>
>> Module 3:auhal (audio)
>>
>> Module 4:portmidi (midi)
>>
>> Module 5:coremidi (midi)
>>
>> .
>> ----------------------------------------------------------------------
>> Ran 7 tests in 0.404s
>>
>> OK
>> end of score.              overall amps:      0.0
>>            overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
>> inactive allocs returned to freespace
>> end of score.              overall amps:  0.00000  0.00000
>>            overall samples out of range:        0        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
>> end of score.              overall amps:      0.0
>>            overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
>> inactive allocs returned to freespace
>> end of score.              overall amps:  0.00000  0.00000
>>            overall samples out of range:        0        0
>> 0 errors in performance
>> closing device
>> 0 2048 sample blks of 64-bit floats written to dac
>> =============
>>
>> Does it look correct to you?
>>
>>
>> ========================
>> Dr Victor Lazzarini
>> Dean of Arts, Celtic Studies and Philosophy,
>> Maynooth University,
>> Maynooth, Co Kildare, Ireland
>> Tel: 00 353 7086936
>> Fax: 00 353 1 7086952
>>
>> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
>> >
>> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
>> >
>> > It can work with python2 and python3 as well.
>> >
>> > It's pure python and does not need any C compilation.
>> >
>> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
>> >
>> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
>> >
>> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
>> >
>> > Francois
>>



Date2016-03-02 21:45
FromFrancois PINOT
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
To wrap the CsoundPerformanceThread class we would need some intermediate C code because ctypes cannot deal directly with C++. That's what is done by swig.

Normally, ctypes releases the GIL during C function calls (see http://www.caswenson.com/2009_06_13_bypassing_the_python_gil_with_ctypes). This should allow us to use the threading functions of the API to get the same result than using CsoundPerformanceThread, keeping ctcsound.py pure python.

I'll investigate this in the Jupyter notebook I'm working on.

2016-03-02 22:34 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
By the way, it would be useful to wrap the CsoundPerformanceThread class as well, so we have
a means to do processing in a separate thread without getting caught up by the GIL.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>
> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
> out the test. This is what I get
>
> ligeti:ctcsound victor$ python test_ctcsound.py
> time resolution is 1000.000 ns
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> .resetting Csound instance
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
> signalflowgraph: csoundModuleDestroy(0x1021ca800)
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> UnifiedCSD:  analogSynth01.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> rtaudio: PortAudio module enabled ...
> using callback interface
> rtmidi: PortMIDI module enabled
> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
> sorting score ...
>         ... done
> --Csound version 6.07 beta (double samples) Jan 26 2016
> displays suppressed
> 0dBFS level = 1.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>    0: dac0 (AirPlay)
>    1: dac1 (Built-in Output)
>    2: dac2 (Soundflower (2ch))
>    3: dac3 (Soundflower (64ch))
>    4: dac4 (Aggregate Device)
> PortAudio: selected output device 'Built-in Output'
> writing 2048 sample blks of 64-bit floats to dac
> SECTION 1:
> .virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> Module 0:pa_bl (audio)
>
> Module 1:pa_cb (audio)
>
> Module 2:jack (audio)
>
> Module 3:auhal (audio)
>
> Module 4:portmidi (midi)
>
> Module 5:coremidi (midi)
>
> .
> ----------------------------------------------------------------------
> Ran 7 tests in 0.404s
>
> OK
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> closing device
> 0 2048 sample blks of 64-bit floats written to dac
> =============
>
> Does it look correct to you?
>
>
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
> >
> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> >
> > It can work with python2 and python3 as well.
> >
> > It's pure python and does not need any C compilation.
> >
> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> >
> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> >
> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> >
> > Francois
>


Date2016-03-02 21:47
FromAndres Cabrera
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
Yes. Right! Ther emight still be some useful code in icsound. I remember I had to write some code to copy tables to and frim numpy arrays (But perhaps you have done that already?)

Cheers,
Andrés

On Wed, Mar 2, 2016 at 1:45 PM, Francois PINOT <fggpinot@gmail.com> wrote:
To wrap the CsoundPerformanceThread class we would need some intermediate C code because ctypes cannot deal directly with C++. That's what is done by swig.

Normally, ctypes releases the GIL during C function calls (see http://www.caswenson.com/2009_06_13_bypassing_the_python_gil_with_ctypes). This should allow us to use the threading functions of the API to get the same result than using CsoundPerformanceThread, keeping ctcsound.py pure python.

I'll investigate this in the Jupyter notebook I'm working on.

2016-03-02 22:34 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
By the way, it would be useful to wrap the CsoundPerformanceThread class as well, so we have
a means to do processing in a separate thread without getting caught up by the GIL.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>
> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
> out the test. This is what I get
>
> ligeti:ctcsound victor$ python test_ctcsound.py
> time resolution is 1000.000 ns
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> .resetting Csound instance
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
> signalflowgraph: csoundModuleDestroy(0x1021ca800)
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> UnifiedCSD:  analogSynth01.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> rtaudio: PortAudio module enabled ...
> using callback interface
> rtmidi: PortMIDI module enabled
> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
> sorting score ...
>         ... done
> --Csound version 6.07 beta (double samples) Jan 26 2016
> displays suppressed
> 0dBFS level = 1.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>    0: dac0 (AirPlay)
>    1: dac1 (Built-in Output)
>    2: dac2 (Soundflower (2ch))
>    3: dac3 (Soundflower (64ch))
>    4: dac4 (Aggregate Device)
> PortAudio: selected output device 'Built-in Output'
> writing 2048 sample blks of 64-bit floats to dac
> SECTION 1:
> .virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> Module 0:pa_bl (audio)
>
> Module 1:pa_cb (audio)
>
> Module 2:jack (audio)
>
> Module 3:auhal (audio)
>
> Module 4:portmidi (midi)
>
> Module 5:coremidi (midi)
>
> .
> ----------------------------------------------------------------------
> Ran 7 tests in 0.404s
>
> OK
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> closing device
> 0 2048 sample blks of 64-bit floats written to dac
> =============
>
> Does it look correct to you?
>
>
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
> >
> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> >
> > It can work with python2 and python3 as well.
> >
> > It's pure python and does not need any C compilation.
> >
> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> >
> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> >
> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> >
> > Francois
>



Date2016-03-02 21:57
FromFrancois PINOT
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
I cast the pointer returned by the API to the data pointer of an numpy array so that the numpy array points directly to the csound memory (see lines 2070 to 2082 in ctcsound.py). I do the same for input and output buffers, and spin and spout.

2016-03-02 22:47 GMT+01:00 Andres Cabrera <mantaraya36@gmail.com>:
Yes. Right! Ther emight still be some useful code in icsound. I remember I had to write some code to copy tables to and frim numpy arrays (But perhaps you have done that already?)

Cheers,
Andrés

On Wed, Mar 2, 2016 at 1:45 PM, Francois PINOT <fggpinot@gmail.com> wrote:
To wrap the CsoundPerformanceThread class we would need some intermediate C code because ctypes cannot deal directly with C++. That's what is done by swig.

Normally, ctypes releases the GIL during C function calls (see http://www.caswenson.com/2009_06_13_bypassing_the_python_gil_with_ctypes). This should allow us to use the threading functions of the API to get the same result than using CsoundPerformanceThread, keeping ctcsound.py pure python.

I'll investigate this in the Jupyter notebook I'm working on.

2016-03-02 22:34 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
By the way, it would be useful to wrap the CsoundPerformanceThread class as well, so we have
a means to do processing in a separate thread without getting caught up by the GIL.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>
> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
> out the test. This is what I get
>
> ligeti:ctcsound victor$ python test_ctcsound.py
> time resolution is 1000.000 ns
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> .resetting Csound instance
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
> signalflowgraph: csoundModuleDestroy(0x1021ca800)
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> UnifiedCSD:  analogSynth01.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> rtaudio: PortAudio module enabled ...
> using callback interface
> rtmidi: PortMIDI module enabled
> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
> sorting score ...
>         ... done
> --Csound version 6.07 beta (double samples) Jan 26 2016
> displays suppressed
> 0dBFS level = 1.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>    0: dac0 (AirPlay)
>    1: dac1 (Built-in Output)
>    2: dac2 (Soundflower (2ch))
>    3: dac3 (Soundflower (64ch))
>    4: dac4 (Aggregate Device)
> PortAudio: selected output device 'Built-in Output'
> writing 2048 sample blks of 64-bit floats to dac
> SECTION 1:
> .virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> Module 0:pa_bl (audio)
>
> Module 1:pa_cb (audio)
>
> Module 2:jack (audio)
>
> Module 3:auhal (audio)
>
> Module 4:portmidi (midi)
>
> Module 5:coremidi (midi)
>
> .
> ----------------------------------------------------------------------
> Ran 7 tests in 0.404s
>
> OK
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> closing device
> 0 2048 sample blks of 64-bit floats written to dac
> =============
>
> Does it look correct to you?
>
>
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
> >
> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> >
> > It can work with python2 and python3 as well.
> >
> > It's pure python and does not need any C compilation.
> >
> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> >
> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> >
> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> >
> > Francois
>




Date2016-03-03 02:14
FromAndres Cabrera
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
Ah! That's nice.

Cheers,
Andrés

On Wed, Mar 2, 2016 at 1:57 PM, Francois PINOT <fggpinot@gmail.com> wrote:
I cast the pointer returned by the API to the data pointer of an numpy array so that the numpy array points directly to the csound memory (see lines 2070 to 2082 in ctcsound.py). I do the same for input and output buffers, and spin and spout.

2016-03-02 22:47 GMT+01:00 Andres Cabrera <mantaraya36@gmail.com>:
Yes. Right! Ther emight still be some useful code in icsound. I remember I had to write some code to copy tables to and frim numpy arrays (But perhaps you have done that already?)

Cheers,
Andrés

On Wed, Mar 2, 2016 at 1:45 PM, Francois PINOT <fggpinot@gmail.com> wrote:
To wrap the CsoundPerformanceThread class we would need some intermediate C code because ctypes cannot deal directly with C++. That's what is done by swig.

Normally, ctypes releases the GIL during C function calls (see http://www.caswenson.com/2009_06_13_bypassing_the_python_gil_with_ctypes). This should allow us to use the threading functions of the API to get the same result than using CsoundPerformanceThread, keeping ctcsound.py pure python.

I'll investigate this in the Jupyter notebook I'm working on.

2016-03-02 22:34 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
By the way, it would be useful to wrap the CsoundPerformanceThread class as well, so we have
a means to do processing in a separate thread without getting caught up by the GIL.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>
> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
> out the test. This is what I get
>
> ligeti:ctcsound victor$ python test_ctcsound.py
> time resolution is 1000.000 ns
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> .resetting Csound instance
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
> signalflowgraph: csoundModuleDestroy(0x1021ca800)
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> UnifiedCSD:  analogSynth01.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> rtaudio: PortAudio module enabled ...
> using callback interface
> rtmidi: PortMIDI module enabled
> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
> sorting score ...
>         ... done
> --Csound version 6.07 beta (double samples) Jan 26 2016
> displays suppressed
> 0dBFS level = 1.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>    0: dac0 (AirPlay)
>    1: dac1 (Built-in Output)
>    2: dac2 (Soundflower (2ch))
>    3: dac3 (Soundflower (64ch))
>    4: dac4 (Aggregate Device)
> PortAudio: selected output device 'Built-in Output'
> writing 2048 sample blks of 64-bit floats to dac
> SECTION 1:
> .virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> Module 0:pa_bl (audio)
>
> Module 1:pa_cb (audio)
>
> Module 2:jack (audio)
>
> Module 3:auhal (audio)
>
> Module 4:portmidi (midi)
>
> Module 5:coremidi (midi)
>
> .
> ----------------------------------------------------------------------
> Ran 7 tests in 0.404s
>
> OK
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> closing device
> 0 2048 sample blks of 64-bit floats written to dac
> =============
>
> Does it look correct to you?
>
>
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
> >
> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> >
> > It can work with python2 and python3 as well.
> >
> > It's pure python and does not need any C compilation.
> >
> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> >
> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> >
> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> >
> > Francois
>





Date2016-03-03 06:39
FromMichael Gogins
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API

That is nice. So does this work for array variables as well?

Regards,
Mike

On Mar 2, 2016 4:57 PM, "Francois PINOT" <fggpinot@gmail.com> wrote:
I cast the pointer returned by the API to the data pointer of an numpy array so that the numpy array points directly to the csound memory (see lines 2070 to 2082 in ctcsound.py). I do the same for input and output buffers, and spin and spout.

2016-03-02 22:47 GMT+01:00 Andres Cabrera <mantaraya36@gmail.com>:
Yes. Right! Ther emight still be some useful code in icsound. I remember I had to write some code to copy tables to and frim numpy arrays (But perhaps you have done that already?)

Cheers,
Andrés

On Wed, Mar 2, 2016 at 1:45 PM, Francois PINOT <fggpinot@gmail.com> wrote:
To wrap the CsoundPerformanceThread class we would need some intermediate C code because ctypes cannot deal directly with C++. That's what is done by swig.

Normally, ctypes releases the GIL during C function calls (see http://www.caswenson.com/2009_06_13_bypassing_the_python_gil_with_ctypes). This should allow us to use the threading functions of the API to get the same result than using CsoundPerformanceThread, keeping ctcsound.py pure python.

I'll investigate this in the Jupyter notebook I'm working on.

2016-03-02 22:34 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
By the way, it would be useful to wrap the CsoundPerformanceThread class as well, so we have
a means to do processing in a separate thread without getting caught up by the GIL.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>
> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
> out the test. This is what I get
>
> ligeti:ctcsound victor$ python test_ctcsound.py
> time resolution is 1000.000 ns
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> .resetting Csound instance
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
> signalflowgraph: csoundModuleDestroy(0x1021ca800)
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> UnifiedCSD:  analogSynth01.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> rtaudio: PortAudio module enabled ...
> using callback interface
> rtmidi: PortMIDI module enabled
> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
> sorting score ...
>         ... done
> --Csound version 6.07 beta (double samples) Jan 26 2016
> displays suppressed
> 0dBFS level = 1.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>    0: dac0 (AirPlay)
>    1: dac1 (Built-in Output)
>    2: dac2 (Soundflower (2ch))
>    3: dac3 (Soundflower (64ch))
>    4: dac4 (Aggregate Device)
> PortAudio: selected output device 'Built-in Output'
> writing 2048 sample blks of 64-bit floats to dac
> SECTION 1:
> .virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> Module 0:pa_bl (audio)
>
> Module 1:pa_cb (audio)
>
> Module 2:jack (audio)
>
> Module 3:auhal (audio)
>
> Module 4:portmidi (midi)
>
> Module 5:coremidi (midi)
>
> .
> ----------------------------------------------------------------------
> Ran 7 tests in 0.404s
>
> OK
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> closing device
> 0 2048 sample blks of 64-bit floats written to dac
> =============
>
> Does it look correct to you?
>
>
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
> >
> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> >
> > It can work with python2 and python3 as well.
> >
> > It's pure python and does not need any C compilation.
> >
> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> >
> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> >
> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> >
> > Francois
>




Date2016-03-03 07:45
FromFrancois PINOT
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
Yes, you can see an example of this in line 2309 and line 2323 of ctcsound.py, where the data pointer of an numpy array is passed to Csound for direct reading/writing.

2016-03-03 7:39 GMT+01:00 Michael Gogins <michael.gogins@gmail.com>:

That is nice. So does this work for array variables as well?

Regards,
Mike

On Mar 2, 2016 4:57 PM, "Francois PINOT" <fggpinot@gmail.com> wrote:
I cast the pointer returned by the API to the data pointer of an numpy array so that the numpy array points directly to the csound memory (see lines 2070 to 2082 in ctcsound.py). I do the same for input and output buffers, and spin and spout.

2016-03-02 22:47 GMT+01:00 Andres Cabrera <mantaraya36@gmail.com>:
Yes. Right! Ther emight still be some useful code in icsound. I remember I had to write some code to copy tables to and frim numpy arrays (But perhaps you have done that already?)

Cheers,
Andrés

On Wed, Mar 2, 2016 at 1:45 PM, Francois PINOT <fggpinot@gmail.com> wrote:
To wrap the CsoundPerformanceThread class we would need some intermediate C code because ctypes cannot deal directly with C++. That's what is done by swig.

Normally, ctypes releases the GIL during C function calls (see http://www.caswenson.com/2009_06_13_bypassing_the_python_gil_with_ctypes). This should allow us to use the threading functions of the API to get the same result than using CsoundPerformanceThread, keeping ctcsound.py pure python.

I'll investigate this in the Jupyter notebook I'm working on.

2016-03-02 22:34 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
By the way, it would be useful to wrap the CsoundPerformanceThread class as well, so we have
a means to do processing in a separate thread without getting caught up by the GIL.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>
> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
> out the test. This is what I get
>
> ligeti:ctcsound victor$ python test_ctcsound.py
> time resolution is 1000.000 ns
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> .resetting Csound instance
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
> signalflowgraph: csoundModuleDestroy(0x1021ca800)
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> UnifiedCSD:  analogSynth01.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> rtaudio: PortAudio module enabled ...
> using callback interface
> rtmidi: PortMIDI module enabled
> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
> sorting score ...
>         ... done
> --Csound version 6.07 beta (double samples) Jan 26 2016
> displays suppressed
> 0dBFS level = 1.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>    0: dac0 (AirPlay)
>    1: dac1 (Built-in Output)
>    2: dac2 (Soundflower (2ch))
>    3: dac3 (Soundflower (64ch))
>    4: dac4 (Aggregate Device)
> PortAudio: selected output device 'Built-in Output'
> writing 2048 sample blks of 64-bit floats to dac
> SECTION 1:
> .virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> Module 0:pa_bl (audio)
>
> Module 1:pa_cb (audio)
>
> Module 2:jack (audio)
>
> Module 3:auhal (audio)
>
> Module 4:portmidi (midi)
>
> Module 5:coremidi (midi)
>
> .
> ----------------------------------------------------------------------
> Ran 7 tests in 0.404s
>
> OK
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> closing device
> 0 2048 sample blks of 64-bit floats written to dac
> =============
>
> Does it look correct to you?
>
>
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
> >
> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> >
> > It can work with python2 and python3 as well.
> >
> > It's pure python and does not need any C compilation.
> >
> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> >
> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> >
> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> >
> > Francois
>





Date2016-03-03 23:47
FromAndres Cabrera
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
Perhaps this module makes icsound.py obsolete?

Cheers,
Andrés

On Wed, Mar 2, 2016 at 11:45 PM, Francois PINOT <fggpinot@gmail.com> wrote:
Yes, you can see an example of this in line 2309 and line 2323 of ctcsound.py, where the data pointer of an numpy array is passed to Csound for direct reading/writing.

2016-03-03 7:39 GMT+01:00 Michael Gogins <michael.gogins@gmail.com>:

That is nice. So does this work for array variables as well?

Regards,
Mike

On Mar 2, 2016 4:57 PM, "Francois PINOT" <fggpinot@gmail.com> wrote:
I cast the pointer returned by the API to the data pointer of an numpy array so that the numpy array points directly to the csound memory (see lines 2070 to 2082 in ctcsound.py). I do the same for input and output buffers, and spin and spout.

2016-03-02 22:47 GMT+01:00 Andres Cabrera <mantaraya36@gmail.com>:
Yes. Right! Ther emight still be some useful code in icsound. I remember I had to write some code to copy tables to and frim numpy arrays (But perhaps you have done that already?)

Cheers,
Andrés

On Wed, Mar 2, 2016 at 1:45 PM, Francois PINOT <fggpinot@gmail.com> wrote:
To wrap the CsoundPerformanceThread class we would need some intermediate C code because ctypes cannot deal directly with C++. That's what is done by swig.

Normally, ctypes releases the GIL during C function calls (see http://www.caswenson.com/2009_06_13_bypassing_the_python_gil_with_ctypes). This should allow us to use the threading functions of the API to get the same result than using CsoundPerformanceThread, keeping ctcsound.py pure python.

I'll investigate this in the Jupyter notebook I'm working on.

2016-03-02 22:34 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
By the way, it would be useful to wrap the CsoundPerformanceThread class as well, so we have
a means to do processing in a separate thread without getting caught up by the GIL.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>
> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
> out the test. This is what I get
>
> ligeti:ctcsound victor$ python test_ctcsound.py
> time resolution is 1000.000 ns
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> .resetting Csound instance
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
> signalflowgraph: csoundModuleDestroy(0x1021ca800)
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> UnifiedCSD:  analogSynth01.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> rtaudio: PortAudio module enabled ...
> using callback interface
> rtmidi: PortMIDI module enabled
> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
> sorting score ...
>         ... done
> --Csound version 6.07 beta (double samples) Jan 26 2016
> displays suppressed
> 0dBFS level = 1.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>    0: dac0 (AirPlay)
>    1: dac1 (Built-in Output)
>    2: dac2 (Soundflower (2ch))
>    3: dac3 (Soundflower (64ch))
>    4: dac4 (Aggregate Device)
> PortAudio: selected output device 'Built-in Output'
> writing 2048 sample blks of 64-bit floats to dac
> SECTION 1:
> .virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> Module 0:pa_bl (audio)
>
> Module 1:pa_cb (audio)
>
> Module 2:jack (audio)
>
> Module 3:auhal (audio)
>
> Module 4:portmidi (midi)
>
> Module 5:coremidi (midi)
>
> .
> ----------------------------------------------------------------------
> Ran 7 tests in 0.404s
>
> OK
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> closing device
> 0 2048 sample blks of 64-bit floats written to dac
> =============
>
> Does it look correct to you?
>
>
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
> >
> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> >
> > It can work with python2 and python3 as well.
> >
> > It's pure python and does not need any C compilation.
> >
> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> >
> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> >
> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> >
> > Francois
>






Date2016-03-04 08:08
FromFrancois PINOT
SubjectRe: [Csnd-dev] Ctypes python wrapper to the Csound API
As I understand it, icsound aims to use Csound in a REPL system based on ipython.

ctcsound is only a wrapper file to the CSOUND API, using numpy data structures for yielding Csound data. Moreover, ctcsound allows the user to work with python2 or python3 as well. And finally, ctsound should be used 'out of the box', with the prerequisite of having a working Python with numpy and a well configured Csound. Of course a complete environment like anaconda (https://www.continuum.io/why-anaconda) does the job too. So ctcsound can be used to develop any kind of python app around Csound.

Ipyhton has evolved and it is now a component of the more ambitious Jupyter project (http://jupyter.org/). Maybe icsound should use ctcsound and Jupyter to become more powerfull...

Regards

Francois

2016-03-04 0:47 GMT+01:00 Andres Cabrera <mantaraya36@gmail.com>:
Perhaps this module makes icsound.py obsolete?

Cheers,
Andrés

On Wed, Mar 2, 2016 at 11:45 PM, Francois PINOT <fggpinot@gmail.com> wrote:
Yes, you can see an example of this in line 2309 and line 2323 of ctcsound.py, where the data pointer of an numpy array is passed to Csound for direct reading/writing.

2016-03-03 7:39 GMT+01:00 Michael Gogins <michael.gogins@gmail.com>:

That is nice. So does this work for array variables as well?

Regards,
Mike

On Mar 2, 2016 4:57 PM, "Francois PINOT" <fggpinot@gmail.com> wrote:
I cast the pointer returned by the API to the data pointer of an numpy array so that the numpy array points directly to the csound memory (see lines 2070 to 2082 in ctcsound.py). I do the same for input and output buffers, and spin and spout.

2016-03-02 22:47 GMT+01:00 Andres Cabrera <mantaraya36@gmail.com>:
Yes. Right! Ther emight still be some useful code in icsound. I remember I had to write some code to copy tables to and frim numpy arrays (But perhaps you have done that already?)

Cheers,
Andrés

On Wed, Mar 2, 2016 at 1:45 PM, Francois PINOT <fggpinot@gmail.com> wrote:
To wrap the CsoundPerformanceThread class we would need some intermediate C code because ctypes cannot deal directly with C++. That's what is done by swig.

Normally, ctypes releases the GIL during C function calls (see http://www.caswenson.com/2009_06_13_bypassing_the_python_gil_with_ctypes). This should allow us to use the threading functions of the API to get the same result than using CsoundPerformanceThread, keeping ctcsound.py pure python.

I'll investigate this in the Jupyter notebook I'm working on.

2016-03-02 22:34 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
By the way, it would be useful to wrap the CsoundPerformanceThread class as well, so we have
a means to do processing in a separate thread without getting caught up by the GIL.
========================
Dr Victor Lazzarini
Dean of Arts, Celtic Studies and Philosophy,
Maynooth University,
Maynooth, Co Kildare, Ireland
Tel: 00 353 7086936
Fax: 00 353 1 7086952

> On 2 Mar 2016, at 21:11, Francois PINOT <fggpinot@GMAIL.COM> wrote:
>
> Great! Can you try to change line 33 in ctcsound.py, replacing "libcsound64.dylib" with the right name? And what is the right name?
>
> 2016-03-02 22:06 GMT+01:00 Victor Lazzarini <Victor.Lazzarini@nuim.ie>:
> We’ll need to change the name of the library (it’s not libcsound64.dylib), but for the moment, I made a soft link to try
> out the test. This is what I get
>
> ligeti:ctcsound victor$ python test_ctcsound.py
> time resolution is 1000.000 ns
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> .resetting Csound instance
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.001s, CPU: 0.000s
> signalflowgraph: csoundModuleDestroy(0x1021ca800)
> virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> UnifiedCSD:  analogSynth01.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> rtaudio: PortAudio module enabled ...
> using callback interface
> rtmidi: PortMIDI module enabled
> sample rate overrides: esr = 96000.0000, ekr = 9600.0000, ksmps = 10
> sorting score ...
>         ... done
> --Csound version 6.07 beta (double samples) Jan 26 2016
> displays suppressed
> 0dBFS level = 1.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> PortAudio V19-devel (built Feb 12 2010 09:42:54)
>    0: dac0 (AirPlay)
>    1: dac1 (Built-in Output)
>    2: dac2 (Soundflower (2ch))
>    3: dac3 (Soundflower (64ch))
>    4: dac4 (Aggregate Device)
> PortAudio: selected output device 'Built-in Output'
> writing 2048 sample blks of 64-bit floats to dac
> SECTION 1:
> .virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> ..virtual_keyboard real time MIDI plugin for Csound
> WARNING: STK opcodes not available: define environment variable RAWWAVE_PATH
> (points to rawwaves directory) to use STK opcodes.
> 0dBFS level = 32768.0
> Csound version 6.07 beta (double samples) Jan 26 2016
> libsndfile-1.0.21
> Module 0:pa_bl (audio)
>
> Module 1:pa_cb (audio)
>
> Module 2:jack (audio)
>
> Module 3:auhal (audio)
>
> Module 4:portmidi (midi)
>
> Module 5:coremidi (midi)
>
> .
> ----------------------------------------------------------------------
> Ran 7 tests in 0.404s
>
> OK
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.257s, CPU: 0.008s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.269s, CPU: 0.020s
> end of score.              overall amps:      0.0
>            overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 0.280s, CPU: 0.030s
> inactive allocs returned to freespace
> end of score.              overall amps:  0.00000  0.00000
>            overall samples out of range:        0        0
> 0 errors in performance
> closing device
> 0 2048 sample blks of 64-bit floats written to dac
> =============
>
> Does it look correct to you?
>
>
> ========================
> Dr Victor Lazzarini
> Dean of Arts, Celtic Studies and Philosophy,
> Maynooth University,
> Maynooth, Co Kildare, Ireland
> Tel: 00 353 7086936
> Fax: 00 353 1 7086952
>
> > On 2 Mar 2016, at 20:06, Francois PINOT <fggpinot@gmail.com> wrote:
> >
> > I wrote a new python wrapper file to the Csound API using the Csound ctypes module. The wrapper is self contained in a single file: ctcsound.py. It can be downloaded from github: https://github.com/fggp/ctcsound
> >
> > It can work with python2 and python3 as well.
> >
> > It's pure python and does not need any C compilation.
> >
> > I've tested the file on a linux box (Ubuntu 14.04 64 bit) and on a Windows box (Seven 64 bit Professional Edition). I have no Apple box. Could someone test it on an OSX system ? A simple command 'python test_ctsound.py' or 'python3 test_ctsound.py' should do it.
> >
> > If it's OK, it could be included in the next Csound release as an alternative and/or a complement to the csnd6 python wrapper generated with SWIG.
> >
> > I'm developping a Jupyter notebook to demonstrate in detail the use of this new python wrapper to the Csound API.
> >
> > Francois
>