You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.8 KiB
Plaintext

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

TITLE:: FluidDataSet
summary:: Container for labelled, multidimensional data
categories:: UGens>FluidManipulation
related:: Classes/FluidLabelSet, Classes/FluidKDTree, Classes/FluidKNN, Classes/FluidKMeans
DESCRIPTION::
A server-side container associating labels with multi-dimensional data. FluidDataSet is identified by its name.
CLASSMETHODS::
PRIVATE:: asUGenInput
METHOD:: new
Create a new instance of the dataset, with the given name. If a Dataset with this name already exists, an exception will be thrown (see link::Classes/FluidDataSet#at:: to access an extant Dataset).
ARGUMENT:: server
The link::Classes/Server:: on which to create the data set.
ARGUMENT:: name
A symbol with the name of the dataset.
returns:: The new instance
METHOD:: at
Retrieves a cached instance of a FluidDataSet with the given name, or returns nil if no such object exists.
ARGUMENT:: server
The server associated with this dataset instance.
ARGUMENT:: name
The name of the Dataset to retrieve from the cache.
INSTANCEMETHODS::
PRIVATE:: init,id,cache
METHOD:: addPoint
Add a new point to the data set. The dimensionality of the dataset is governed by the size of the first point added.
Will report an error if the label already exists, or if the size of the data does not match the dimensionality of the dataset.
ARGUMENT:: label
A symbol or string with the label for the new point.
ARGUMENT:: buffer
A link::Classes/Buffer:: with the new data point.
ARGUMENT:: action
A function to run when the point has been added.
METHOD:: updatePoint
Update an existing label's data. Will report an error if the label doesn't exist, or if the size of the data does not match the given dimensionality of the dataset.
METHOD:: getPoint
Retrieve a point from the data set into a link::Classes/Buffer::. Will report an error if the label or buffer doesn't exist.
METHOD:: deletePoint
Remove a point from the data set. Will report an error if the label doesn't exist.
METHOD:: clear
Empty the data set.
METHOD:: free
Destroy the object on the server.
METHOD:: read
Read a data set from a JSON file on disk.
METHOD:: write
Write the data set to disk as a JSON file.
METHOD:: size
Report the number of items currently in the data set.
METHOD:: cols
Report the dimensionality of the data set. If action is nil, will default to posting result.
METHOD:: dump
Get the contents of the dataset as a Dictionary (note: uses a temporary file under the hood);
METHOD:: load
Fill the dataset with the contents of a dictionary, replacing its current contents (note: uses a temporary file under the hood).
METHOD:: print
Post an abbreviated content of the dataset in the window by default, but you can supply a custom action instead.
METHOD:: synth
The internal synth the object uses to communicate with the server
returns:: A link::Classes/Synth::
METHOD:: server
The server instance the object uses
returns:: A link::Classes/Server::
EXAMPLES::
CODE::
// Create a simple a one-dimensional data set, three ways
// Using routine
s.boot;
(
fork{
~ds = FluidDataSet.new(s,\simple1d_1);
~point = Buffer.alloc(s,1,1);
s.sync;
10.do{|i|
~point.set(0,i);
~ds.addPoint(i.asString,~point,{("addPoint"+i).postln});
s.sync;
};
~ds.dump; s.sync; ~ds.free;
};
)
//Using Dictionary
(
d = Dictionary.new;
d.add(\cols -> 1);
d.add(\data -> Dictionary.newFrom(10.collect{|i|[i.asString, [i.asFloat]]}.flatten));
fork{
~ds = FluidDataSet.new(s,\simple1d_2); s.sync;
~ds.load(d); s.sync;
~ds.dump; s.sync; ~ds.free;
}
);
// Using synth
(
~ds = FluidDataSet.new(s,\simple1d_3);
{
var trig = Impulse.kr(10);
var count = PulseCount.kr(trig) - 1;
var buf = LocalBuf(1);
BufWr.kr(count, buf);
FluidDataSetWr.kr(\simple1d_3, buf: buf, trig: trig);
FreeSelf.kr(count - 8);
}.play.onFree{~ds.dump{|o| o.postln; ~ds.free}}
)
::