Environment: Siren
Instances of the subclasses of MusicMagnitude are used to represent scalar magnitudes in musical objects. The class MusicMagnitude is a place for the music magnitudes to share their state and basic accessing behavior.
MusicMagnitudes generally implement precise mixed-mode arithmetic and comparison methods using a per-species generality table and auto-coercion within a species.
The "type abstraction" classes (Duration, Pitch, Amplitude, etc.) represent "what"; they are never instantiated; their class creation methods answer instances of their species, but they manage coercion within the classes of their species. The "representational abstraction" classes (NominalMagnitude, OrdinalMagnitude, NumericalMagnitude, RatioMagnitude, etc.) represent "how"; they share value model semantics and coercion techniques. Note that the concrete implementation classes therefore answer their species by property model rather than by implementation subclass (i.e., HertzPitch species --> Pitch rather than NumericalMagnitude).
MusicMagnitudes can have dependents (observers), and send themselves the changed: message when their values are changed.
There are many examples in the implementation classes and the Siren outline.
Instance variables:
accessing
value
value
Answer the instance variable 'value'.
value: theValue
Accept the argument, 'theValue', as the new instance variable 'value'
and signal any dependents.
printing
Print the receiver on the argument as a MM declaration.
printOn: aStream parens: useParens
Print the receiver on the argument as a MM declaration.
printString
Answer a String whose characters are a description of the receiver.
printStringParens: bool
Answer a String whose characters are a description of the receiver.
printValue
storeOn: aStream
Store the receiver on the argument as a MM declaration.
units
Answer the units string of the receiver.
private
Answer MusicMagnitude.
converting
If I am involved in arithmetic with a number, convert me to a number.
coerceTo: type
Coerce the receiver to the given class and answer a new object.
ddMsgName
Answer the selector to be used in coercing double-dispatching messages.
msec
Answer a MSecondDuration.
usec
Answer a MSecondDuration.
testing
Answer whether the receiver has an immediate representation.
isMusicMagnitude
Answer true for the receiver and all subsclasses.
arithmetic
Answer the product of the receiver and the argument
+ aValue
Answer the sum of the receiver and the argument, doing generality-based
class coercion within a species using auto-generated coercion messages.
- aValue
Answer the difference of the receiver and the argument
/ aValue
Answer the quotient of the receiver and the argument
comparing
Answer whether the receiver is less than the argument
= aValue
Answer whether the receiver and the argument are equal.
hash
Answer a SmallInteger unique to the receiver.
MetaClass: MusicMagnitude class
instance creation
Answer and instance with the argument as its value.
class constants
Answer the default color to display instances with (hack for making pretty graphs).
propertyName
Answer the receiver class's default property name.
relativeMember
Answer the receiver class's species member used as a relative magnitude.