Skip to content

Instantly share code, notes, and snippets.

@johl
Last active April 24, 2020 13:52
Show Gist options
  • Save johl/b473f76a7bdb1369d2646fedc0017dbb to your computer and use it in GitHub Desktop.
Save johl/b473f76a7bdb1369d2646fedc0017dbb to your computer and use it in GitHub Desktop.
live_loop :soup do
use_real_time
sleep 6.856
end
live_loop :nutz do
sample :loop_amen_full
sync :soup
end
live_loop :foo do
use_real_time
a, b = sync "/osc/0"
synth :dpulse, note: a, duration: b
end
live_loop :bar do
use_real_time
a, b = sync "/osc/1"
synth :prophet, note: a, duration: b
end
live_loop :baz do
use_real_time
a, b = sync "/osc/2"
synth :blade, note: a, duration: b
end
live_loop :quux do
use_real_time
a, b = sync "/osc/3"
synth :dtri, note: a, duration: b
end
import time
from pythonosc import osc_message_builder
from pythonosc import udp_client
import sys
import re
from SPARQLWrapper import SPARQLWrapper, JSON
endpoint_url = "https://query.wikidata.org/sparql"
query = """# All popes with number of children
SELECT (SAMPLE(?father) as ?father) ?fatherLabel (SAMPLE(?age) as ?age) (SAMPLE(?birthyear) as ?birthyear) (SAMPLE(?deathyear) as ?deathyear) (COUNT(?father) as ?children)
WHERE
{
?subj wdt:P22 ?father .
?father wdt:P31 wd:Q5 .
?father wdt:P39 wd:Q19546 .
?father wdt:P569 ?birthdate .
?father wdt:P570 ?deathdate .
BIND (YEAR(?birthdate) AS ?birthyear).
BIND (YEAR(?deathdate) AS ?deathyear).
BIND(?deathyear - ?birthyear AS ?age).
OPTIONAL {
?father wdt:P18 ?picture .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
GROUP BY ?fatherLabel
ORDER BY ?fatherLabel
LIMIT 50"""
def get_results(endpoint_url, query):
user_agent = "NoiseQuery/%s.%s" % (sys.version_info[0], sys.version_info[1])
sparql = SPARQLWrapper(endpoint_url, agent=user_agent)
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
return sparql.query().convert()
results = get_results(endpoint_url, query)
sender = udp_client.SimpleUDPClient('10.0.0.12', 4559)
for result in results["results"]["bindings"]:
note = int(result['age']['value']) - 15
sustain = int(result['children']['value']) + 5 * 0.75
q = int(re.search(r'[0-9]+', result['father']['value']).group(0))
synth = q % 4
sender.send_message('/'+str(synth), [note, sustain])
time.sleep(sustain)
print(synth, note, sustain)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment