本文整理汇总了C++中EventBase::size方法的典型用法代码示例。如果您正苦于以下问题:C++ EventBase::size方法的具体用法?C++ EventBase::size怎么用?C++ EventBase::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventBase
的用法示例。
在下文中一共展示了EventBase::size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processDsp
void Top::processDsp()
{
// check if there's anything to read
int availableRead = jack_ringbuffer_read_space( guiToDsp );
while ( availableRead >= sizeof(EventBase) )
{
jack_ringbuffer_peek( guiToDsp, (char*)guiToDspMem, sizeof(EventBase) );
EventBase* e = static_cast<EventBase*>( guiToDspMem );
// have to check the size against the event size (as opposed to the EventBase
// size check earlier. Just because the write thread has written the EventBase
// doesn't mean the whole event is written (2 memcpy writes when buffer wraps).
// this check gaurantees that the whole event is available, and can be run
if ( availableRead >= e->size() )
{
switch ( e->type() )
{
case EventBase::EVENT_BUFFER_TRANSFER:
{
if ( availableRead >= sizeof(EventBufferTransfer) )
{
EventBufferTransfer ev( (AudioBuffer*)0);
jack_ringbuffer_read( guiToDsp, (char*)&ev, sizeof(EventBufferTransfer) );
// pass the pointer to DSP
dsp->setBuffer( ev.audioBufferPtr );
}
break;
}
}
}
// update available read, and loop over events
availableRead = jack_ringbuffer_read_space(guiToDsp);
}
}
示例2: processGui
// GUI thread calls this function periodically to update itself
void Top::processGui()
{
// check if there's anything to read
int availableRead = jack_ringbuffer_read_space(dspToGui);
while ( availableRead >= sizeof(EventBase) )
{
jack_ringbuffer_peek( dspToGui, (char*)dspToGuiMem, sizeof(EventBase) );
EventBase* e = static_cast<EventBase*>( dspToGuiMem );
// again, have to check in case buffer is wrapping, and thread gets paused
// inbetween the two memcpy calls, leaving a possible non-full event
if ( availableRead >= e->size() )
{
switch ( e->type() )
{
case EventBase::EVENT_BUFFER_TRANSFER:
{
// create an empty of this event type
EventBufferTransfer ev( (AudioBuffer*)0 );
// read the event from the buffer
jack_ringbuffer_read( dspToGui, (char*)&ev, sizeof(ev) );
stringstream s;
s << "GUI: Deleting AudioBuffer instance " << ev.audioBufferPtr->getID() << " Addr: "
<< ev.audioBufferPtr;
gui->printTextView( true, s.str() );
AudioBuffer* tmp = ev.audioBufferPtr;
cout << "Top deleting DSP audioBuffer Addr: " << tmp << endl;
// do the action: de-allocate buffer
delete tmp;
break;
}
case EventBase::EVENT_GUI_PRINT:
{
// create an empty of this event type
EventGuiPrint ev;
// read the event from the buffer
jack_ringbuffer_read( dspToGui, (char*)&ev, ev.size() );
// do the action: print it
gui->printTextView( false, ev.getMessage() );
break;
}
case EventBase::EVENT_PLAYBACK_POSITION:
{
// create an empty of this event type
EventPlaybackPosition ev;
// read the event from the buffer
jack_ringbuffer_read( dspToGui, (char*)&ev, sizeof(ev) );
// do the action: set the playback position
gui->getWaveview()->setPlaybackPosition( ev.position );
break;
}
default:
{
cout << "Top::processGUI() Recieved unknown event type " << e->type() << endl;
}
} // switch
} // if ( available >= e->size() )
else
{
// return if the EventBase was written but the whole event was not. This
// breaks out of the while loop, and the EventBase which is still in the
// ringbuffer will be read on the next call of this function
return;
}
// update available read, and see if there's more events
availableRead = jack_ringbuffer_read_space( dspToGui );
}
}