diff --git a/oscplayer/oscplayer.py b/oscplayer/oscplayer.py index 5ba0069..74a0985 100644 --- a/oscplayer/oscplayer.py +++ b/oscplayer/oscplayer.py @@ -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 @@ -33,8 +33,8 @@ 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 +63,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 +72,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 @@ -95,7 +99,7 @@ def init(): ######### 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: @@ -160,7 +164,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 +179,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,6 +204,7 @@ 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) @@ -240,6 +255,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 +266,4 @@ if __name__ == "__main__": res=True while res: - res=update(time.time()) \ No newline at end of file + res=update(time.time())