aboutsummaryrefslogtreecommitdiff
path: root/site/udo/soundxdb_extract.udo
diff options
context:
space:
mode:
Diffstat (limited to 'site/udo/soundxdb_extract.udo')
-rwxr-xr-xsite/udo/soundxdb_extract.udo67
1 files changed, 67 insertions, 0 deletions
diff --git a/site/udo/soundxdb_extract.udo b/site/udo/soundxdb_extract.udo
new file mode 100755
index 0000000..64899c8
--- /dev/null
+++ b/site/udo/soundxdb_extract.udo
@@ -0,0 +1,67 @@
+#ifndef UDO_SOUNDDB_XPORT
+#define UDO_SOUNDDB_XPORT ##
+/*
+ SQL database extraction to be used with soundxdb.udo
+
+ This file is part of the SONICS UDO collection by Richard Knight 2022
+ License: GPL-2.0-or-later
+ http://1bpm.net
+
+*/
+
+#include "pgdb.udo"
+
+
+/*
+ Extract UDO definition from database for specified collection(s), to be used with soundxdb.udo.
+ Permits using functionality of sounddb.udo without database connectivity.
+ The file output includes an include of soundxdb.udo, so only the resulting file needs to be included.
+
+ soundxdb_extract Sfile, Scollections [, iminnote=0]
+
+ Sfile file path to extract to
+ Scollections collection name, or multiple comma-separated (no whitespace) collection names
+ iminnote the minimum MIDI note number to extract (higher can save output space/text usage; lower notes (eg < 25) are not usually used)
+*/
+opcode soundxdb_extract, 0, SSo
+ Sfile, Scollections, iminnote xin
+
+ Sclause = ""
+ if (strindex(Scollections, ",") > 0) then
+ index = 1
+ Stemp = Scollections
+ while (index > 0) do
+ index strindex Stemp, ","
+ if (index > 0) then
+ Sclause strcat Sclause, sprintf("'%s',", strsub(Stemp, 0, index))
+ Stemp strsub Stemp, index+1
+ else
+ Sclause strcat Sclause, sprintf("'%s'", Stemp)
+ endif
+ od
+ else
+ Sclause = sprintf("'%s'", Scollections)
+ endif
+
+ Squery = sprintf("SELECT f_xdb_export(%d, %s)", iminnote, Sclause)
+
+ iwritelines = 50
+ Scache = ""
+ Sres[][] dbarray gidb, Squery
+ index = 0
+ while (index < lenarray(Sres)) do
+ Scache strcat Scache, Sres[index][0]
+ Scache strcat Scache, "\n"
+
+ if (index % iwritelines == 0) then
+ fprints Sfile, Scache
+ Scache = ""
+ endif
+ index += 1
+ od
+ fprints Sfile, Scache
+ Scache = ""
+endop
+
+
+#end