<div class="gmail_quote">On Mon, Dec 19, 2011 at 5:10 PM, Iain Duncan <span dir="ltr"><<a href="mailto:iainduncanlists@gmail.com">iainduncanlists@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
Anyone have any suggestions for how to safely do the above or some better alternative?</div></blockquote><div><br>I will state my current implementation of such a feature, and let you decided if its good / bad / ugly :D<br>
<br>enum TrackState {<br>  TRACK_STATE_NORMAL,<br>  TRACK_STATE_EVENT_QUEUED,<br>  TRACK_STATE_EVENT_NOW,<br>};<br><br>process()<br>{<br>  if ( state == TRACK_STATE_EVENT_QUEUED && time == topOfTrack )<br>    processQueuedEvent();<br>
  else if ( state == TRACK_STATE_EVENT_NOW )<br>    processNowEvent();<br>   // process your MIDI output or whatever your doing.. <br>}<br><br>I'm storing all the "events" in a ringbuffer that another thread can write to, so say GUI stuff all gets updated trough "Event::setX()" style functions, and then they're read "raw" on the other side (public member variables..) its not strictly OOP, but I don't want to write the 30+ functions & structs* to pass back exactly what is expected every time :)<br>
<br>I think its a pretty OK way of going, each track will have a "TrackState" variable, and that tells you everything you need about the track. Of course if you want to have multiple things like playing - paused - relocating, as well as normal - queued - now, then you should convert them to bitfields, or separate enums to keep yourself sane... <br>
<br>I've just the one, but my "BufferAudioSource" doesn't have that many states that can be active at the same time, so I've just kept it like above. Simple :)<br>HTH, -Harry<br><br>PS: Re RT-ness, enum's are just ints, so its a RT safe & cheap. <br>
PSS: Perhaps you could elaborate on what these "Events" could be, like just a single event per track, or are we talking hundreds?<br> </div></div>