SynthMaker

Synchronized elements vs. O-O programming (interfaces)

Archive · 2005 16 old posts

From the original SynthMaker forum (2004–2014), with its members’ names and dates.

Kitchen Sink ·

I wrote about this in the Examples forum, but I think it needs a thread of its own, so I'm copying it here:

Isn't the "synchronized" concept a bit bad programming? I mean, if synchronized elements are used as a kind of work-around to have the same object instance visible in several places. Are they the same instance, or are they really synchronized copies? Of course, synchronization can have its uses, but this font/label thing smells like a kludge that will later on collapse in a big unmaintainable mess.

I'd like to thing of all components as objects, as in object oriented programming. One should be able to plug in an entire component as such, without needing to connect all (maybe dozens of) individual wires. Or what do you think? Currently there's no such thing as "interfaces" (think Java, Delphi's Object Pascal, COM, C++ pure virtual abstract base class, etc.).

In Synthmaker, an interface could be a collection of input/output "jacks", bound together as something you can plug with one wire. Then of course you could split the interface apart, if you wanted to patch only some parts of it, with component "signals" coming from various places. IMO, interfaces would be a huge step for making Synthmaker quicker and easier to use. Real polymorphism and object reuse. 🙂

Currently, there are different types of plugs: integer, float, string, area, colour, font, ... But where does it end? IMO, things like area and font should definitely be compound interfaces. Like, if you have an interface called "Parametric EQ input" and many different types of modules that conform to that, it is very easy to let the user switch between different eq modules. But if there's a separate wire for each of the settings (type, frequency, gain, Q, signal in), it will be a lot messier.

This would introduce a new "meta level" of things, to manage interfaces. If I make a new interface type, there should be a corresponding compound data type, too. And module input/output connectors should show their interface types.

Please comment on these thoughts.

stefan ·

They are several instances, just using the same "class".

What would an interface be like in SM?

Why not use buses for binding connections together?

Tom7777 ·

The more modules used usually the more complex things can get and i guess it really depends on how complex one wants things to get. I think that better results are usually best with more wires and modules ect on a synth anyway. But programs like SM allows you more depth within things so a user can make custom edits to single units and use buses ect then group to modules to simplify things. Modular synthesis is not really a simple thing anyway i think and the more complex the more variations and orginal ideas can be created and usually better results 🙂

malc ·

Kitchen Sink wrote: Isn't the "synchronized" concept a bit bad programming? I mean, if synchronized elements are used as a kind of work-around to have the same object instance visible in several places. Are they the same instance, or are they really synchronized copies?

I see your point. You're saying that copying modules is the SM equivalent to copying and pasting code in C++ say - something that is generally regarded to be bad practice.

It's a fair comment, although one of the reasons why it's considered bad practice when programming is because changes need to be made in more than one place and more often than not something gets forgotton. This isn't the case with our syncing modules.

Kitchen Sink wrote: this font/label thing smells like a kludge that will later on collapse in a big unmaintainable mess.

I don't think it's a kludge. It's fairly straightforward really. The whole point of sync modules is to make things easier to maintain not harder.

That all said I can understand where you are coming from. At the moment SM has no concept of a class as such. Modules are more like functions than classes. So in fact SM is more comparable with standard procedural programming than object oriented programming.

Maybe we can look at introducing some object oriented concepts into the software. It'll need some thinking about though.

Kitchen Sink wrote: Currently, there are different types of plugs: integer, float, string, area, colour, font, ... But where does it end? IMO, things like area and font should definitely be compound interfaces. Like, if you have an interface called "Parametric EQ input" and many different types of modules that conform to that, it is very easy to let the user switch between different eq modules. But if there's a separate wire for each of the settings (type, frequency, gain, Q, signal in), it will be a lot messier.

As Stefan said, you can already do something like this using the Bus components. I'm sure this concept has room for further development.

Thanks very much for your comments.

Kitchen Sink ·

stefancrs wrote: They are several instances, just using the same "class".

OK.

What would an interface be like in SM?

Like a bus connection, i.e. a collection of connections, but without having to use explicit bus create and bus extract components, and manually typed list strings. Just like you can now select a bunch of components and make a module out of them, it should be possible to select a bunch of connectors and bind them into an interface. With some kind of show/hide buttons, it would be possible to show the individual connectors of an interface, without popping up yet another dozen component boxes and a web of connections, at the same time losing view of what I was doing.

Why not use buses for binding connections together?

*cough* hadn't tried them before *cough*

To try my EQ interface example with buses, I created two modules: "Parametric EQ Interface Create" and "Parametric EQ Interface Extract", which kind of work as interfaces. If I now add these to the toolbox, it's quite good already. 🙂 Now if only there was integrated support for making these automatically for any set of connectors in a module...

It's also a bit of a problem that module inputs and outputs are untyped. So my interface create/extract modules' inputs and outputs are untyped, too. Of course the recommended types can be written in the connector labels as text.

Maybe I'm only looking for some "in-place" editing here. It seems that most things are possible to do already with Synthmaker's components and connections (because they're so generic), but usually I have to open another view, another "window" (although it isn't a real Windows window), and lose what I had in view. The same problem has been with Cubase: you can't edit almost anything without opening yet another pop-up editor window or dialog. This makes working with it quite distracting.

stefan ·

Imo, it would be cool if you could select any number of connectors and choose "convert to bus", where it would also take the names of the connectors and use these names in the bus string input, automatically. Something for malc and jorge to do I guess, because this is how you usually end up doing it, but manually. Also to be able to make a selection and _add those connectors_ to an existing bus connector would be good.

Kitchen Sink ·

malc wrote: It's a fair comment, although one of the reasons why it's considered bad practice when programming is because changes need to be made in more than one place and more often than not something gets forgotton. This isn't the case with our syncing modules.

So synchronized modules have the same code and the same data, so... why have separate copies at all? I understand the situation, if there are no classes inside Synthmaker.

Btw, if each synced module has its own code, doesn't it make the CPU's code cache very inefficient? I used to do "sprites" with self-building code with my 286 (over a decade ago), and it was very fast, because the sprites' data could be put inside instructions as immediate operands, but with newer machines, that kind of "optimization" was very stupid because the CPU had a 0% cache hit ratio. 😉

At the moment SM has no concept of a class as such. Modules are more like functions than classes. So in fact SM is more comparable with standard procedural programming than object oriented programming.

Doing O-O in SM isn't that far, really. 🙂 By using bus connections as "object interfaces", it's possible to do a bit of polymorphism. It could even be possible to simulate base classes like this, by exporting triggers and everything from a "base class" module. (why would somebody want to do that, is another question)

Kitchen Sink ·

stefancrs wrote: Imo, it would be cool if you could select any number of connectors and choose "convert to bus", where it would also take the names of the connectors and use these names in the bus string input, automatically.

Yeah, but why is there a need for such a name list string in the first place... why couldn't the names be written where they appear. 🙂

It's great we can discuss these things when Synthmaker isn't in version 1.0 yet.

stefan ·

Because you can have connections within the bus that aren't connected at the bus create and/or bus extract. You don't need to feed all connections into a bus create, and you don't have to extract all connections from a bus extract.

This way, you can split the bus up both into two different extracts or into two different creates (going to just one extract) and so forth.

Kitchen Sink ·

With "Add connector" and "Remove connector" functions/buttons, perhaps? To the added connector's label you would type the name of the connection you want to create or extract. I don't see a problem here. The list string input is an odd way to specify connectors and their names, but at the same time the string input itself is pretty useless, don't you think?

This is what I meant with my "properties" suggestion, too. To have in-place editing of stuff. To be able to set some data values inside a module without opening the module.

stefan ·

The string input is, imo, a very convinient way to copy bus connections between different bus creators/extractors.

Kitchen Sink ·

It is a way to do that. At least it must have been very easy to add to the existing code. 🙂

But I began to think about the code cache issue. If Synthmaker doesn't have classes and objects, then basically there is not a single byte of code shared between any two parts of even a very large synth, right? This doesn't seem too good for cache performance.

stefan ·

Basicly any schematic is compiled into one whole function. No calls, everything is inlined. This ought to be cache heaven, since the coming instructions always are right after (in memory) the program counter.

Kitchen Sink ·

So do you mean that as long as the instructions are sequential, they are pre-fetched with zero performance hit, even if there's a megabyte of code?

I thought it could be better if each similar chunk of code had to be loaded into the CPU only once, because all of the code is executed many times in a row to fill the ASIO buffer.

Btw, how large amounts of memory are we talking about? How large is a big synth's code?

stefan ·

I've looked at the generated code for my synth, and I'd roughly estimate it's size to maybe 50-70kbyte. And yes, as long as you don't make any function calls / jumps, the cpu can prefetch code in the most efficient manner. But on most cpu's, the entire code should fit in the cache anyway.

Kitchen Sink ·

Actually I meant, how fast can prefetching be compared to 100% code cache hits? Can it be equally fast?

Anyway, if the "no calls, no branching" principle is carved into stone design-wise (?), then there's nothing to be done for it.

Wrote something here? To have a post removed or your name hidden, write to [email protected].

Before your first post

A few rules keep this a friendly place. You agree to them once.

Shown next to what you post, here and in the app. It doesn’t have to be your real name: 3–24 lower-case letters, digits or _ (capitals become lower case, spaces become _).

    Then your post goes up straight away.

    Delete this reply?

    Open it in SynthMaker?

    It goes on the track you’re editing there, in place of that track’s sound, and into My sounds. Your other tracks stay as they are.

    Want to keep that track’s sound? Start a new song in SynthMaker first (Song › New song), then open this.

    Report this reply?

    Only the developer reads reports. The person isn’t told who reported them.

    What’s wrong with it?

    Block this person?

    You won’t see their posts and replies here any more. They aren’t told, and you can unblock them at any time.

    People you’ve blocked

    Their posts and replies are hidden from you. Unblock someone to see them again.

    The community rules

    A few rules keep this a friendly place. Everyone agrees to them once, before their first post.