aboutsummaryrefslogtreecommitdiff
path: root/sonics/soundxdb.udo
diff options
context:
space:
mode:
Diffstat (limited to 'sonics/soundxdb.udo')
-rwxr-xr-xsonics/soundxdb.udo202
1 files changed, 202 insertions, 0 deletions
diff --git a/sonics/soundxdb.udo b/sonics/soundxdb.udo
new file mode 100755
index 0000000..c27b2bf
--- /dev/null
+++ b/sonics/soundxdb.udo
@@ -0,0 +1,202 @@
+#ifndef UDO_SOUNDXDB
+#define UDO_SOUNDXDB ##
+/*
+ SQL database extract interface to sound object management.
+ File containing extract definitions must be included before this.
+ Slim excerpt for Partial Emergence
+
+ This file is part of the SONICS UDO collection by Richard Knight 2022
+ License: GPL-2.0-or-later
+ http://1bpm.net
+
+*/
+
+#ifndef XDB_SET
+prints "Database extract not defined; cannot continue.\n\n\n"
+exitnow
+#end
+
+
+#ifndef XDB_MINNOTE
+#define XDB_MINNOTE #0#
+#end
+
+
+
+
+
+/*
+ Get the ID of a filecollection by name
+
+ icollectionid sounddb_getcollectionid Scollection
+
+ icollectionid collection ID
+ Scollection collection name
+*/
+opcode sounddb_getcollectionid, i, S
+ Scollection xin
+ index = 0
+ while (index < lenarray(gSxdb_collections)) do
+ if (strcmp(gSxdb_collections[index], Scollection) == 0) then
+ igoto complete
+ endif
+ index += 1
+ od
+ index = -1
+complete:
+ xout index
+endop
+
+
+
+/*
+ Get the file IDs of a filecollection, also loading each file to gisounddb
+
+ ifileids[] sounddb_getcollection Scollection
+
+ ifileids[] file IDs in the collection, accessible as indexes to f-tables in gisounddb
+ Scollection collection name
+*/
+opcode sounddb_getcollection, i[], S
+ Scollection xin
+ idata[], icollectionid sounddb_getcollection Scollection
+ xout idata
+endop
+
+
+
+
+
+/*
+ Get the collection ID and file IDs of a filecollection, also loading each file to gisounddb
+
+ ifileids[], icollectionid sounddb_getcollection Scollection
+
+ ifileids[] file IDs in the collection, accessible as indexes to f-tables in gisounddb
+ icollectionid collection ID
+ Scollection collection name
+*/
+opcode sounddb_getcollection, i[]i, S
+ Scollection xin
+
+ itotalsize = 0
+ if (strindex(Scollection, ",") > 0) then
+ index = 1
+ Stemp = Scollection
+ while (index > 0) do
+ index strindex Stemp, ","
+ if (index > 0) then
+ icollectionid = sounddb_getcollectionid(strsub(Stemp, 0, index))
+ itotalsize += ftlen(gixdb_collectionsfn[icollectionid])
+ Stemp strsub Stemp, index+1
+ else
+ icollectionid = sounddb_getcollectionid(Stemp)
+ itotalsize += ftlen(gixdb_collectionsfn[icollectionid])
+ endif
+ od
+
+ idata[] init itotalsize
+ iwriteindex = 0
+ index = 1
+ Stemp = Scollection
+ while (index > 0) do
+ index strindex Stemp, ","
+ if (index > 0) then
+ icollectionid = sounddb_getcollectionid(strsub(Stemp, 0, index))
+ ifn = gixdb_collectionsfn[icollectionid]
+ ireadindex = 0
+ while (ireadindex < ftlen(ifn)) do
+ idata[iwriteindex] table ireadindex, ifn
+ ireadindex += 1
+ iwriteindex += 1
+ od
+ Stemp strsub Stemp, index+1
+ else
+ icollectionid = sounddb_getcollectionid(Stemp)
+ ifn = gixdb_collectionsfn[icollectionid]
+ ireadindex = 0
+ while (ireadindex < ftlen(ifn)) do
+ idata[iwriteindex] table ireadindex, ifn
+ ireadindex += 1
+ iwriteindex += 1
+ od
+ endif
+ od
+
+ else
+ icollectionid = sounddb_getcollectionid(Stemp)
+ idata[] tab2array gixdb_collectionsfn[icollectionid]
+ igoto complete
+ endif
+
+complete:
+ xout idata, icollectionid
+endop
+
+
+
+
+/*
+ gixdb_pitchreference
+ has 127 * 4 entries. get start and end indexes for gixdb_pitchnotes by
+ index = (inote + (icollectionid * 127)) * 2
+
+ then values
+ iminindex table index, gixdb_pitchreference
+ imaxindex table index+1, gixdb_pitchreference
+
+ then get the actual files which are between min and max indexes eg
+
+ iselected = round(random(iminindex, imaxindex))
+ ifileid table iselected, gixdb_pitchnotes
+ ipitchadjust table iselected, gixdb_pitchadjust
+
+
+
+*/
+
+
+
+
+/*
+ Get the nearest note in a filecollection, return the file ID and the pitch ratio adjustment required to the requested note.
+
+ ifileid, ipitchratio sounddb_mel_nearestnote icollectionid, inote
+
+ ifileid file ID, corresponding to index in gisounddb
+ ipitchratio pitch ratio adjustment required to make the file match the requested note
+ icollectionid collection ID
+ inote MIDI note number
+*/
+opcode sounddb_mel_nearestnote, ii, ii
+ icollectionid, inote xin
+ irefindex = ((inote - $XDB_MINNOTE) + (icollectionid * 128)) * 2 ;, gixdb_pitchreference
+ iselected = round(random(tab_i(irefindex, gixdb_pitchreference), tab_i(irefindex+1, gixdb_pitchreference)))
+ ifileid tab_i iselected, gixdb_pitchnotes
+ ipitchratio tab_i iselected, gixdb_pitchadjust
+
+ xout ifileid, ipitchratio
+endop
+
+
+
+/*
+ Get the nearest note in a filecollection, return the file ID and the pitch ratio adjustment required to the requested note.
+
+ ifileid, ipitchratio sounddb_mel_nearestnote Scollection, inote
+
+ ifileid file ID, corresponding to index in gisounddb
+ ipitchratio pitch ratio adjustment required to make the file match the requested note
+ Scollection collection name
+ inote MIDI note number
+*/
+opcode sounddb_mel_nearestnote, ii, Si
+ Scollection, inote xin
+ icollectionid = sounddb_getcollectionid(Scollection)
+ ifileid, ipitchratio sounddb_mel_nearestnote icollectionid, inote
+ xout ifileid, ipitchratio
+endop
+
+
+
+#end