On Thu, 18 Apr 2013, D. Michael McIntyre wrote:

> On 04/18/2013 11:41 AM, Holger Marzen wrote:
> 
> > trying to understand the data structures, failing. But I noticed an
> > excessive use of ++j in for-loops instead the C-style j++.
> 
> Probably because there are tons and tons of situations in STL and Qt 
> where standard idiom is to iterate through container classes with 
> iterators, and the standard language is
> 
>    for (some_class_iterator i = some_class.begin();
>         i < some_class.end(); ++i) { ...

Yes, that's what I think. But then we have tons of logical inaccuracies
because we don't see "i < some_class.end()" but "i != some_class.end()".
That's less safe.

> > So loops
> > don't start with a zero offset. Bug 1358 is an off-by-one bug, so I
> > tried
> >
> >    pluginLatency +=
> >      m_instrumentMixer->getPluginLatency((unsigned int) * 
> > connections.begin() - 1);
> >
> > and it looks like the bug has been gone.
> 
> Nah, trying to start iterating from before begin() can't be right, and 
> is likely to end badly.

I agree that it leaves a bad smell. But I guess the QT-style offsets
(starting by 1 because off ++i) don't apply correctly in other
structures. Maybe the code for subgroups was added by a different
programmer.

> I looked around in the code and thought about where an "off by one" 
> problem could be coming from, and I don't see it.

My big problem: I don't find the code of getPluginLatency. I only find a
declaration in sound/AudioProcess.h:

size_t getPluginLatency(unsigned int id);

In sound/AudioProcess.cpp there is

1305 size_t
1306 AudioInstrumentMixer::getPluginLatency(unsigned int id)
1307 {
1308     // Not RT safe
1309 
1310     size_t latency = 0;
1311 
1312     RunnablePluginInstance *synth = m_synths[id];
1313     if (synth)
1314         latency += m_synths[id]->getLatency();
1315 
1316     for (PluginList::iterator i = m_plugins[id].begin();
1317             i != m_plugins[id].end(); ++i) {
1318         RunnablePluginInstance *plugin = *i;
1319         if (plugin)
1320             latency += plugin->getLatency();
1321     }
1322 
1323     return latency;
1324 }

But my lack of C++-knowledge prevents me of mapping this to
sound/JackDriver.cpp:

2086         } else if (!empty) {
2087             pluginLatency +=
2088                 m_instrumentMixer->getPluginLatency((unsigned int) * 
connections.begin());
2089         }

And even then the off-by-one-problem (experimentally proven and
reproducable) could be in the mixer's data structures. My stomach tells
me that the problem is located in connections.begin and
m_instrumentMixer in line 2088.

It's not satisfacting to simply subtract 1 without understanding if it
opens the door to other collateral damages.

Maybe I'll try hightech-debugging with printf to see if there are zeroes
returned in real life.

Regards
Holger

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Rosegarden-devel mailing list
[email protected] - use the link below to unsubscribe
https://lists.sourceforge.net/lists/listinfo/rosegarden-devel

Reply via email to