Skip to content

Commit

Permalink
update to getGlobalUGenSamples()
Browse files Browse the repository at this point in the history
  • Loading branch information
gewang committed Oct 13, 2024
1 parent eeedd5a commit 7b65c0f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ ChucK VERSIONS log
"Duration since the last MidiMsg (only valid for MidiFileIn)."
- (fixed, windows) SndBuf issue when compiled with UNICODE (FYI SndBuf is still ANSI,
but this averts an error due to char width mismatch)
- (changed, developer) chuck global manager getGlobalUGenSamples() now handles multi-channel
implications for Chunity support for stereo


1.5.3.1 (October 2024)
Expand Down
35 changes: 32 additions & 3 deletions src/core/chuck_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,9 @@ Chuck_Event * * Chuck_Globals_Manager::get_ptr_to_global_event( const std::strin
// desc: get buffer samples
//-----------------------------------------------------------------------------
t_CKBOOL Chuck_Globals_Manager::getGlobalUGenSamples( const char * name,
SAMPLE * buffer, int numFrames )
SAMPLE * buffer,
int numFrames,
int numChannels )
{
// if hasn't been init, or it has been init and hasn't been constructed,
if( m_global_ugens.count( name ) == 0 ||
Expand All @@ -1350,8 +1352,35 @@ t_CKBOOL Chuck_Globals_Manager::getGlobalUGenSamples( const char * name,
return FALSE;
}

// else, fill (if the ugen isn't buffered, then it will fill with zeroes)
m_global_ugens[name]->val->get_buffer( buffer, numFrames );
// get the UGen
Chuck_UGen * ugen = m_global_ugens[name]->val;
// get number of channels
t_CKINT multichans = ugen->m_multi_chan_size;

// check that # of channels match
if( multichans != numChannels )
{
// fail without doing anything
return FALSE;
}

// if > mono
if( multichans )
{
// loop over channel
for( t_CKINT c = 0; c < multichans; c++ )
{
// copy in chunk (non-interleaved)
ugen->m_multi_chan[c]->get_buffer( buffer, numFrames );
// advance buffer pointer
buffer += numFrames;
}
}
else // mono
{
// fill (if the ugen isn't buffered, then it will fill with zeroes)
ugen->get_buffer( buffer, numFrames );
}

return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/chuck_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ struct Chuck_Globals_Manager
t_CKBOOL stopListeningForGlobalEvent( const char * name, void (*callback)(const char*) );
t_CKBOOL stopListeningForGlobalEvent( const char * name, t_CKINT callbackID, void (*callback)(t_CKINT) );

t_CKBOOL getGlobalUGenSamples( const char * name, SAMPLE* buffer, int numFrames );
t_CKBOOL getGlobalUGenSamples( const char * name, SAMPLE * buffer, int numFrames, int numChannels );

t_CKBOOL setGlobalIntArray( const char * name, t_CKINT arrayValues[], t_CKUINT numValues );
t_CKBOOL getGlobalIntArray( const char * name, void (*callback)(t_CKINT[], t_CKUINT) );
Expand Down

0 comments on commit 7b65c0f

Please sign in to comment.