Created
September 26, 2011 15:12
-
-
Save moxuse/1242464 to your computer and use it in GitHub Desktop.
SimpleOscPlay
This file contains hidden or 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
( | |
var indexNum,window,portText,hostText,addresText,address,slideView, | |
numArray,bufferArray,pattern,valMonitor,playButton,resetButton,task,host,port, | |
stDist,scale,scaleTex,scaleTexField,poler,modePopup; | |
///////////priset destination OSC/////// | |
host = "127.0.0.1"; | |
port = 5000; | |
address = "/value"; | |
///////////////////////////////// | |
numArray=100; | |
window = Window.new("SimpleOSCPlayer"); | |
indexNum = 0; | |
scale = 1; | |
poler = 0; | |
bufferArray = Array.fill(100, {0}); | |
window.bounds = Rect(10, 410, 1330, 160); | |
pattern = Pseq(bufferArray,inf).asStream; | |
valMonitor = TextField.new(window, Rect(75,120,60,20)); | |
slideView = MultiSliderView(window,Rect(10,10,100*13+2,100)); | |
slideView.elasticMode_(1); | |
slideView.value=Array.fill(numArray, {|v| 0}); | |
slideView.reference=Array.fill(numArray, {|v| 0}); | |
slideView.action = { | |
arg q; bufferArray = q.value; | |
pattern = Pseq(bufferArray,inf).asStream; | |
indexNum = 0; | |
}; | |
slideView.isFilled_ (true); | |
slideView.drawLines_(true); | |
slideView.drawRects_(false); | |
slideView.fillColor_(Color(0.0,0.6,0.4,0.8)); | |
slideView.setProperty(\showIndex, true); | |
slideView.indexThumbSize_(2); | |
hostText = TextField.new(window, Rect(250,120,90,20)); | |
portText = TextField.new(window, Rect(350,120,90,20)); | |
addresText = TextField.new(window, Rect(450,120,90,20)); | |
scaleTex = TextField.new(window, Rect(1160,120,40,20)); | |
stDist = StaticText.new(window, Rect(180,120,90,20)).string_("destination:"); | |
scaleTexField = StaticText.new(window, Rect(1125,120,90,20)).string_("scale:"); | |
portText.string = port; | |
hostText.string = host; | |
addresText.string = address; | |
scaleTex.string = scale; | |
portText.action = {arg field; port = field.value.asInteger}; | |
hostText.action = {arg field; host = field.value}; | |
addresText.action = {arg field; address = field.value}; | |
scaleTex.action = {arg field; scale = field.value.asFloat}; | |
modePopup = PopUpMenu.new(window, Rect(1220,120,90,20)); | |
modePopup.items = ["liner","bipolar"]; | |
modePopup.action = {|menu| | |
if(menu.value == 0,{poler = 0; | |
slideView.reference=Array.fill(numArray, {|v| 0}); | |
},{ | |
poler = 1; | |
slideView.reference=Array.fill(numArray, {|v| 0.5}); | |
}); | |
}; | |
task = Task({ | |
inf.do({|i| | |
var messageVal; | |
if(poler == 0,{ | |
messageVal = pattern.next *scale; //your value | |
},{ | |
messageVal = pattern.next-0.5; | |
if(messageVal<0,{messageVal = 0 + messageVal}); | |
messageVal = messageVal*scale*2; | |
}); | |
defer{valMonitor.value_(messageVal); | |
slideView.index = indexNum; | |
}; | |
NetAddr(host,port).sendMsg(address,messageVal); // your mssage | |
0.025.wait; //wait time for loop | |
if(indexNum<100,{ | |
indexNum = indexNum+1; | |
},{indexNum = 0}); | |
}); | |
}); | |
playButton = Button(window, Rect(10,120,30,30)) | |
.states_([ | |
["play", Color.white, Color.gray], | |
["stop", Color.black, Color(0.0,0.9,0.5,0.9)], | |
]) | |
.action_({ arg butt; | |
if(butt.value==1,{ | |
task.play; | |
},{ | |
task.stop; | |
}); | |
}); | |
resetButton = Button(window, Rect(50,120,10,30)) | |
.states_([ | |
["<", Color.white, Color.black] | |
]) | |
.action_({ arg butt; | |
pattern.reset; | |
indexNum = 0 | |
}); | |
window.front; | |
window.onClose_({task.stop}); | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment