Class: Node

Node(pt, name, inputs, outputs, outStyle, ctx)

The node class is used to represent the individual nodes of our graphs.

Constructor

new Node(pt, name, inputs, outputs, outStyle, ctx)

Construct a node instance.
Parameters:
Name Type Description
pt object The point containing the location of the node.
name string The name of the node.
inputs number The number of inputs to the node.
outputs string String containing csv format list of output types.
outStyle string The output style of the node (should be "FUNCTIONAL" or "MACRO").
ctx object The html canvas context the node draws itself to.
Source:

Members

fontSize

The size of the font for our rectangle.
Source:

height

The height of the rectangle representing our node.
Source:

id

A numerical identifier for the current node. Nodes are numbered by their order of creation.
Source:

inputList

The list of input rectangles for the node. These rectangles denote the inputs to the node on the main rectangle denoting the node.
Source:

inputNodes

The list of nodes connected to this one as inputs to this node.
Source:

name

The name of this node.
Source:

nodeType

The type of node this is for output purposes, can be "FUNCTIONAL" or "MACRO" for now. In functional mode code is emitted using csound opcode functional notation (without typing). In macro mode code is emitted as is but with some inputs substituted for text based macros of the form @ where n is an integer.
Source:

outTypes

The string containing the types corresponding to the types for each outputs of this node. This is a string in csv format. Each entry is the variable type prefix from csound of the corresponding output. The node outputs are specified in order in the list from left to right. See the outputColorMap variables initial values for the support output types (and their associated color coding).
Source:

outputColorMap

Mapping of output type to colors for drawing. This allows for the rectangles representing outputs on this node to be color coded based on their type.
Source:

outputList

The list of output rectangles for the node. These rectangles denote the outputs to the node on the main rectangle denoting the node.
Source:

outputNodes

The list of nodes connected to this one as outputs from this node.
Source:

printedFlag

A flag used to determine whether or not the current node has been printed by objects using this node class.
Source:

pt

The location of this node.
Source:

width

The width of the rectangle representing our node.
Source:

Methods

addInputNode(node, fromParam, toParam)

Add an node to the list of input nodes of this node. We cannot have multiple outputs connect to the same input, so return true if the adding the new node is successful and return false otherwise.
Parameters:
Name Type Description
node object The node to add to the list of input nodes.
fromParam object The index that the node outputting to this node is outputting from.
toParam object The index this node is receiving input to.
Source:
Returns:
True if adding the node succeeds else return false.

addOutputNode(node, fromParam, toParam)

Add an node to the list of output nodes of this node.
Parameters:
Name Type Description
node object The node to add to the list of output nodes.
fromParam object The index that this node is outputting from.
toParam object The index that the node receiving input from this node is receiving input to.
Source:

boundingCollision(pt)

Check if input argument pt collides with node bounding rectangle.
Parameters:
Name Type Description
pt object The point to test collision against.
Source:
Returns:
True if point lies in node bounding rectangle else false.

collision(pt)

If collision between argument pt and an input rectangle occurs return the rectangle midpoint, else return null.
Parameters:
Name Type Description
pt object The point to test collision against.
Source:
Returns:
midpoint of rectangle collision occurs with or null.

collisionInputParam(pt)

Check if input argument point collides with an input rectangle and return the index of the collision input rectangle if collision occurs else returns -1.
Parameters:
Name Type Description
pt object The point to test collision against.
Source:
Returns:
The index of the input rectangle that collision occurs with else -1.

collisionOutputParam(pt)

Check if input argument point collides with an output rectangle and return the index of the collision output rectangle if collision occurs else returns -1.
Parameters:
Name Type Description
pt object The point to test collision against.
Source:
Returns:
The index of the output rectangle that collision occurs with else -1.

collisionType(pt)

Checks input argument for collision with an input or output rectangle and returns the type of collision that occurs or null if no collision.
Parameters:
Name Type Description
pt object The point to test collision against.
Source:
Returns:
"INPUT" or "OUTPUT" if collision occurs with an input or output rectangle else null if no collision occurs.

draw(ctx)

Draw this node to the supplied canvas context.
Parameters:
Name Type Description
ctx object The canvas context to be drawn to.
Source:

drawRectangle(pt, ctx, outlineColor, fillColor)

Draw this node to the supplied canvas context.
Parameters:
Name Type Description
pt object Array of pts containing the rectangle to draw.
ctx object The canvas context to be drawn to.
outlineColor string The color to outline the rectangle with.
fillColor string The color to fill the rectangle with.
Source:

functionalSyntaxHelper()

Helper function for rendering the current node in functional mode. Functional syntax is always of the form ' = name()'. Here we build the 'name()' part.
Source:
Returns:
A string in the above mentioned format.

getId()

Get the ID of this node.
Source:
Returns:
The ID of this node.

getInputNode(n)

Get the nth input node of this node.
Parameters:
Name Type Description
n number The node to retrieve from the list of input nodes.
Source:
Returns:
The corresponding input node.

getName()

Returns the name of this node.
Source:
Returns:
The name of this node.

getOutputNode(n)

Get the nth output node of this node.
Parameters:
Name Type Description
n number The node to retrieve from the list of output nodes.
Source:
Returns:
The corresponding output node.

getOutputType(n)

Get the output type of the nth output for this node.
Parameters:
Name Type Description
n number Index of the nth output.
Source:
Returns:
The type of the nth output.

getPrintFlag()

Get the print flag of this node.
Source:
Returns:
The print flag of this node.

inputNodeCount()

Return the number of input nodes for this node.
Source:
Returns:
the number of input nodes for this node.

macroSyntaxHelper()

Helper function for rendering the current node in macro mode. Macro nodes allow us to specify parameters using notation @1,...,@n notation. This allows us to do arithmetic and specify constants in csound as well as to use the more traditional csound syntax for opcodes in place of the functional syntax. This function finds and replaces @n with its corresponding parameter using a regex.
Source:
Returns:
A string in the above mentioned format.

outputNodeCount()

Return the number of output nodes for this node.
Source:
Returns:
the number of output nodes for this node.

pointInRectangle(pt, rect)

Check if the argument pt lies in the argument rectangle.
Parameters:
Name Type Description
pt object The point to test.
rect object The rectangle to test the point with.
Source:
Returns:
True if pt lies in rect else false.

reconfigure(file)

Set up the state of the widget based on the input file.
Parameters:
Name Type Description
file object The file as an array of strings to load the node from.
Source:

renderToText()

Emit this node and all of its inputs (if they have not already been rendered) as csound code.
Source:
Returns:
A string containing csound code for this node and all of its inputs.

resetInput(n)

Reset the nth input node of this node to null.
Parameters:
Name Type Description
n number The node to reset.
Source:

resetOutput(n)

Reset the nth output node of this node to null.
Parameters:
Name Type Description
n number The node to reset.
Source:

setPrintFlag(flag)

Set the print flag of this node.
Parameters:
Name Type Description
flag boolean The value to set the flag to.
Source:

toText(nodeIndexDict)

Render the current node to JSON string. This is used for saving/loading nodes to a file. to avoid circularity we replace input nodes with their corresponding indices using the nodeIndexDict argument. These indices represent the index of the node in the output file. Later when we read this file back in these values will allow us to swap out indices for the actual node objects cleanly.
Parameters:
Name Type Description
nodeIndexDict dictionary Dictionary containing the node/index mapping mentioned above.
Source:
Returns:
A textual representation of this node.