fluid waveform features are stackable or not

nix
Ted Moore 4 years ago
parent bab3661c25
commit 019c9cac50

@ -13,16 +13,17 @@ FluidViewer {
} }
FluidWaveform : FluidViewer { FluidWaveform : FluidViewer {
var <win;
*new { *new {
arg audioBuffer, slicesBuffer, featureBuffer, bounds, lineWidth = 1, waveformColor; arg audioBuffer, slicesBuffer, featureBuffer, bounds, lineWidth = 1, waveformColor, stackFeatures = false;
^super.new.init(audioBuffer,slicesBuffer, featureBuffer, bounds, lineWidth, waveformColor); ^super.new.init(audioBuffer,slicesBuffer, featureBuffer, bounds, lineWidth, waveformColor,stackFeatures);
} }
init { init {
arg audio_buf, slices_buf, feature_buf, bounds, lineWidth, waveformColor; arg audio_buf, slices_buf, feature_buf, bounds, lineWidth, waveformColor,stackFeatures = false;
Task{ Task{
var sfv, win, categoryCounter = 0; var sfv, categoryCounter = 0;
waveformColor = waveformColor ? Color(*0.5.dup(3)); waveformColor = waveformColor ? Color(*0.5.dup(3));
@ -30,6 +31,7 @@ FluidWaveform : FluidViewer {
bounds = bounds ? Rect(0,0,800,200); bounds = bounds ? Rect(0,0,800,200);
win = Window("FluidWaveform",bounds); win = Window("FluidWaveform",bounds);
win.background_(Color.white);
if(audio_buf.notNil,{ if(audio_buf.notNil,{
var path = "%%_%_FluidWaveform.wav".format(PathName.tmp,Date.localtime.stamp,UniqueID.next); var path = "%%_%_FluidWaveform.wav".format(PathName.tmp,Date.localtime.stamp,UniqueID.next);
@ -93,12 +95,24 @@ FluidWaveform : FluidViewer {
}); });
if(feature_buf.notNil,{ if(feature_buf.notNil,{
var stacked_height = bounds.height / feature_buf.numChannels;
feature_buf.loadToFloatArray(action:{ feature_buf.loadToFloatArray(action:{
arg fa; arg fa;
fa = fa.clump(feature_buf.numChannels).flop; fa = fa.clump(feature_buf.numChannels).flop;
fa.do({ fa.do({
arg channel; arg channel, channel_i;
channel = channel.resamp1(bounds.width).linlin(channel.minItem,channel.maxItem,bounds.height,0); var maxy;// a lower value;
var miny; // a higher value;
if(stackFeatures,{
miny = stacked_height * (channel_i + 1);
maxy = stacked_height * channel_i;
},{
miny = bounds.height;
maxy = 0;
});
channel = channel.resamp1(bounds.width).linlin(channel.minItem,channel.maxItem,miny,maxy);
UserView(win,Rect(0,0,bounds.width,bounds.height)) UserView(win,Rect(0,0,bounds.width,bounds.height))
.drawFunc_({ .drawFunc_({
Pen.moveTo(Point(0,channel[0])); Pen.moveTo(Point(0,channel[0]));

Loading…
Cancel
Save