Created
September 29, 2021 19:25
-
-
Save julianrubisch/13421b071be98558e7baa5f51c6bd556 to your computer and use it in GitHub Desktop.
Supercollider OOP - Part 2: Pluggable Views
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
VBufferCollection { | |
var <buffers, views; | |
*new { |server, numBuffersOrPaths, numFrames=0, numChannels=1| | |
^super.new.init(server, numBuffersOrPaths, numFrames, numChannels); | |
} | |
init { |server, numBuffersOrPaths, numFrames=0, numChannels=1| | |
buffers = case | |
{numBuffersOrPaths.class == PathName && {numBuffersOrPaths.isFolder}} { | |
// is a directory | |
numBuffersOrPaths.entries.select({ |fileOrDir| fileOrDir.isFile }).collect({ | |
|path| | |
// TODO try to monofy in place | |
Buffer.readChannel(server, path.fullPath, channels: [0]) | |
}); | |
} | |
{numBuffersOrPaths.isArray && {numBuffersOrPaths.every { |path| path.class == PathName && path.isFile }}} { | |
// is an array of file paths | |
numBuffersOrPaths.collect { |path| | |
Buffer.read(server, path) | |
} | |
} | |
{numBuffersOrPaths.isInteger} { | |
numBuffersOrPaths.collect { | |
Buffer.alloc(server, numFrames, numChannels); | |
} | |
}; | |
} | |
// we want to lazily initialize those | |
views { |parent| | |
views = this.prMakeViews(parent); | |
^views; | |
} | |
prMakeViews { |parent| | |
^buffers.collect { |buffer| | |
BufferSoundFileView.new(parent, nil, buffer); | |
} | |
} | |
} | |
BufferSoundFileView : SoundFileView { | |
var buffer; | |
*new { |parent, bounds, buffer| | |
^super.new.init(parent, bounds, buffer); | |
} | |
init { |parent, bounds, buffer| | |
buffer = buffer; | |
buffer.getToFloatArray(timeout: 30, action: { |samples| | |
{ | |
this.setData(samples); | |
this.refresh; | |
}.defer; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment