FluidDataset: help file review, minor changes and formatting, FluidLabelSet: add print

nix
Gerard 6 years ago
parent a87df66e35
commit 2184ab3758

@ -11,8 +11,8 @@ FluidDataSet : FluidManipulationClient {
serverCaches = FluidServerCache.new; serverCaches = FluidServerCache.new;
} }
*at{ |server, id| *at{ |server, name|
^serverCaches.tryPerform(\at, server,id) ^serverCaches.tryPerform(\at, server, name)
} }
*new { |server, name| *new { |server, name|
@ -38,7 +38,6 @@ FluidDataSet : FluidManipulationClient {
^[ascii.size].addAll(ascii) ^[ascii.size].addAll(ascii)
} }
asString { asString {
^"FluidDataSet(%)".format(id).asString; ^"FluidDataSet(%)".format(id).asString;
} }

@ -93,4 +93,10 @@ FluidLabelSet : FluidManipulationClient {
*freeAll { |server| *freeAll { |server|
serverCaches.do(server,{|x|x.free;}); serverCaches.do(server,{|x|x.free;});
} }
print { |action|
action ?? {action = postit};
this.prSendMsg(\print,[],action,[string(FluidMessageResponse,_,_)]);
}
} }

@ -6,29 +6,27 @@ related:: Classes/FluidLabelSet, Classes/FluidKDTree, Classes/FluidKNN, Classes/
DESCRIPTION:: DESCRIPTION::
A server-side container associating labels with multi-dimensional data. FluidDataSet is identified by its name. A server-side container associating labels with multi-dimensional data. FluidDataSet is identified by its name.
CLASSMETHODS:: CLASSMETHODS::
PRIVATE:: asUGenInput PRIVATE:: asUGenInput
METHOD:: new 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) 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 ARGUMENT:: server
The link::Classes/Server:: on which to create the data set The link::Classes/Server:: on which to create the data set.
ARGUMENT:: name ARGUMENT:: name
A symbol or string with the name of the dataset. A symbol with the name of the dataset.
returns:: The new instance returns:: The new instance
METHOD:: at METHOD:: at
Retreives a cached instance of a FluidDataSet with the given name, or returns nil if no such object exists. Retrieves a cached instance of a FluidDataSet with the given name, or returns nil if no such object exists.
ARGUMENT:: server ARGUMENT:: server
The server associated with this dataset instance The server associated with this dataset instance.
ARGUMENT:: id ARGUMENT:: name
The name of the Dataset to retreive from the cache The name of the Dataset to retrieve from the cache.
INSTANCEMETHODS:: INSTANCEMETHODS::
@ -39,88 +37,51 @@ 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. 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. 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 ARGUMENT:: label
A symbol or string with the label for the new point A symbol or string with the label for the new point.
ARGUMENT:: buffer ARGUMENT:: buffer
A link::Classes/Buffer:: with the new data point A link::Classes/Buffer:: with the new data point.
ARGUMENT:: action ARGUMENT:: action
A function to run when the point has been added A function to run when the point has been added.
METHOD:: updatePoint 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. 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.
ARGUMENT:: label
symbol or string with the label
ARGUMENT:: buffer
A link::Classes/Buffer:: containing the updated data
ARGUMENT:: action
A function to run when the server has updated
METHOD:: size
Report the number of items currently in the data set
METHOD:: getPoint
Retreive a point from the data set into a link::Classes/Buffer::. Will report an error if the label or buffer doesn't exist
ARGUMENT:: label
symbol or string with the label to retreive
ARGUMENT:: buffer
link::Classes/Buffer:: to fill
ARGUMENT:: action
function to run when the point has been retreived
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 METHOD:: deletePoint
Remove a point from the data set. Will report an error if the label doesn't exist. Remove a point from the data set. Will report an error if the label doesn't exist.
ARGUMENT:: label
symbol or string with the label to remove
ARGUMENT:: action
Function to run when the point has been deleted
METHOD:: clear METHOD:: clear
Empty the data set Empty the data set.
ARGUMENT:: action
Function to run when the data set has been emptied
METHOD:: free METHOD:: free
Destroy the object on the server Destroy the object on the server.
METHOD:: cols
Report the dimensionality of the data set. If action is nil, will default to posting result.
ARGUMENT:: action
A function to run when the server responds, whose argument is the data set dimensionality. By default, the method will print the response to the post window.
METHOD:: size
Report the number of points in the data set. If action is nil, will default to posting result.
ARGUMENT:: action
A function to run when the server responds, whose argument is the data set size. By default, the method will print the response to the post window.
METHOD:: read METHOD:: read
Read a data set from a JSON file on disk Read a data set from a JSON file on disk.
ARGUMENT:: filename
The absolute path of the JSON file to read
ARGUMENT:: action
A function to run when the file has been read
METHOD:: write METHOD:: write
Write the data set to disk as a JSON file. Write the data set to disk as a JSON file.
ARGUMENT:: filename
Absolute path for the new file METHOD:: size
ARGUMENT:: action Report the number of items currently in the data set.
A function to run when the file has been written
METHOD:: cols
Report the dimensionality of the data set. If action is nil, will default to posting result.
METHOD:: dump METHOD:: dump
(buggy, please use Print for now) Post the content of the dataset in JSON format in the window by default, but you can supply a custom action instead; 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 METHOD:: print
Post an abbreviated content of the dataset in the window by default, but you can supply a custom action instead; Post an abbreviated content of the dataset in the window by default, but you can supply a custom action instead.
METHOD:: asString
Responds with the name of the data set as a pretty(ish) string
METHOD:: asSymbol
Responds with the name of the data set as a symbol
METHOD:: synth METHOD:: synth
The internal synth the object uses to communicate with the server The internal synth the object uses to communicate with the server
returns:: A link::Classes/Synth:: returns:: A link::Classes/Synth::
METHOD:: server METHOD:: server
@ -131,33 +92,46 @@ returns:: A link::Classes/Server::
EXAMPLES:: EXAMPLES::
CODE:: CODE::
// Make a one-dimensional data set called 'simple1data' // Create a simple a one-dimensional data set, three ways
( // Using routine
~ds = FluidDataSet.new(s,\simple1data,1); s.boot;
)
( (
Routine{ fork{
~ds.clear; ~ds = FluidDataSet.new(s,\simple1d_1);
// Make a buffer to use for adding points
~point = Buffer.alloc(s,1,1); ~point = Buffer.alloc(s,1,1);
//Add 10 points, using the index as a label.
s.sync; s.sync;
10.do{|i| 10.do{|i|
~point.set(0,i); ~point.set(0,i);
~ds.addPoint(i.asString,~point,{("addPoint"+i).postln}); ~ds.addPoint(i.asString,~point,{("addPoint"+i).postln});
s.sync; s.sync;
} };
}.play ~ds.dump; s.sync; ~ds.free;
};
) )
//Inspect the dataset using print (abbreviated output) or dump (JSON output) //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;
}
);
~ds.print //to post window by default, but you can supply a custom action instead // Using synth
~ds.dump //likewise (
//for example ~ds = FluidDataSet.new(s,\simple1d_3);
~ds.dump{ |d| ~dict = d } {
//Now we have a Dictionary of our data and IDs var trig = Impulse.kr(10);
~dict.postcs 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}}
)
:: ::

Loading…
Cancel
Save