Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/core/chuck_lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ t_CKBOOL init_class_ugen( Chuck_Env * env, Chuck_Type * type )
func->doc = "return true if this UGen's output is connected to the input of rhs; if either this UGen or rhs has more than one channel, this function returns true if any connections exist between the channels; return false if there are no connections.";
if( !type_engine_import_mfun( env, func ) ) goto error;

// add connectsTo
func = make_new_mfun( "UGen[]", "goesTo", ugen_goes_to );
func->doc = "returns a list of UGens that this UGen connects to; if this UGen has more than one channel, this function returns any UGen that is connected to any channgel. Return an empty list if there are no connections.";
if( !type_engine_import_mfun( env, func ) ) goto error;

// add buffered
func = make_new_mfun( "int", "buffered", ugen_buffered );
func->add_arg( "int", "val" );
Expand Down Expand Up @@ -1780,6 +1785,28 @@ CK_DLL_CTRL( ugen_chan )
RETURN->v_object = NULL;
}

CK_DLL_CTRL( ugen_goes_to )
{
// get ugen
Chuck_UGen * ugen = (Chuck_UGen *)SELF;

Chuck_UGen ** ugen_dest_list = ugen->m_dest_list;

t_CKINT size = ugen->m_num_dest;

// allocate array object
Chuck_ArrayInt * arr_dest_list = new Chuck_ArrayInt(FALSE, size);
// initialize with trappings of Object
initialize_object(arr_dest_list, SHRED->vm_ref->env()->ckt_array, SHRED, SHRED->vm_ref);

for (t_CKINT i = 0; i < size; i++) {
arr_dest_list->set(i, (t_CKINT)ugen_dest_list[i]);
}

RETURN->v_object = arr_dest_list;
}


CK_DLL_CTRL( ugen_connected )
{
// get ugen
Expand Down
1 change: 1 addition & 0 deletions src/core/chuck_lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ CK_DLL_MFUN( ugen_numChannels );
CK_DLL_MFUN( ugen_cget_numChannels );
CK_DLL_MFUN( ugen_chan );
CK_DLL_MFUN( ugen_connected );
CK_DLL_MFUN( ugen_goes_to );
CK_DLL_MFUN( ugen_buffered );
CK_DLL_MFUN( ugen_cget_buffered );

Expand Down
89 changes: 89 additions & 0 deletions src/test/02-UGens/UGen_connection.ck
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
SinOsc s => dac;
// s => blackhole;
// s => Gain g;

s.goesTo() @=> UGen arr[];

<<< arr.size() >>>;

<<< arr[0] >>>;
<<< arr[1] >>>;
<<< arr[2] >>>;
<<< arr[3] >>>;
<<< g >>>;
<<< dac >>>;
<<< blackhole >>>;

about(Type.of(arr[0]));
about(Type.of(arr[1]));
about(Type.of(arr[2]));
about(Type.of(arr[3]));

<<< Type.of(dac).name() >>>;


// print some info about a Type
fun void about( Type t )
{
// divider
cherr <= "--------------------------------------------------" <= IO.newline();
// check
if( t == null )
{
cherr <= "null Type passed to about()!" <= IO.newline();
return;
}

//-----------------------------------------------------------------
// use .name() to get full type name e.g., 'int[][]'
//-----------------------------------------------------------------
cherr <= "type name using .name(): " <= t.name() <= IO.newline();
//-----------------------------------------------------------------
// use .baseName() to get base type name (without the array part)
//-----------------------------------------------------------------
cherr <= "type name using .baseName(): " <= t.baseName();
repeat( t.arrayDepth() ) cherr <= "[]";
cherr <= IO.newline();

//-----------------------------------------------------------------
// parents
//-----------------------------------------------------------------
cherr <= "inherits: ";
// get parent
t.parent() @=> Type @ p;
// nothing
if( p == null ) cherr <= "(nothing)" <= IO.newline();
else
{
while( p != null )
{
// name of parent
cherr <= p.name();
// get parent's parent
p.parent() @=> p;
// null?
cherr <= ((p != null) ? " -> " : IO.newline());
}
}

//-----------------------------------------------------------------
// is a kind of?
//-----------------------------------------------------------------
cherr <= "isa...Object:" <= t.isa("Object") <= " "
<= "UGen:" <= t.isa("UGen") <= " "
<= "Gain:" <= t.isa("Gain") <= " "
<= "DAC:" <= t.isa("DAC") <= " "
<= "UAna:" <= t.isa("UAna") <= IO.newline();

//-----------------------------------------------------------------
// more attributes
//-----------------------------------------------------------------
cherr <= "primitive: " <= (t.isPrimitive() ? "YES" : "NO" ) <= IO.newline();
cherr <= "array: " <= (t.isArray() ? "YES" : "NO" )
<= " depth: " <= t.arrayDepth() <= IO.newline();
}


// s.help();

<<< "success" >>>;
11 changes: 11 additions & 0 deletions src/test/02-UGens/UGen_connection2.ck
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SinOsc s => dac;

s.goesTo() @=> UGen arr[];

// This is two because dac is left and right?
<<< arr.size() >>>;

<<< arr[0] >>>;
<<< arr[1] >>>;
<<< dac.chan(0) >>>;
<<< dac.chan(1) >>>;