Created
January 16, 2014 09:24
-
-
Save miguel-negrao/8452073 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/local/bin/sclang -l/home/miguel/bin/langconf.yaml | |
( | |
var jack_device = if("jack_lsp | grep firewire".systemCmd == 0){ | |
"firewire_pcm" | |
}{ | |
"system" | |
}; | |
"SC_JACK_DEFAULT_INPUTS".setenv(jack_device); | |
"SC_JACK_DEFAULT_OUTPUTS".setenv(jack_device); | |
"Starting file player".postln; | |
q = (); | |
//start server | |
q.server = Server("fileplayer",NetAddr("localhost",57555)); | |
q.server.options.numWireBufs_(1024).numInputBusChannels_(0).numOutputBusChannels_(8); | |
q.server.makeWindow; | |
q.server.boot; | |
ULib.servers = [q.server]; | |
//ULib.startup; | |
UGlobalEQ.gui; | |
//soundfileview | |
q.sview = SoundFileView(); | |
q.sview.timeCursorOn = true; | |
q.sview.timeCursorColor = Color.red; | |
q.sview.drawsWaveForm = true; | |
q.sview.gridOn = true; | |
q.sview.gridResolution = 0.2; | |
q.sview.elasticMode = true; | |
q.sview.action_{ | |
q.smpte.pos_(q.sview.timeCursorPosition/q.sf.sampleRate); | |
q.smpte.view.refresh; | |
}; | |
q.sf = SoundFile.new; | |
//buttons | |
q[\play] = Button().states_([["play"],["stop"]]).action_{ |v| | |
var pos; | |
if(v.value == 1) { | |
q.chain = UChain(*[[ 'diskSoundFile', | |
[\level,q.volGui.value, 'soundFile', DiskSndFile.newBasic(q.path, q.sf.numFrames, q.sf.numChannels, | |
q.sf.sampleRate, q.sview.timeCursorPosition, q.sf.numFrames, 1, false) ] ]]++ | |
switch(q.modesGui.value) | |
{0}{[[ 'output', [ 'numChannels', q.sf.numChannels ]]] } | |
{1}{ [[ 'mixdown', [ 'numChannels', q.sf.numChannels ]] ] } | |
{2}{[]} | |
{[]} | |
); | |
q.chain.useSndFileDur; | |
if(q.ctl.notNil){ q.ctl.remove }; | |
q.ctl = SimpleController(q.chain); | |
q.ctl.put(\end, { { q[\play].value_(0) }.defer; q.playTask.stop; }); | |
q.chain.prepareAndStart; | |
pos = q.sview.timeCursorPosition; | |
q.playTask = Routine({ | |
loop{ | |
0.1.wait; | |
defer{ | |
pos = pos + (0.1*q.sf.sampleRate); | |
q.sview.timeCursorPosition = pos; | |
q.smpte.pos_(pos/q.sf.sampleRate); | |
q.smpte.view.refresh; | |
}; | |
} | |
}).play | |
} { | |
q.chain.stop; | |
q.playTask.stop; | |
} | |
}; | |
q.filepickBut = Button().states_([["open file"]]).action_{ | |
Dialog.openPanel({ |path| | |
q[\setFile].(path); | |
},multipleSelection:false); | |
}; | |
q.infoGui = StaticText().string_(""); | |
q.modesGui = PopUpMenu().items_(["direct","stereo","binaural"]); | |
q.volGui = Slider().orientation_(\vertical).value_(1).action_{ |v| | |
if(q.chain.notNil){ | |
q.chain.setAt(0, \level, v.value) | |
} | |
}; | |
q.smpte = SMPTEView(()); | |
q.listGui = ListView().maxWidth_(200) | |
.enterKeyAction_{ q[\setFile].(q.listDir++"/"++q.listGui.item); }; | |
q.updateListButton = Button().states_([["load dir"]]) | |
.action_{ | |
Dialog.openPanel({ |path| | |
q.listDir = path.dirname; | |
//q.listGui.items = (++"/*").pathMatch; | |
q.listGui.items = q.listDir.findPathsInDirectory; | |
},multipleSelection:false); | |
}; | |
q.meterView = ServerMeterView(q.server, (), 0@0, 0, 8); | |
q.meterView.view.minWidth_(190); | |
q.meterView.view.minHeight_(230); | |
w = Window.new("SF player -", Rect(200, 300, 1000, 700)) | |
.layout_(HLayout( | |
VLayout(q.meterView.view, q.listGui, q.updateListButton), | |
VLayout( | |
q.sview, | |
q.infoGui, | |
HLayout( | |
q.filepickBut, q[\play], q.modesGui, q.smpte.view )), | |
q.volGui | |
)); | |
w.view.keyDownAction_{ |a,b,c,d| | |
if(d== 32) { | |
var current = q[\play].value; | |
q[\play].valueAction_(current.asBoolean.not.binaryValue); | |
} | |
}; | |
w.front; | |
//action | |
q[\setFile] = { |path| | |
if(q.chain.notNil){q.chain.stop}; | |
q.path = path; | |
q.sf.openRead(q.path); | |
q.sview.soundfile = q.sf; | |
q.sview.read(0, q.sf.numFrames); | |
q.sview.timeCursorPosition = 0; | |
//q.pathSv.string_(q.path); | |
w.name_("SF player - "++path); | |
q.infoGui.string_("% | % | %Khz | %ch | %".format(q.sf.headerFormat, q.sf.sampleFormat, q.sf.sampleRate/1000, q.sf.numChannels, SMPTE(q.sf.numFrames/q.sf.sampleRate).toString)); | |
}; | |
q[\setFile].("/home/miguel/Audio/188551__mika55__drum-solo-120-bpm.wav"); | |
q.server.doWhenBooted{ | |
"/home/miguel/Development/SuperCollider/Unit Lib/UnitDefs/diskSoundFile.scd".load; | |
"/home/miguel/Development/SuperCollider/Unit Lib/UnitDefs/output.scd".load; | |
"/home/miguel/.local/share/SuperCollider/UnitDefs/mixdown.scd".load; | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment