using SQLite in Csound
Date | 2016-02-28 13:00 |
From | Richard |
Subject | using SQLite in Csound |
Attachments | test.db |
A quick and dirty test to show that it is possible to use a database
in Csound. The attached database has a table "samples" with 2 floating points in it (pi and e). They are read as a kind of iterator by the function select. Note: you cannot open the database in the global pyruni section , because SQLite complains about different threads. In a real world example, when reading samples, 'select' should be k-rate, of course.. Here's the code: <CsInstruments>
pyinit
pyruni {{ import sqlite3 as lite
gotit = 0 elm = -1 rows = []
def select(i): global gotit, elm, rows if gotit == 0: con = lite.connect('test.db') cur = con.cursor()
cur.execute("SELECT * FROM samples") rows = cur.fetchall() con.close() print rows gotit = 1 elm += 1 return rows[0][elm] }}
instr 1 ;call it ival pycall1i "select", 1 prints "val = %f\n", ival endin
</CsInstruments> <CsScore> i 1 0 1 100 200 i 1 1 1 1000 2000 </CsScore> </CsoundSynthesizer> |
Date | 2016-02-28 13:35 |
From | Richard |
Subject | Re: using SQLite in Csound |
This opens a lot of possibilities, e.g. score lines (with up to 8
parameters) could be stored in the database. In this example I have an argument (i), that is not used, but that could be an index in a query table, etc. (since strings are not allowed as arguments for pycall) Would it be possible to modify pycall to return an array of arbitrary length? That would be very useful... Richard On 28/02/16 14:00, Richard wrote:
A quick and dirty test to show that it is possible to use a database in Csound. |
Date | 2016-02-28 13:36 |
From | "Dr. Richard Boulanger" |
Subject | Re: using SQLite in Csound |
I get the following error message from your example: pyruni: python exception File "<string>", line 7 global gotit, elm, rows ^ IndentationError: expected an indented block _____________________________________________ Dr. Richard Boulanger Professor of Electronic Production and Design Professional Writing and Music Technology Division Berklee College of Music 1140 Boylston Street, FB-75 Boston, MA 02215-3693 Office @ 161 Mass Ave - 4th Floor 617-747-2384 (office) 774-488-9166 (cell) ______________________________________________ rboulanger@berklee.edu (email) https://www.facebook.com/richard.boulanger.58 (facebook) ______________________________________________ President of Boulanger Labs - http://boulangerlabs.com Director of Csounds.com - http://csounds.com Author & Editor: The Csound Book - http://mitpress.mit.edu/books/csound-book Author & Editor: The Audio Programming Book - http://mitpress.mit.edu/books/audio-programming-book ______________________________________________ about: http://www.boulangerlabs.com/about/richardboulanger/ about: http://www.csounds.com/community/developers/dr-richard-boulanger/ ______________________________________________ music: http://www.csounds.com/community/developers/dr-richard-boulanger/dr-richard-boulanger-music/ On Sun, Feb 28, 2016 at 8:00 AM, Richard <zappfinger@gmail.com> wrote:
|
Date | 2016-02-28 13:42 |
From | Richard |
Subject | Re: using SQLite in Csound |
Attachments | sqlite.csd |
Python is a bit strict about indentation. I created and executed
this example in CsoundQt. Here is the csd attached. Richard On 28/02/16 14:36, Dr. Richard
Boulanger wrote:
|
Date | 2016-02-28 14:19 |
From | "Dr. Richard Boulanger" |
Subject | Re: using SQLite in Csound |
Thanks for the .csd. It works! _____________________________________________ Dr. Richard Boulanger Professor of Electronic Production and Design Professional Writing and Music Technology Division Berklee College of Music 1140 Boylston Street, FB-75 Boston, MA 02215-3693 Office @ 161 Mass Ave - 4th Floor 617-747-2384 (office) 774-488-9166 (cell) ______________________________________________ rboulanger@berklee.edu (email) https://www.facebook.com/richard.boulanger.58 (facebook) ______________________________________________ President of Boulanger Labs - http://boulangerlabs.com Director of Csounds.com - http://csounds.com Author & Editor: The Csound Book - http://mitpress.mit.edu/books/csound-book Author & Editor: The Audio Programming Book - http://mitpress.mit.edu/books/audio-programming-book ______________________________________________ about: http://www.boulangerlabs.com/about/richardboulanger/ about: http://www.csounds.com/community/developers/dr-richard-boulanger/ ______________________________________________ music: http://www.csounds.com/community/developers/dr-richard-boulanger/dr-richard-boulanger-music/ On Sun, Feb 28, 2016 at 8:42 AM, Richard <zappfinger@gmail.com> wrote:
|
Date | 2016-02-28 15:55 |
From | Peter Burgess |
Subject | Re: using SQLite in Csound |
Awesome work! So this is the potential solution to building samples into my app that you mentioned? You guys sure work quick round here, thanks! On Sun, Feb 28, 2016 at 2:19 PM, Dr. Richard Boulanger |
Date | 2016-02-28 16:00 |
From | Richard |
Subject | Re: using SQLite in Csound |
Yes. I have to work it out with a real sample as a blob, but in principle this should be a solution. Richard On 28/02/16 16:55, Peter Burgess wrote: > Awesome work! So this is the potential solution to building samples > into my app that you mentioned? You guys sure work quick round here, > thanks! > > On Sun, Feb 28, 2016 at 2:19 PM, Dr. Richard Boulanger > |
Date | 2016-02-28 16:05 |
From | Peter Burgess |
Subject | Re: using SQLite in Csound |
Fantastic! Thank you very much :D On Sun, Feb 28, 2016 at 4:00 PM, Richard |
Date | 2016-02-28 16:18 |
From | Richard |
Subject | Re: using SQLite in Csound |
BTW, the Firefox web browser has a free add-in, SQLite Manager, that can be used to manage a SQLite database. (Create tables, inspect, insert data, perform queries, etc) Richard On 28/02/16 17:05, Peter Burgess wrote: > Fantastic! Thank you very much :D > > On Sun, Feb 28, 2016 at 4:00 PM, Richard |
Date | 2016-02-28 17:58 |
From | Richard |
Subject | Re: using SQLite in Csound |
This is trickier than I thought. pycalli only returns floats, but a WAV file contains strings and integers, no floats....hmmm A new opcode might still be needed... Richard On 28/02/16 17:05, Peter Burgess wrote: > Fantastic! Thank you very much :D > > On Sun, Feb 28, 2016 at 4:00 PM, Richard |
Date | 2016-02-28 18:12 |
From | Peter Burgess |
Subject | Re: using SQLite in Csound |
I assume this will only work with python enabled Csound? On Sun, Feb 28, 2016 at 5:58 PM, Richard |
Date | 2016-02-28 18:16 |
From | Richard |
Subject | Re: using SQLite in Csound |
I think the python opcodes are standard Csound now... Maybe there is another way out for reading samples as blobs: In Python I could save the blob as a (temporary) wave file and then call a GEN routine to read that file into a table. May be a lot easier... Richard On 28/02/16 19:12, Peter Burgess wrote: > I assume this will only work with python enabled Csound? > > On Sun, Feb 28, 2016 at 5:58 PM, Richard |
Date | 2016-02-28 18:48 |
From | Peter Burgess |
Subject | Re: using SQLite in Csound |
if python's standard now then we're all good. Just trying to keep everything I do for the app within the standard build of csound On Sun, Feb 28, 2016 at 6:16 PM, Richard |
Date | 2016-02-28 19:17 |
From | Richard |
Subject | Re: using SQLite in Csound |
Attachments | sqlite.csd test.db |
Good news, this works! The rowid number could be an argument for a
function to determine what sample to load.. I've attached the database and csd file. The samples table contains a guitar sample playing an A3.. Richard <CsInstruments>
pyinit
pyruni {{ import sqlite3 as lite
con = lite.connect('test.db') cur = con.cursor() cur.execute("select sample from samples where rowid=1") ablob = cur.fetchone() with open('temp.wav', 'wb') as output_file: output_file.write(ablob[0]) }}
instr 1 kamp = 30000 kcps = 1 ifn = 1 ibas = 1
; Play the audio sample stored in Table #1. a1 loscil kamp, kcps, ifn, ibas out a1 endin
</CsInstruments> <CsScore> f 1 0 0 1 "temp.wav" 0 0 0 ; Play Instrument #1 for 2 seconds. i 1 0 2 e On 28/02/16 19:48, Peter Burgess wrote:
if python's standard now then we're all good. Just trying to keep everything I do for the app within the standard build of csound On Sun, Feb 28, 2016 at 6:16 PM, Richard <zappfinger@gmail.com> wrote:I think the python opcodes are standard Csound now... Maybe there is another way out for reading samples as blobs: In Python I could save the blob as a (temporary) wave file and then call a GEN routine to read that file into a table. May be a lot easier... Richard On 28/02/16 19:12, Peter Burgess wrote:I assume this will only work with python enabled Csound? On Sun, Feb 28, 2016 at 5:58 PM, Richard <zappfinger@gmail.com> wrote:This is trickier than I thought. pycalli only returns floats, but a WAV file contains strings and integers, no floats....hmmm A new opcode might still be needed... Richard On 28/02/16 17:05, Peter Burgess wrote:Fantastic! Thank you very much :D On Sun, Feb 28, 2016 at 4:00 PM, Richard <zappfinger@gmail.com> wrote:Yes. I have to work it out with a real sample as a blob, but in principle this should be a solution. Richard On 28/02/16 16:55, Peter Burgess wrote:Awesome work! So this is the potential solution to building samples into my app that you mentioned? You guys sure work quick round here, thanks! On Sun, Feb 28, 2016 at 2:19 PM, Dr. Richard Boulanger <rboulanger@berklee.edu> wrote:Thanks for the .csd. It works! _____________________________________________ Dr. Richard Boulanger Professor of Electronic Production and Design Professional Writing and Music Technology Division Berklee College of Music 1140 Boylston Street, FB-75 Boston, MA 02215-3693 Office @ 161 Mass Ave - 4th Floor 617-747-2384 (office) 774-488-9166 (cell) ______________________________________________ rboulanger@berklee.edu (email) https://www.facebook.com/richard.boulanger.58 (facebook) ______________________________________________ President of Boulanger Labs - http://boulangerlabs.com Director of Csounds.com - http://csounds.com Author & Editor: The Csound Book - http://mitpress.mit.edu/books/csound-book Author & Editor: The Audio Programming Book - http://mitpress.mit.edu/books/audio-programming-book ______________________________________________ about: http://www.boulangerlabs.com/about/richardboulanger/ about: http://www.csounds.com/community/developers/dr-richard-boulanger/ ______________________________________________ music: http://www.csounds.com/community/developers/dr-richard-boulanger/dr-richard-boulanger-music/ On Sun, Feb 28, 2016 at 8:42 AM, Richard <zappfinger@gmail.com> wrote:Python is a bit strict about indentation. I created and executed this example in CsoundQt. Here is the csd attached. Richard On 28/02/16 14:36, Dr. Richard Boulanger wrote: I get the following error message from your example: pyruni: python exception File "<string>", line 7 global gotit, elm, rows ^ IndentationError: expected an indented block _____________________________________________ Dr. Richard Boulanger Professor of Electronic Production and Design Professional Writing and Music Technology Division Berklee College of Music 1140 Boylston Street, FB-75 Boston, MA 02215-3693 Office @ 161 Mass Ave - 4th Floor 617-747-2384 (office) 774-488-9166 (cell) ______________________________________________ rboulanger@berklee.edu (email) https://www.facebook.com/richard.boulanger.58 (facebook) ______________________________________________ President of Boulanger Labs - http://boulangerlabs.com Director of Csounds.com - http://csounds.com Author & Editor: The Csound Book - http://mitpress.mit.edu/books/csound-book Author & Editor: The Audio Programming Book - http://mitpress.mit.edu/books/audio-programming-book ______________________________________________ about: http://www.boulangerlabs.com/about/richardboulanger/ about: http://www.csounds.com/community/developers/dr-richard-boulanger/ ______________________________________________ music: http://www.csounds.com/community/developers/dr-richard-boulanger/dr-richard-boulanger-music/ On Sun, Feb 28, 2016 at 8:00 AM, Richard <zappfinger@gmail.com> wrote:A quick and dirty test to show that it is possible to use a database in Csound. The attached database has a table "samples" with 2 floating points in it (pi and e). They are read as a kind of iterator by the function select. Note: you cannot open the database in the global pyruni section , because SQLite complains about different threads. In a real world example, when reading samples, 'select' should be k-rate, of course.. Here's the code: <CsInstruments> pyinit pyruni {{ import sqlite3 as lite gotit = 0 elm = -1 rows = [] def select(i): global gotit, elm, rows if gotit == 0: con = lite.connect('test.db') cur = con.cursor() cur.execute("SELECT * FROM samples") rows = cur.fetchall() con.close() print rows gotit = 1 elm += 1 return rows[0][elm] }} instr 1 ;call it ival pycall1i "select", 1 prints "val = %f\n", ival endin </CsInstruments> <CsScore> i 1 0 1 100 200 i 1 1 1 1000 2000 </CsScore> </CsoundSynthesizer> Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted hereCsound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted hereCsound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted hereCsound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted hereCsound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted hereCsound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2016-02-28 19:22 |
From | Peter Burgess |
Subject | Re: using SQLite in Csound |
Awesome! I'll check that out when I get a sec. Nice one man! :D On Sun, Feb 28, 2016 at 7:17 PM, Richard |
Date | 2016-02-29 01:05 |
From | "Dr. Richard Boulanger" |
Subject | Re: using SQLite in Csound |
Wonderful! Thanks for this. Dr.B.
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
_____________________________________________ Dr. Richard Boulanger Professor of Electronic Production and Design Professional Writing and Music Technology Division On Sun, Feb 28, 2016 at 12:58 PM, Richard <zappfinger@gmail.com> wrote: This is trickier than I thought. |