From 9fbf91db06a6d4f4b5cd8bb45389a731bb86bf22 Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 13 Apr 2025 18:48:02 +0100 Subject: initial --- site/udo/aodb.udo | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 site/udo/aodb.udo (limited to 'site/udo/aodb.udo') diff --git a/site/udo/aodb.udo b/site/udo/aodb.udo new file mode 100755 index 0000000..c81c233 --- /dev/null +++ b/site/udo/aodb.udo @@ -0,0 +1,80 @@ +#ifndef UDO_AODB +#define UDO_AODB ## +/* + AudioOrganiser SQLite connection and tools + + This file is part of the SONICS UDO collection by Richard Knight 2023 + License: GPL-2.0-or-later + http://1bpm.net +*/ + +#include "__config__.udo" +#include "host_tools.udo" +#define USING_AODB ## + +if (gihost_type == 0) then + giaodb dbconnect "sqlite", "$AODB_PATH_WIN" +else + giaodb dbconnect "sqlite", "$AODB_PATH_LINUX" +endif + +opcode _aodb_formatquery, S, Sip + Slike, irandomorder, inumber xin + xout sprintf("SELECT id, path FROM audiofile WHERE path LIKE 'd:\\Samples\\%%%s%%' %s LIMIT %d", Slike, (irandomorder == 1 ? "ORDER BY RANDOM()" : ""), inumber) +endop + + +opcode aodb_getsample, iS, Sp + Slike, irandomorder xin + Sres[][] dbarray giaodb, _aodb_formatquery(Slike, irandomorder) + id strtod Sres[0][0] + Spath = Sres[0][1] + xout id, Spath +endop + +opcode aodb_getsample, S, Sp + Slike, irandomorder xin + id, Spath aodb_getsample Slike, irandomorder + xout Spath +endop + +opcode aodb_loadsample, i, Spp + Slike, irandomorder, imono xin + Spath aodb_getsample Slike, irandomorder + ifn ftgen 0, 0, 0, 1, Spath, 0, 0, imono + xout ifn +endop + +opcode aodb_diskinsample, aa, Sp + Slike, irandomorder xin + id, Spath aodb_getsample Slike, irandomorder + ichannels filenchnls Spath + if (ichannels == 1) then + aL diskin Spath, 1 + aR = aL + else + aL, aR diskin Spath, 1 + endif + xout aL, aR +endop + + +opcode aodb_getsamples, S[], Sip + Slike, inumber, irandomorder xin + Sout[] init inumber + Sres[][] dbarray giaodb, _aodb_formatquery(Slike, irandomorder, inumber) + index = 0 + while (index < lenarray(Sres)) do + Sout[index] = Sres[index][1] + index += 1 + od + xout Sout +endop + +opcode aodb_getsamplebyid, S, i + id xin + Sres dbscalar giaodb, sprintf("SELECT path FROM audiofile WHERE id = %d", id) + xout Sres +endop + +#end -- cgit v1.2.3