Compare commits
2 Commits
9709555b98
...
d8f369fe55
Author | SHA1 | Date |
---|---|---|
Philipp Kramer | d8f369fe55 | |
Philipp Kramer | 0aa1308908 |
|
@ -20,7 +20,7 @@ import numpy as np #pip install numpy
|
|||
|
||||
|
||||
|
||||
scenetimes=[0,20,60,70,150,220,500] #definition of times . Last value will be overwritten by last time of csv file
|
||||
scenetimes=[0,20,60,70,120,150,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
|
||||
scenes =[0,1, 0, 2, 0, 3, -1] #definition of scenes. scene -1 will end the program
|
||||
|
||||
|
@ -31,10 +31,8 @@ currentScene=-1 #keeps track of current scene
|
|||
timemultiplier=1.0 #current time multiplier for speed changes
|
||||
|
||||
topicScene=['','','','']
|
||||
valueScene=['','','','']
|
||||
valueSceneOff=[0,0,0,0]
|
||||
timemultiplierScene=[1,1,1,1]
|
||||
|
||||
timemultiplierScene=[1,1,1,1] #only initializiation
|
||||
|
||||
stropheTriggered=False
|
||||
valueCommulative=0
|
||||
|
||||
|
@ -63,6 +61,7 @@ def init():
|
|||
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("--channel", type=int, default=1, help="The midi channel to use for osc topic")
|
||||
parser.add_argument("--file", type=str, default='heart_cluster_max.csv', help="The csv file used for data input")
|
||||
args = parser.parse_args()
|
||||
|
||||
global client
|
||||
|
@ -71,6 +70,9 @@ def init():
|
|||
global midiChannel
|
||||
midiChannel=args.channel
|
||||
print("Using midi Channel "+str(midiChannel))
|
||||
|
||||
csvfilename=args.file
|
||||
print("Using csv file "+str(csvfilename))
|
||||
|
||||
|
||||
# Initialize parameters for scenes
|
||||
|
@ -78,24 +80,20 @@ def init():
|
|||
|
||||
#Scene 1
|
||||
topicScene[1]="/"+str(midiChannel)+"/oscplayer/strophe"
|
||||
valueScene[1]=1
|
||||
stropheTriggered=False #keep track if it is already triggered once
|
||||
|
||||
#Scene 2
|
||||
topicScene[2]="/"+str(midiChannel)+"/oscplayer/satz/?"
|
||||
valueScene[2]=1
|
||||
|
||||
valueCommulative=0
|
||||
|
||||
#Scene 3
|
||||
topicScene[3]="/"+str(midiChannel)+"/oscplayer/value/?"
|
||||
valueScene[3]=1
|
||||
timemultiplierScene[3]=60.0 / 50 / 2
|
||||
|
||||
#########
|
||||
|
||||
csvlist=None
|
||||
with open('heart_cluster_max.csv', newline='') as csvfile: #check if file name is correct and in same dir. Maybe network drive?
|
||||
with open(csvfilename, newline='') as csvfile:
|
||||
csvreader = csv.reader(csvfile, delimiter=',', quotechar='|')
|
||||
csvlist = list(csvreader)
|
||||
'''for row in csvreader:
|
||||
|
@ -122,9 +120,14 @@ def init():
|
|||
|
||||
minvalues=[min([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)]
|
||||
|
||||
scenetimes[-1]=maxvalues[0] #take maximum value of first column (time) as endtime
|
||||
print("Scenetimes:" + str(scenetimes))
|
||||
|
||||
print("minvalues="+str(minvalues))
|
||||
print("maxvalues="+str(maxvalues))
|
||||
print("meanvalues="+str(meanvalues))
|
||||
|
||||
|
||||
|
||||
|
@ -160,7 +163,7 @@ def update(ctime):
|
|||
timeFromStart=ctime-time_start
|
||||
|
||||
|
||||
if currentScene!=getSceneFromTime(timeFromStart): #scene changed
|
||||
if currentScene!=getSceneFromTime(timeFromStart): #When scene changed
|
||||
currentScene=getSceneFromTime(timeFromStart)
|
||||
timemultiplier=timemultiplierScene[currentScene] #update speed
|
||||
|
||||
|
@ -175,6 +178,16 @@ def update(ctime):
|
|||
print("Updated Row Id from "+str(_rowidBefore)+" to "+str(rowid)+" of "+str(len(rows)))
|
||||
|
||||
print("t="+str(timeFromStart)+"s: Changed Scene to "+str(currentScene)+". timemultiplier="+str(timemultiplier))
|
||||
|
||||
|
||||
# Below here things that should happen once on scene change to "currentScene"
|
||||
if currentScene==3: #on scene change to 3
|
||||
sendOSCTrigger("/sprachsamples/beatrepeatonoff")
|
||||
|
||||
if currentScene==-1: #ended
|
||||
sendOSCTrigger("/stopcommand")
|
||||
sendOSCTrigger("/sprachsamples/beatrepeatonoff")
|
||||
|
||||
|
||||
|
||||
'''if rowid>=len(rows): #ended?
|
||||
|
@ -190,14 +203,13 @@ def update(ctime):
|
|||
value=float(crow[i+1])
|
||||
|
||||
if (i==0): #were only using the first column of the csv file
|
||||
#Below here things that should happen when in "currentScene" every time new data from the csv file is read
|
||||
if currentScene==1:
|
||||
if not stropheTriggered:
|
||||
_threshold=(minvalues[i+1]+(maxvalues[i+1]-minvalues[i+1])*0.2)
|
||||
print("waiting for "+str(value)+"<"+str(_threshold))
|
||||
if value<_threshold or getSceneFromTime(timeFromStart+1)!=currentScene: #trigger "randomly" or when scene is about to change
|
||||
print("OSC: "+topicScene[currentScene]+": "+str(valueScene[currentScene]))
|
||||
client.send_message(topicScene[currentScene], valueScene[currentScene])
|
||||
client.send_message(topicScene[currentScene], valueSceneOff[currentScene])
|
||||
sendOSCTrigger(topicScene[currentScene])
|
||||
stropheTriggered=True
|
||||
|
||||
if currentScene==2:
|
||||
|
@ -207,15 +219,12 @@ def update(ctime):
|
|||
if valueCommulative>100:
|
||||
valueCommulative=0 #reset
|
||||
sendvalue=int(mapRangeConstrain(value,minvalues[i+1],maxvalues[i+1],1,4))
|
||||
print("OSC: "+topicScene[currentScene].replace('?',str(sendvalue))+": "+str(valueScene[currentScene]))
|
||||
client.send_message(topicScene[currentScene].replace('?',str(sendvalue)), valueScene[currentScene])
|
||||
client.send_message(topicScene[currentScene].replace('?',str(sendvalue)), valueSceneOff[currentScene])
|
||||
sendOSCTrigger(topicScene[currentScene].replace('?',str(sendvalue)))
|
||||
|
||||
if currentScene==3:
|
||||
sendvalue=int(mapRangeConstrain(value,minvalues[i+1],maxvalues[i+1],1,40))
|
||||
print("OSC: "+str(rowid)+"/"+str(len(rows))+" t="+str(round(timeFromStart,2))+" "+topicScene[currentScene].replace('?',str(sendvalue))+": "+str(valueScene[currentScene]))
|
||||
client.send_message(topicScene[currentScene].replace('?',str(sendvalue)), valueScene[currentScene])
|
||||
client.send_message(topicScene[currentScene].replace('?',str(sendvalue)), valueSceneOff[currentScene])
|
||||
sendOSCTrigger(topicScene[currentScene].replace('?',str(sendvalue)))
|
||||
print("OSC: "+str(rowid)+"/"+str(len(rows))+" t="+str(round(timeFromStart,2)))
|
||||
|
||||
|
||||
|
||||
|
@ -240,6 +249,10 @@ def mapRange(value, inMin, inMax, outMin, outMax):
|
|||
def mapRangeConstrain(v,minIn,maxIn,minOut,maxOut): #include minOut and maxOut and constrain
|
||||
return int(max(minOut,min(maxOut,mapRange(v,minIn,maxIn,minOut,maxOut+1))))
|
||||
|
||||
def sendOSCTrigger(mesg):
|
||||
print("OSC: "+str(mesg)+" : 1 and 0")
|
||||
client.send_message(str(mesg), 1)
|
||||
client.send_message(str(mesg), 0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
init()
|
||||
|
@ -247,4 +260,4 @@ if __name__ == "__main__":
|
|||
|
||||
res=True
|
||||
while res:
|
||||
res=update(time.time())
|
||||
res=update(time.time())
|
||||
|
|
Loading…
Reference in New Issue