<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to sequence events in C&#x2F;C++]]></title><description><![CDATA[<p>I'm asking this here because what I'd like to do is something that pd does, so I suspect people here might know the answer. That is, you can have objects like delay that delay a bang or message. I'd like to, at first just for personal interest and pedagogical value, write a simple patcher-like system for managing the flow of events. I've tried to read some of the source code, but the size of it is overwhelming without some advice as to where in the source to read, and some idea of how pd is structured internally.</p>
<p>So suppose I wanted to write a pd-very-lite with no audio, just messages. The only objects would be 'bang', 'delay' and some kind of output (e.g. sending a midi CC or something). What sort of code do you have to write to get a reliable ms delay of an event?</p>
<p>More generally, again pedagogical value for now, how does one sequence midi events, or events in general, either when there is an audio thread to sync to, or without.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c</link><generator>RSS for Node</generator><lastBuildDate>Thu, 15 Oct 2026 02:14:16 GMT</lastBuildDate><atom:link href="http://forum.pdpatchrepo.info/topic/14408.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Jun 2023 17:38:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Thu, 29 Jun 2023 17:38:08 GMT]]></title><description><![CDATA[<p>I'm asking this here because what I'd like to do is something that pd does, so I suspect people here might know the answer. That is, you can have objects like delay that delay a bang or message. I'd like to, at first just for personal interest and pedagogical value, write a simple patcher-like system for managing the flow of events. I've tried to read some of the source code, but the size of it is overwhelming without some advice as to where in the source to read, and some idea of how pd is structured internally.</p>
<p>So suppose I wanted to write a pd-very-lite with no audio, just messages. The only objects would be 'bang', 'delay' and some kind of output (e.g. sending a midi CC or something). What sort of code do you have to write to get a reliable ms delay of an event?</p>
<p>More generally, again pedagogical value for now, how does one sequence midi events, or events in general, either when there is an audio thread to sync to, or without.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c</guid><dc:creator><![CDATA[Chalisque]]></dc:creator><pubDate>Thu, 29 Jun 2023 17:38:08 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Thu, 29 Jun 2023 18:22:24 GMT]]></title><description><![CDATA[<p>every object that delays contains a <code>*t_clock</code>. When you want to delay from within an object, you call <code>clock_delay</code> with that structure and the delay time. (and you can also set clock units)</p>
<p><code>clock_delay</code> will take the pointer to <code>t_clock</code> and put it on the scheduling list, which is run through every 64 samples to the next 64-sample time</p>
<p>when you create the clock, with <code>clock_new</code>, you give it a callback &quot;tick&quot; function that will be called when the scheduler reaches that point in the scheduling list.</p>
<p>here are the time-based objects: <a href="https://github.com/pure-data/pure-data/blob/master/src/x_time.c" rel="nofollow">https://github.com/pure-data/pure-data/blob/master/src/x_time.c</a></p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/2</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/2</guid><dc:creator><![CDATA[seb-harmonik.ar]]></dc:creator><pubDate>Thu, 29 Jun 2023 18:22:24 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Thu, 29 Jun 2023 18:19:37 GMT]]></title><description><![CDATA[<p>as for your second question, a more efficient way to do a scheduler is to use a heap-based priority queue. But you can also just use a regular list-based priority queue like pd does.</p>
<p>your scheduler basically has to tick every so often (and either <code>sleep</code> or spin in between), going through the scheduling queue (in pd this is <code>pd_clock_setlist</code> in <code>m_sched.c</code>) and popping off of the queue for every time value less than the next tick. In between your ticks get input from the ui and schedule things on the queue based on that.</p>
<p>I forget the details, but when audio is running the 'ticks' are based on calling the audio output api (or visa-versa?) every 64 samples.<br />
you can see pd's scheduler here: <a href="https://github.com/pure-data/pure-data/blob/master/src/m_sched.c" rel="nofollow">https://github.com/pure-data/pure-data/blob/master/src/m_sched.c</a></p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/3</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/3</guid><dc:creator><![CDATA[seb-harmonik.ar]]></dc:creator><pubDate>Thu, 29 Jun 2023 18:19:37 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Thu, 29 Jun 2023 18:16:03 GMT]]></title><description><![CDATA[<p>actually if you aren't doing audio you can get away without using ticks (just 'sleep' until the next time in the queue) but you need to check for user input as well somehow, whether through interrupts or polling a queue periodically (or both). Idk that much about that latter part.</p>
<p>getting an accurate <code>sleep</code> can also be tricky, there are some articles on it.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/4</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/4</guid><dc:creator><![CDATA[seb-harmonik.ar]]></dc:creator><pubDate>Thu, 29 Jun 2023 18:16:03 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Thu, 29 Jun 2023 20:50:01 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/chalisque">@Chalisque</a> Miller has a series of recorded lectures going through the internals of PD, fairly informative on this stuff, First couple lectures have some technical issues but they sort them out.<br />
<a href="http://msp.ucsd.edu/syllabi/206.20s/index.htm" rel="nofollow">http://msp.ucsd.edu/syllabi/206.20s/index.htm</a></p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/5</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/5</guid><dc:creator><![CDATA[oid]]></dc:creator><pubDate>Thu, 29 Jun 2023 20:50:01 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Fri, 30 Jun 2023 11:50:30 GMT]]></title><description><![CDATA[<p>If you don't care of heaviness and dependencies, you very can use QT.<br />
See <a href="https://doc.qt.io/qt-5/qtimer.html" rel="nofollow">https://doc.qt.io/qt-5/qtimer.html</a></p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/6</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/6</guid><dc:creator><![CDATA[FFW]]></dc:creator><pubDate>Fri, 30 Jun 2023 11:50:30 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Sat, 01 Jul 2023 18:53:16 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/chalisque">@Chalisque</a></p>
<p>short answer: you have to make sure that the data runs in the high priority thread.</p>
<p>pd and max have a main thread, a high priority thread (overdrive), and an audio thread (among others)</p>
<p>how to do that in C++ is surely documented in the SDK examples, but i will not be of much help here.</p>
<p>maybe compare the source code of [+ ] vs. [delay], the latter outputs to the high priority thread if one exists.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/7</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/7</guid><dc:creator><![CDATA[Obineg]]></dc:creator><pubDate>Sat, 01 Jul 2023 18:53:16 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Sun, 02 Jul 2023 01:48:09 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/obineg">@Obineg</a> all of pd vanilla runs on 1 thread (well, the 'core' non-wish process anyways)<br />
Message processing is simply interspersed w/ audio processing.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/8</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/8</guid><dc:creator><![CDATA[seb-harmonik.ar]]></dc:creator><pubDate>Sun, 02 Jul 2023 01:48:09 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Sun, 02 Jul 2023 14:59:09 GMT]]></title><description><![CDATA[<p>oh, i wasnt aware of that at all. so one could say there is basically no main thread? when the scheduler cant be turned off.:)</p>
<p>(scheduling events works fine: metro 1 -&gt; click~ at vectorsizes 32 does what it is supposed to - in max it required the hp-thread to be available or it would produce hiccup.)</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/9</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/9</guid><dc:creator><![CDATA[Obineg]]></dc:creator><pubDate>Sun, 02 Jul 2023 14:59:09 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Sun, 02 Jul 2023 15:38:26 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/obineg">@Obineg</a> Chapter 2.5 Scheduling..... <a href="http://puredata.info/docs/manuals/pd/x2.htm" rel="nofollow">http://puredata.info/docs/manuals/pd/x2.htm</a><br />
David.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/10</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/10</guid><dc:creator><![CDATA[whale-av]]></dc:creator><pubDate>Sun, 02 Jul 2023 15:38:26 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Tue, 04 Jul 2023 08:12:31 GMT]]></title><description><![CDATA[<p>wow that is closer to live than to max.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/11</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/11</guid><dc:creator><![CDATA[Obineg]]></dc:creator><pubDate>Tue, 04 Jul 2023 08:12:31 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Tue, 04 Jul 2023 09:46:44 GMT]]></title><description><![CDATA[<p>There is a command line to launch pure-data without the audio engine.</p>
<p>flag -noaudio</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/12</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/12</guid><dc:creator><![CDATA[Il pleut]]></dc:creator><pubDate>Tue, 04 Jul 2023 09:46:44 GMT</pubDate></item><item><title><![CDATA[Reply to How to sequence events in C&#x2F;C++ on Mon, 24 Jul 2023 21:59:43 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/seb-harmonik-ar">@seb-harmonik.ar</a> said:</p>
<blockquote>
<p><a class="plugin-mentions-a" href="http://forum.pdpatchrepo.info/user/obineg">@Obineg</a> all of pd vanilla runs on 1 thread (well, the 'core' non-wish process anyways)<br />
Message processing is simply interspersed w/ audio processing.</p>
</blockquote>
<p>Almost. Pd does use a single thread for DSP and message processing, but this is not the same as the audio callback (unless &quot;use callbacks&quot; is enabled), so you have (at least) two threads.</p>
<p>Side note: In Pd, the audio callback does almost no work; it just reads/writes samples from/to a ringbuffer and returns. Pd's main thread waits on the ringbuffer (see <code>sys_send_dacs</code>), so it is indirectly (asynchronously) driven by the audio callback.</p>
]]></description><link>http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/13</link><guid isPermaLink="true">http://forum.pdpatchrepo.info/topic/14408/how-to-sequence-events-in-c-c/13</guid><dc:creator><![CDATA[Spacechild1]]></dc:creator><pubDate>Mon, 24 Jul 2023 21:59:43 GMT</pubDate></item></channel></rss>