Object:
Filter:
Classes | Core > Kernel | Language > OOP

Object

abstract superclass of all objects
Source: Object.sc
Subclasses: AbstractDispatcher, AbstractFunction, AbstractMDPlugin, AbstractMessageMatcher, … see all

Description

Object is the root class of all other classes. All objects are indirect instances of class Object. We call the "receiver" the object the message is sent to: receiver.method(argument).

Class Methods

Object.readArchive(pathname)

Read in an object from a text archive.

Arguments:

pathname

A String containing the archive file's path.

Object.new(maxSize: 0)

Create a new instance. The creation of new instances of any Object actually happens in this method (or with newCopyArgs) when it is called by a child class. See Writing Classes.

Object.newCopyArgs( ... args)

Creates a new instance and copies the arguments to the instance variables in the order that the variables were defined. If the superclass's new method requires arguments, the first arguments passed to newCopyArgs will be passed on to that method, and the following arguments will be copied to this class's instance variables. Class variables are ignored.

Undocumented class methods

Object.dependantsDictionary

Object.implClass

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/backwardsCompatibility/classNameRedirects.sc

Object.readBinaryArchive(pathname)

Object.readTextArchive(pathname)

Object.uniqueMethods

Instance Methods

Class Membership

.class

Answer the class of the receiver.

.respondsTo(aSymbol)

Answer a Boolean whether the receiver understands the message selector.

Arguments:

aSymbol

A selector name. Must be a Symbol.

.isKindOf(aClass)

Answer a Boolean indicating whether the receiver is a direct or indirect instance of aClass. Use of this message in code must be questioned, because it often indicates a missed opportunity to exploit object polymorphism.

.isMemberOf(aClass)

Answer a Boolean whether the receiver is a direct instance of aClass. Use of this message in code is almost always a design mistake.

Accessing

.size

Different classes respond to this message differently. Object always returns 0.

Copying

.copy

Make a copy of the receiver. The implementation of this message depends on the object's class. In class Object, copy calls shallowCopy.

.shallowCopy

Makes a copy of the object. The copy's named and indexed instance variables refer to the same objects as the receiver.

.deepCopy

Recursively copies the object and all of the objects contained in the instance variables, and so on down the structure. This method works with cyclic graphs.

.copyImmutable

If object is immutable then return a shallow copy, else return receiver.

Conversion

To convert an object of a certain class into a similar object of another class, Object provides a number of methods.

.as(aSimilarClass)

Returns a similar new Object of a different class.

.asArray

Returns an Array with the receiver, unless it is an Array already.

.asCompileString

Returns a String that can be interpreted to reconstruct a copy of the receiver. For the complementary method, see String: -interpret.

.asInt

From extension in /usr/local/share/SuperCollider/SCClassLibrary/deprecated/3.11/deprecated-3.11.sc

Deprecated. Use asInteger instead.

.cs

Shorthand for -asCompileString.

Archiving

Object implements methods for writing and retrieving objects from disk. Note that you cannot archive instances of Thread and its subclasses (i.e. Routine), or open Functions (i.e., a Function which refers to variables from outside its own scope).

.writeArchive(pathname)

Write an object to disk as a text archive.

Arguments:

pathname

A String containing the resulting file's path.

Equality and Identity

==(obj)

Answer whether the receiver equals anotherObject. The definition of equality depends on the class of the receiver. The default implementation in Object is to answer if the two objects are identical.

NOTE: Whenever == is overridden in a class, hash should be overridden as well.

===(obj)

Answer whether the receiver is the exact same object as anotherObject.

!=(obj)

Answer whether the receiver does not equal anotherObject. The default implementation in Object is to determine '==' for the two operands and negate this result. (see below).

!==(obj)

Answer whether the receiver is not identical to anotherObject.

|==|(that)

A lazy equality operator. For typical object types, |==| behaves the same as Object: -==. For AbstractFunction and its subclasses (including Pattern and UGen), it does not perform the equality check immediately, but rather composes an equality operation to be performed at the time of evaluating the resulting function or stream.

|!=|(that)

A lazy inequality operator, defined as not(this |==| that). See Object: -|==|.

.fuzzyEqual(that, precision: 1.0)

Returns the degree of equality between two objects with regard to a given precision. Objects to compare must support max, substraction, and division.

Returns:

A number in the range 0 to 1.

.compareObject(that, instVarNames)

Tests if two Objects (of the same class) are the same in a certain respect: It returns true if instVarNames are equal in both. If none are given, all instance variables are tested (see also: -instVarHash)

.hash

Answer a code used to index into a hash table. This is used by Dictionary and Set and their subclasses to implement fast object lookup. Objects which are equal == should have the same hash values. Whenever == is overridden in a class, hash should be overridden as well.

.identityHash

Answer a code used to index into a hash table. This method is implemented by a primitive and is not overridden. Objects which are identical === should have the same hash values.

.instVarHash(instVarNames)

Returns a combined hash value for the object's instance variables and the object's class. If none are given, all instance variables are tested (see also: -compareObject).

Testing

.isNil

Answer a Boolean indicating whether the receiver is nil.

.notNil

Answer a Boolean indicating whether the receiver is not nil.

.isNumber

Answer a Boolean indicating whether the receiver is an instance of Number.

.isInteger

Answer a Boolean indicating whether the receiver is an instance of Integer.

.isFloat

Answer a Boolean indicating whether the receiver is an instance of Float.

?(obj)

If the receiver is nil then answer anObject, otherwise answer the receiver.

??(obj)

If the receiver is nil, evaluate the Function and return the result.

!?(obj)

If the receiver is not nil, evaluate the Function passing in the receiver as argument and return the result, otherwise return nil.

NOTE: The function will be inlined if it contains no variables or arguments.

Discussion:

This method allow building up chains of actions to be performed on an object (possibly across several methods) without having to check if the object is nil or not. After all the desired actions are performed, -?? can be used to check if result the result is nil and supply a default value in that case.

Examples:

With x = nil, this will result in:

It was a nil, so I give a default value
Point( 1, 1 )

But if x = Point(3,4), the result will be:

Point( 9, 12 )

Nested nil checks:

Results in nil

Results in 87.321245982865

.pointsTo(obj)

Returns true if receiver has a direct reference to obj.

.mutable

Returns true if receiver is mutable.

.frozen

Returns true if receiver is frozen.

.switch( ... cases)

Object implements a switch method which allows for conditional evaluation with multiple cases. These are implemented as pairs of test objects (tested using if this == test.value) and corresponding functions to be evaluated if true. In order for switch to be inlined (and thus be as efficient as nested if statements) the matching values must be literal Integers, Floats, Chars, Symbols and the functions must have no variables or arguments.

Discussion:

or:

Messaging

Instead of directly sending a method to an object, a method may be invoked given a method selector only (a Symbol). The other arguments may be provided by passing them directly, from an environment. If it is not known whether the receiver implements the method, tryPerform only sends if it does, and superPerform invokes the method of the superclass.

.perform(selector ... args)

The selector argument must be a Symbol. Sends the method named by the selector with the given arguments to the receiver.

If the first argument is an Array or List, this method behaves like performMsg. However, this usage is discouraged, and performMsg ought to be used instead.

.performList(selector, arglist)

The selector argument must be a Symbol. Sends the method named by the selector with the given arguments to the receiver. If the last argument is a List or an Array, then its elements are unpacked and passed as arguments.

.performMsg(msg)

The argument must be a List or Array whose first element is a Symbol representing a method selector. The remaining elements are unpacked and passed as arguments to the method named by the selector.

.performWithEnvir(selector, envir)

Arguments:

selector

A Symbol representing a method selector.

envir

The remaining arguments derived from the environment and passed as arguments to the method named by the selector.

Discussion:

.performKeyValuePairs(selector, pairs)

Arguments:

selector

A Symbol representing a method selector.

pairs

Array or List with key-value pairs.

Discussion:

.tryPerform(selector ... args)

Like 'perform', but tryPerform passes the method to the receiver only if the receiver understands the method name. If the receiver doesn't implement that method, the result is nil. Note that this does not catch errors like 'try' does (see Exception). If the receiver does have a matching method but that method throws an error, execution will halt. But, 'tryPerform' is faster than 'try'.

.superPerform(selector ... args)

Like perform, superPerform calls a method, however it calls the method on the superclass. selector: A Symbol representing a method selector. args: Method arguments.

.superPerformList(selector, arglist)

Like performList, superPerformList calls a method, however it calls the method on the superclass. selector: A Symbol representing a method selector. args: Method arguments. If the last argument is a List or an Array, then its elements are unpacked and passed as arguments.

.multiChannelPerform(selector ... args)

Perform selector with multichannel expansion. See also: Multichannel Expansion.

Arguments:

selector

A Symbol representing a method selector.

... args

Method arguments which, if they contain an array, will call the method multiple times for each sub-element.

Discussion:

Unique Methods

Method definitions not yet implemented may be added to an Object instance.

.addUniqueMethod(selector, function)

Add a unique method.

.removeUniqueMethod(selector)

Remove a unique method.

.removeUniqueMethods

Remove all unique methods of an Object.

Dependancy

.addDependant(dependant)

Add aDependant to the receiver's list of dependants.

.removeDependant(dependant)

Remove aDependant from the receiver's list of dependants.

.dependants

Returns an IdentitySet of all dependants of the receiver.

.changed(what ... moreArgs)

Notify the receiver's dependants that the receiver has changed. The object making the change should be passed as theChanger.

.update(theChanged, theChanger)

An object upon which the receiver depends has changed. theChanged is the object that changed and theChanger is the object that made the change.

.release

Remove all dependants of the receiver. Any object that has had dependants added must be released in order for it or its dependants to get garbage collected.

Error Support

Object implements a number of methods which throw instances of Error. A number of methods (e.g. doesNotUnderstand) are 'private' and do not normally need to be called directly in user code. Others, such as those documented below can be useful for purposes such as object oriented design (e.g. to define an abstract interface which will be implemented in subclasses) and deprecation of methods. The reserved keyword thisMethod can be used to refer to the enclosing method. See also Method and Function (for exception handling).

.throw

Throws the receiver as an Exception, which may or may not be caught and handled by any enclosing Function.

.subclassResponsibility(method)

Throws a SubclassResponsibilityError. Use this to indicate that this method should be defined in all subclasses of the receiver.

Discussion:

.shouldNotImplement(method)

Throws a ShouldNotImplementError. Use this to indicate that this inherited method should not be defined or used in the receiver.

.deprecated(method, alternateMethod)

Throws a DeprecatedError. Use this to indicate that the enclosing method has been replaced by a better one (possibly in another class), and that it will likely be removed in the future. Unlike other errors, DeprecatedError only halts execution if Error.debug == true. In all cases it posts a warning indicating that the method is deprecated and what is the recommended alternative.

Discussion:

Printing and Introspection

.post

Print a string representation of the receiver to the post window.

.postln

Print a string representation of the receiver followed by a newline.

.postc

Print a string representation of the receiver preceded by comments.

.postcln

Print a string representation of the receiver preceded by comments, followed by a newline.

.postcs

Print the compile string representation of the receiver, followed by a newline.

.dump

Print a detailed low level representation of the receiver to the post window.

System Information

.gcInfo

Posts garbage collector information in a table format.

Discussion:

Then for each size class: numer of black, white and free objects, total number of objects and the total set size.

You can also query the amount of free memory with Object.totalFree and dump the currently grey objects with Object.dumpGrey. More memory status methods are: largestFreeBlock, gcDumpSet, and gcSanity.

Iteration

.do(function)

Object evaluates the function with itself as an argument, returning the result. Different classes respond to this message differently.

Discussion:

.generate(function, state)

Object iterates by the message do, sent to the receiver. This method is used internally by list comprehensions.

.dup(n: 2)

Duplicates the receiver n times, returning an array of n copies. Different classes respond to this message differently. The shortcut "!" can be used in place.

Discussion:

Scheduling

.awake(beats, seconds, clock)

This method is called by a Clock on which the object was scheduled when its scheduling time is up. It calls -next, passing on the scheduling time in beats as an argument.

Arguments:

beats

The scheduling time in beats. This is equal to the current logical time (Thread: -beats).

seconds

The scheduling time in seconds. This is equal to the current logical time (Thread: -seconds).

clock

The clock on which the object was scheduled.

Stream Support

.next

Does nothing; simply returns the object itself.

.reset

Does nothing; simply returns the object itself.

Routine Support

Objects support the basic interface of Stream, just returning itself in response to the following messages: next, reset, stop, free, clear, removedFromScheduler, asStream.

.yield

Must be called from inside a Routine. Yields control to the calling thread. The receiver is the result passed to the calling thread's method. The result of yield will be the value passed to the Routine's next method the next time it is called.

.yieldAndReset(reset: true)

Must be called from inside a Routine. Yields control to the calling thread. The receiver is the result passed to the calling thread's method. The Routine is reset so that the next time it is called, it will start from the beginning. yieldAndReset never returns within the Routine.

.alwaysYield

Must be called from inside a Routine. Yields control to the calling thread. The receiver is the result passed to the calling thread's method. The Routine, when called subsequently will always yield the receiver until it is reset. alwaysYield never returns within the Routine.

.embedInStream

Yields the receiver

.idle(val)

within a routine, return values (the receiver) until this time is over. (see also Routine: play) Time is measured relative to the thread's clock.

.iter

Returns a OneShotStream with the receiver as return value.

.cyc(n: inf)

Embeds the receiver in the stream n times (default: inf), each time resetting it.

.fin(n: 1)

Calls next with the receiver n times only (default: 1), yielding the result.

.repeat(repeats: inf)

Repeatedly embeds the receiver in the stream using a Pn (may thus be used for patterns and other objects alike)

.loop

Indefinitely embeds the receiver in the stream

.nextN(n, inval)

Returns an array with the results of calling -next a given number of times

Arguments:

n

Number of message calls

inval

argument passed to the next message

.streamArg(embed: false)

Dependent on whether an object that is passed to a stream the object will behave differently: it may be embedded in the stream or used as stream directly.

This method allows to switch between the two behaviors. For efficiency, the subclasses Pattern and Stream implement this method simply as "asStream".

Arguments:

embed

If set to true, the object embeds itself into the stream (and thus return only once). If set to false, it returns itself forever. For simplicity, subclasses implement this method without this switch.

.addFunc( ... functions)

.addFuncTo(variableName ... functions)

.removeFunc(function)

.removeFuncFrom(variableName, function)

The messages Function: -addFunc Function: -addFuncTo, Function: -removeFunc, Function: -removeFuncFrom are supported by Object.

.instill(index, item, default)

.obtain(index, default)

The messages SequenceableCollection: -instill and SequenceableCollection: -obtain, are supported by Object.

Math Support

.blend(that, blendFrac: 0.5)

Lineraly interpolate between this and argument

Undocumented instance methods

!(n)

%(that)

&(that)

**(that)

+>>(that)

->(obj)

<!(that)

<<(that)

>>(that)

.archiveAsCompileString

.archiveAsObject

.argNames

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.asArchive

.asAudioRateInput

.asBinaryArchive

.asCollection

.asControlInput

.asDefName

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/asDefName.sc

.asLayoutElement

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/Base/ext-asLayoutElement.sc

.asNodeArg

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/asNodeArg.sc

.asOSCArgArray

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/extConvertToOSC.sc

.asOSCArgBundle

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/extConvertToOSC.sc

.asOSCArgEmbeddedArray(array)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/extConvertToOSC.sc

.asRef

.asSequenceableCollection

.asStream

.asString(limit: 512)

.asStringff(size: 8)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/extConvertToOSC.sc

.asSymbol

.asSynthDef

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/asDefName.sc

.asTextArchive

.asUGenInput

.atLimit

.basicHash

.beats =

.blendAt(index, method: 'clipAt')

.blendPut(index, val, method: 'wrapPut')

.bubble(depth: 0, levels: 1)

.buildForProxy(proxy, channelOffset: 0)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.canCallOS

.canFreeSynth

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Audio/canFreeSynth.sc

.checkCanArchive

.clear

.clock =

.composeEvents(event)

.containsSeqColl

.contentsCopy

.crash

.debug(caller)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Core/debug.sc

.deepCollect(depth, function, index: 0, rank: 0)

.deepDo(depth, function, index: 0, rank: 0)

.defaultArgs

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.dereference

.dereferenceOperand

.doOnCmdPeriod

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/extSystemActions.sc

.doesNotUnderstand(selector ... args)

.dumpBackTrace

.dumpDetailedBackTrace

.dumpStack

.envirCompileString

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/extStoreOn.sc

.envirKey(envir)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/extStoreOn.sc

.equals(that, properties)

.eventAt

.falseAt(key)

.finishEvent

.first(inval)

.flatSize

.free

.freeze

.functionPerformList

.gcDumpGrey

.gcDumpSet(set)

.gcSanity

.getBackTrace

.getContainedObjects(objects)

.getSlots

.gui(parent, bounds ... args)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/tools/guicrucial/gui.sc

.guiClass

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/tools/guicrucial/gui.sc

.halt

.help

.immutableError(value)

.indexedSize

.initBus

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.initFromArchive

.inspect

.inspector

.inspectorClass

.instVarAt(index)

.instVarPut(index, item)

.instVarSize

.isArray

.isCollection

.isControlUGen

.isException

.isFunction

.isInputUGen

.isNeutral

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.isOutputUGen

.isPlaying

.isRest

.isSequenceableCollection

.isString

.isUGen

.isValidUGenInput

.keyDown

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Core/ObjectPlusGUI.sc

.largestFreeBlock

.makeProxyControl(channelOffset: 0)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.matchItem(item)

.mouseDown

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Core/ObjectPlusGUI.sc

.mouseOver

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/PlusGUI/Core/ObjectPlusGUI.sc

.mustBeBoolean

.nodeMapMapsToControl

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.notYetImplemented

.numChannels

.outOfContextReturn(method, result)

.pair(that)

.pairs(that)

.performBinaryOpOnComplex(aSelector, thing, adverb)

.performBinaryOpOnSeqColl(aSelector, thing, adverb)

.performBinaryOpOnSignal(aSelector, thing, adverb)

.performBinaryOpOnSimpleNumber(aSelector, thing, adverb)

.performBinaryOpOnSomething(aSelector, thing, adverb)

.performBinaryOpOnUGen(aSelector, thing, adverb)

.poll

.postString

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/Patterns/extFunction.sc

.postff(size: 8)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/extConvertToOSC.sc

.prHalt

.prReverseLazyEquals(that)

.prepareForProxySynthDef

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.primitiveFailed

.printClassNameOn(stream)

.proxyControlClass

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.rank

.reduceFuncProxy

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/Patterns/extFunction.sc

.reference

.releaseDependants

.removedFromScheduler

.render(path, maxTime: 60, sampleRate: 44100, headerFormat: "AIFF", sampleFormat: "int16", options, inputFilePath, action)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Control/asScore/asScore.sc

.replaceFunc(find, replace)

.reportError

.setSlots(array)

.shape

.simplifyStoreArgs(args)

.slice

.slotAt(index)

.slotIndex(key)

.slotKey(index)

.slotPut(index, value)

.slotSize

.slotValuesDo(function)

.slotsDo(function)

.source

.species

.stackDepth

.stop

.storeModifiersOn(stream)

.storeParamsOn(stream)

.threadPlayer

.threadPlayer =

.totalFree

.trueAt

.unbubble

.value

.valueArray

.valueArrayEnvir

.valueEnvir

.valueFuncProxy

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/Patterns/extFunction.sc

.wakeUp

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/wrapForNodeProxy.sc

.wakeUpToBundle

From extension in /usr/local/share/SuperCollider/SCClassLibrary/JITLib/ProxySpace/NodeMap.sc

.while(body)

.writeBinaryArchive(pathname)

.writeDefFile(name, dir, overwrite: true)

.writeDefFileOld(name, dir, overwrite: true)

From extension in /usr/local/share/SuperCollider/SCClassLibrary/Common/Audio/SynthDefOld.sc

.writeTextArchive(pathname)

|(that)