forked from eegsynth/eegsynth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implemented virtual sequencer to complement the virtual synthesizer.
- Loading branch information
1 parent
875bf0c
commit ea6fe3d
Showing
6 changed files
with
111 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[general] | ||
name="Sequencer" | ||
|
||
[redis] | ||
hostname=localhost | ||
port=6379 | ||
|
||
[sequence] | ||
pattern000= 0 4 0 7 | ||
pattern001= 0 4 7 9 10 9 7 4 | ||
pattern002= 5 10 13 10 | ||
pattern003= 5 13 12 10 | ||
pattern004= 4 4 4 4 | ||
pattern005= 5 5 5 5 | ||
pattern006= 6 6 6 6 | ||
pattern007= 7 7 7 7 | ||
pattern008= 8 8 8 8 | ||
pattern009= 9 9 9 9 | ||
pattern010= 10 10 10 10 | ||
|
||
[default] | ||
pattern=1 ; see above for the sequences | ||
rate=120 ; beats per minute | ||
offset=48 | ||
|
||
[input] | ||
pattern=launchcontrol.channel00.control053 | ||
rate=launchcontrol.channel00.control054 | ||
offset=keyboard.channel00.note | ||
|
||
[output] | ||
prefix=sequencer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env python | ||
|
||
import math | ||
import ConfigParser # this is version 2.x specific,on version 3.x it is called "configparser" and has a different API | ||
import redis | ||
import time | ||
|
||
config = ConfigParser.ConfigParser() | ||
config.read('sequencer.ini') | ||
|
||
r = redis.StrictRedis(host=config.get('redis','hostname'),port=config.getint('redis','port'),db=0) | ||
|
||
pattern = r.get(config.get('input','pattern')) | ||
if pattern: | ||
pattern = int(pattern) | ||
else: | ||
pattern = config.getint('default','pattern') | ||
previous = pattern | ||
|
||
# get the corresponding pattern | ||
sequence = config.get('sequence',"pattern{:0>3d}".format(pattern)) | ||
|
||
while True: | ||
|
||
for note in sequence.split(): | ||
# this will return empty if not available | ||
new = int(r.get(config.get('input','pattern'))) | ||
if pattern!=new: | ||
pattern = new | ||
try: | ||
sequence = config.get('sequence',"pattern{:0>3d}".format(pattern)) | ||
except: | ||
pass | ||
# immediately start playing the new sequence | ||
break | ||
|
||
rate = r.get(config.get('input','rate')) | ||
if rate: | ||
rate = float(rate) | ||
else: | ||
rate = config.getfloat('default','rate') | ||
# assume that value is between 0 and 127, map exponentially from 20 to 2000 | ||
# it should not get too low, otherwise the code with the sleep below becomes unresponsive | ||
rate = 20*math.exp(rate*math.log(100)/127) | ||
|
||
offset = r.get(config.get('input','offset')) | ||
if offset: | ||
offset = int(offset) | ||
else: | ||
offset = config.getint('default','offset') | ||
|
||
note = int(note) | ||
|
||
print(pattern, int(rate), offset, note) | ||
|
||
key = "{}.note".format(config.get('output','prefix')) | ||
val = note+offset | ||
# send it as control value: prefix.channel000.note=note | ||
r.set(key,val) | ||
# send it as trigger: prefix.channel000.note=note | ||
r.publish(key,val) | ||
|
||
time.sleep(60/rate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters