Skip to content

Commit

Permalink
cleaning deprecated mappings #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Itaborala committed Jun 22, 2024
1 parent cf5b14c commit 86eaec8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 159 deletions.
125 changes: 3 additions & 122 deletions synth/sc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
NOTESDICT = {"c":"amp1", "c#":"amp2", "d":"amp3", "d#":"amp4", "e":"amp5", "f":"amp6", "f#":"amp7", "g":"amp8", "g#":"amp9", "a":"amp10", "a#":"amp11", "b":"amp12", "new":"amp13"}
global FREQDICT
FREQDICT = {"c":60, "c#":61, "d":62, "d#":63, "e":64, "f":65, "f#":66, "g":67, "g#":68, "a":69, "a#":70, "b":71}
global FREQDICTL
FREQDICTL = {"l1":60, "l2":61, "l3":62, "l4":63, "l5":64, "l6":65, "l7":66, "l8":67, "l9":68, "l10":69, "l11":70, "l12":71}
global EXAMPLE
EXAMPLE = {"l1":"amp1", "l2":"amp2", "l3":"amp3", "l4":"amp4", "l5":"amp5", "l6":"amp6", "l7":"amp7", "l8":"amp8"}
global EXAMPLE6
EXAMPLE6 = {"s0":"amp1", "s1":"amp2", "s2":"amp3", "s3":"amp4", "s4":"amp5", "s5":"amp6"}
global EXAMPLE4
EXAMPLE4 = {"00":"amp1", "01":"amp2", "10":"amp3", "11":"amp4"}
global EXAMPLERT
EXAMPLERT = {"c":"amp1", "e":"amp2", "g":"amp3", "b":"amp4"}

class MusicalScale:
def __init__(self):
Expand Down Expand Up @@ -72,92 +62,9 @@ def gain(self, value):
# with self.lock:
self._gain = value

# Mapping #1 - Simple additive synthesis - 12 qubits
def note_loudness_multiple(self, data, **kwargs):
global NOTESDICT
loudnessstream = data[0]

labels = ["amp1", "amp2", "amp3", "amp4", "amp5", "amp6", "amp7", "amp8", "amp9", "amp10", "amp11", "amp12", "amp13"]
loudness = np.zeros(12)
args = dict(zip(labels,loudness))
synth = Synth(self.server, "vqe_model1_son1", args)

for state in loudnessstream:
print(state)
for k, amp in state.items():
synth.set(NOTESDICT[k], amp)
time.sleep(0.05)
# Mapping #2 - Simple additive synthesis - 8 qubits
def note_loudness_multiple_8_qubits(self, data, **kwargs):
global EXAMPLE
loudnessstream = data[0]


labels = ["amp1", "amp2", "amp3", "amp4", "amp5", "amp6", "amp7", "amp8"]
loudness = np.zeros(12)
args = dict(zip(labels,loudness))
synth = Synth(self.server, "vqe_model1_son1", args)

for state in loudnessstream:
print(state)
for k, amp in state.items():
synth.set(EXAMPLE[k], amp)
time.sleep(0.03)

# Mapping #4 - Simple additive synthesis - 6 qubits
def note_loudness_multiple_6_qubits(self, data, **kwargs):
global EXAMPLE6
loudnessstream = data[0]


labels = ["amp1", "amp2", "amp3", "amp4", "amp5", "amp6"]
loudness = np.zeros(6)
args = dict(zip(labels,loudness))
synth = Synth(self.server, "vqe_model1_6q", args)

for state in loudnessstream:
print(state)
for k, amp in state.items():
synth.set(EXAMPLE6[k], amp)
time.sleep(0.03)

# Mapping #4 - Simple additive synthesis - 4 qubits
def note_loudness_multiple_4_qubits(self, data, **kwargs):
global EXAMPLE4
loudnessstream = data[0]


labels = ["amp1", "amp2", "amp3", "amp4"]
loudness = np.zeros(4)
args = dict(zip(labels,loudness))
synth = Synth(self.server, "vqe_model1_4q", args)

for state in loudnessstream:
print(state)
for k, amp in state.items():
synth.set(EXAMPLE4[k], amp)
time.sleep(0.03)

# Mapping #3 - Pitchshifted Arpeggios instead of chords. Philip Glass vibes.
def note_cluster_intensity(self, data, **kwargs):
global FREQDICT
loudnessstream = data[0]
expect_values = data[1]

for v, state in enumerate(loudnessstream):
#print(state)
sorted_state = dict(sorted(state.items(), key=lambda item: item[1]))
print(sorted_state)
print(f" expected value: {expect_values[v]}")
print(f" shifted value: {(expect_values[v] - min(expect_values))/100}")
shifted_value = (expect_values[v] - min(expect_values))/200
for i, (k, amp) in enumerate(sorted_state.items()):
sy = Synth(self.server, "vqe_son2", {"note": FREQDICT[k], "amp":amp})
# sy = Synth(server, "vqe_son2", {"note": FREQDICT[k]+expect_values[v]-3, "amp":amp})
time.sleep(0.004+shifted_value)
#time.sleep(0.2)

# TODO: Refactor this deprecated function for v0.3
def note_loudness_multiple_rs(self, data, **kwargs):
raise ValueError("Old Subractive synthesis function is now deprecated.")
global NOTESDICT
loudnessstream = data[0]
expect_values = data[1]
Expand All @@ -174,32 +81,8 @@ def note_loudness_multiple_rs(self, data, **kwargs):
synth.set("shift", expect_values[v])
time.sleep(0.04)

# Mapping #9 - REALTIME
def note_loudness_multiple_rt(self, data, **kwargs):
global EXAMPLERT
loudnesses = data[0]


labels = ["amp1", "amp2", "amp3", "amp4"]

if not self.rt_synth:

silence = np.zeros(4)
args = dict(zip(labels,silence))
self.rt_synth = Synth(self.server, "vqh_rt_4q", args)

state = dict(zip(labels, loudnesses))
state = loudnesses[0]
#print(state, end="\r")
#print(state)
print(f"Mapper: (", end="")
for k, amp in state.items():
self.rt_synth.set(EXAMPLERT[k], amp)
print(f"{k}:{amp:.1f},", end="")
print(")", end="\r")

def note_loudness_rt(self, data, **kwargs):
global EXAMPLERT
loudnesses = data[0]


Expand Down Expand Up @@ -231,7 +114,7 @@ def note_loudness_rt(self, data, **kwargs):
print(")", end="\r")



# TODO: Remove dependency on global variables
def note_cluster_intensity_rt(self, data, **kwargs):
global FREQDICT
loudnessstream = data[0]
Expand All @@ -242,8 +125,6 @@ def note_cluster_intensity_rt(self, data, **kwargs):
sorted_state = dict(sorted(state.items(), key=lambda item: item[1]))
print(sorted_state)
print(f" expected value: {expect_values}")
#print(f" expected value: {expect_values}")
#print(f" shifted value: {(expect_values - min(expect_values))/100}")
print(f" shifted value: {(expect_values - (-32))/100}")
shifted_value = (expect_values - (-32))/400
for i, (k, amp) in enumerate(sorted_state.items()):
Expand Down
44 changes: 7 additions & 37 deletions synth/sonification_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,41 @@ def __init__(self):
}
self._library = {
1: {
"description": "Additive Synthesis with 12 chromatic notes",
"interface": "sc",
"mapping": "note_loudness_multiple"
},
2: {
"description": "Additive Synthesis with 8 chromatic notes",
"interface": "sc",
"mapping": "note_loudness_multiple_8_qubits"
},
3: {
"description": "Pitchshifted Arpeggios instead of chords",
"interface": "sc",
"mapping": "note_cluster_intensity"
},
4: {
"description": "Send data to Zen, to be stored as a new Book",
"interface": "zen",
"mapping": "post_book"
},
5: {
2: {
"description": "Send data to Zen, to be stored as a new Book, and send data to Processing to be displayed",
"interface": "zen",
"mapping": "post_book_and_update_display"
},
6: {
"description": "Additive Synthesis with 6 chromatic notes",
"interface": "sc",
"mapping": "note_loudness_multiple_6_qubits"
},
7: {
"description": "Additive Synthesis with 4 chromatic notes",
"interface": "sc",
"mapping": "note_loudness_multiple_4_qubits"
},
8: {
3: {
"description": "Subtractive synthesis with Pitchshift (dentist)",
"interface": "sc",
"mapping": "note_loudness_multiple_rs"
},
9: {
"description": "RealTime Synthesis",
"interface": "sc",
"mapping": "note_loudness_multiple_rt"
},
10: {
4: {
"description": "RealTime Arpeggios",
"interface": "sc",
"mapping": "note_cluster_intensity_rt"
},
11: {
5: {
"description": "Gereral RealTime OSC Mapping",
"interface": "osc",
"mapping": "publish_data"
},
12: {
6: {
"description": "Gerenal RealTime Additive Synthesis",
"interface": "sc",
"mapping": "note_loudness_rt"
},
13: {
7: {
"description": "Score Measure Manipulation Test",
"interface": "score",
"mapping": "update_stream"
},
14: {
8: {
"description": "Circular Book",
"interface": "zen",
"mapping": "post_page"
Expand Down
4 changes: 4 additions & 0 deletions synth/zen.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def post_page(self, data, **kwargs):
response = requests.post(self._page_url, data=json.dumps(data_msg), headers=self._headers)
print(f"We have composed page {response.json()['id']} of the Circular Book.")

#TODO: Migrate to new API
def post_book(self, data, **kwargs):
raise ValueError('This method is now deprecated')
"""Post a book to the database"""
bookid = self.get_last_book_id()
#bookid = "book_6"
Expand Down Expand Up @@ -85,7 +87,9 @@ def post_book(self, data, **kwargs):
self.current_data = data
response = requests.post(self._data_url, data=json.dumps(data_msg), headers=self._headers)

#TODO: Migrate to new API
def post_book_and_update_display(self, data, **kwargs):
raise ValueError('This method is now deprecated')
"""Post a book to the database"""
bookid = self.get_last_book_id()
#bookid = "book_6"
Expand Down

0 comments on commit 86eaec8

Please sign in to comment.