scene changes

This commit is contained in:
Philipp Kramer 2022-05-17 09:54:09 +02:00
parent d8f369fe55
commit 5a58b14c5d

View file

@ -20,9 +20,11 @@ import numpy as np #pip install numpy
scenetimes=[0,20,60,70,120,150,500] #definition of times . Last value will be overwritten by last time of csv file scenetimes=[0,10,60,70,130,150,155,210,220,290,500] #definition of times . Last value will be overwritten by last time of csv file
#scenetimes=[0,2,4,5,6,10,300] #definition of times FASTER FOR TESTING #scenetimes=[0,2,4,5,6,10,300] #definition of times FASTER FOR TESTING
scenes =[0,1, 0, 2, 0, 3, -1] #definition of scenes. scene -1 will end the program scenes =[0,1, 0, 2, 0 ,3 , 0, 3 , 0, 3, -1] #definition of scenes. scene -1 will end the program
scenes =[0,2,2,2,2,2,2,2,2,2, -1] #definition of scenes. scene -1 will end the program
currentScene=-1 #keeps track of current scene currentScene=-1 #keeps track of current scene
@ -60,7 +62,7 @@ def init():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1", help="The ip of the OSC server") parser.add_argument("--ip", default="127.0.0.1", help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=7005, help="The port the OSC server is listening on") parser.add_argument("--port", type=int, default=7005, help="The port the OSC server is listening on")
parser.add_argument("--channel", type=int, default=1, help="The midi channel to use for osc topic") parser.add_argument("--channel", type=int, default=None, help="The midi channel to use for osc topic. Default=Automatic")
parser.add_argument("--file", type=str, default='heart_cluster_max.csv', help="The csv file used for data input") parser.add_argument("--file", type=str, default='heart_cluster_max.csv', help="The csv file used for data input")
args = parser.parse_args() args = parser.parse_args()
@ -75,20 +77,6 @@ def init():
print("Using csv file "+str(csvfilename)) print("Using csv file "+str(csvfilename))
# Initialize parameters for scenes
#Scene 0
#Scene 1
topicScene[1]="/"+str(midiChannel)+"/oscplayer/strophe"
stropheTriggered=False #keep track if it is already triggered once
#Scene 2
topicScene[2]="/"+str(midiChannel)+"/oscplayer/satz/?"
valueCommulative=0
#Scene 3
topicScene[3]="/"+str(midiChannel)+"/oscplayer/value/?"
timemultiplierScene[3]=60.0 / 50 / 2
######### #########
@ -107,12 +95,17 @@ def init():
global rows global rows
rows=csvlist[1:] #discard first row/header rows=csvlist[1:] #discard first row/header
rows = [x for x in rows if float(x[1])>40] #filter out rows with value <40
global rowid global rowid
rowid=0 #waiting for this row to send rowid=0 #waiting for this row to send
global lastvalue global lastvalue
lastvalue=np.zeros(len(rows)-1) lastvalue=np.zeros(len(rows)-1)
global minvalues global minvalues
global maxvalues global maxvalues
global meanvalues global meanvalues
@ -122,15 +115,37 @@ def init():
maxvalues=[max([float(a) for a in x]) for x in filterEmpty(rows)] maxvalues=[max([float(a) for a in x]) for x in filterEmpty(rows)]
meanvalues=[np.mean([float(a) for a in x]) for x in filterEmpty(rows)] meanvalues=[np.mean([float(a) for a in x]) for x in filterEmpty(rows)]
if midiChannel is None:
midiChannel=int(mapRangeConstrain(float(rows[0][1]),minvalues[1],maxvalues[1],1,16))
print("Using midi Channel "+str(midiChannel))
scenetimes[-1]=maxvalues[0] #take maximum value of first column (time) as endtime scenetimes[-1]=maxvalues[0] #take maximum value of first column (time) as endtime
scenetimes[-2]=maxvalues[0]-20
print("Scenetimes:" + str(scenetimes)) print("Scenetimes:" + str(scenetimes))
print("minvalues="+str(minvalues)) print("minvalues="+str(minvalues))
print("maxvalues="+str(maxvalues)) print("maxvalues="+str(maxvalues))
print("meanvalues="+str(meanvalues)) print("meanvalues="+str(meanvalues))
# Initialize parameters for scenes
#Scene 0
#Scene 1
topicScene[1]="/"+str(midiChannel)+"/oscplayer/strophe"
stropheTriggered=False #keep track if it is already triggered once
#Scene 2
topicScene[2]="/"+str(midiChannel)+"/oscplayer/satz/?"
valueCommulative=0
#Scene 3
topicScene[3]="/"+str(midiChannel)+"/oscplayer/value/?"
timemultiplierScene[3]=60.0 / 50 / 2
#print(np.mean(np.array((filterEmpty(rows))),axis=1)) #TODO: mittelwert ausrechnen funktioniert noch nicht #print(np.mean(np.array((filterEmpty(rows))),axis=1)) #TODO: mittelwert ausrechnen funktioniert noch nicht
#exit() #exit()
#meanvalues=[float(np.mean(x)) for x in filterEmpty(rows)] #meanvalues=[float(np.mean(x)) for x in filterEmpty(rows)]
@ -214,10 +229,11 @@ def update(ctime):
if currentScene==2: if currentScene==2:
print("waiting. diff="+str(abs(maxvalues[i+1]-value))+" commulative="+str(valueCommulative)) print("waiting. diff="+str(abs(maxvalues[i+1]-value))+" commulative="+str(valueCommulative))
valueCommulative+=abs(maxvalues[i+1]-value) #valueCommulative+=abs(maxvalues[i+1]-value)
valueCommulative+=mapRangeConstrain(value,minvalues[i+1],maxvalues[i+1],0,100)
if valueCommulative>100: if valueCommulative>500: #higher value triggers less
valueCommulative=0 #reset valueCommulative-=500 #reset
sendvalue=int(mapRangeConstrain(value,minvalues[i+1],maxvalues[i+1],1,4)) sendvalue=int(mapRangeConstrain(value,minvalues[i+1],maxvalues[i+1],1,4))
sendOSCTrigger(topicScene[currentScene].replace('?',str(sendvalue))) sendOSCTrigger(topicScene[currentScene].replace('?',str(sendvalue)))
@ -242,6 +258,8 @@ def filterEmpty(rows):
n=[list(filter(None, x)) for x in n] n=[list(filter(None, x)) for x in n]
return n return n
def mapRange(value, inMin, inMax, outMin, outMax): def mapRange(value, inMin, inMax, outMin, outMax):
return outMin + (((value - inMin) / (inMax - inMin)) * (outMax - outMin)) return outMin + (((value - inMin) / (inMax - inMin)) * (outMax - outMin))