5

I've started drawing plugs in Java, like connectors using bezier curves, but just the visual stuff.

example

Then I begin wondering about making some kind of modular thing, with inputs and outputs. However, I'm very confused on decisions about how to implement it. Let's say for example, a modular synthesizer, or Pure Data / MaxMSP concepts, in which you have modules, and any module has attributes, inputs and outputs.

I wonder if you know what keywords should I use to search something to read about. I need some basic examples or abstract ideas concerning this kind of interface. Is there any some design pattern that fits this idea?

Byte Commander
  • 6,506
  • 6
  • 44
  • 71
whitenoisedb
  • 403
  • 1
  • 5
  • 16
  • Well the "modules" is not good definition for what you need. Usually that mean a part of bigger system which you can add or remove - like module for sending emails in your cms or something like that. About design patterns - the most of them are not here to actually solve problem, but to make it easier to use/change/move etc., and if it is good or not to use them, it differs based on what you exactly need. You can try to create a "beta" version of your app, the classes and intefaces Java have enough variability and funcionality itself... – libik Mar 25 '15 at 16:56
  • Ok, maybe I don't need any pattern. I thought I would need an Observer round there. I should start with something like [this](http://i.imgur.com/Hw66MLc.jpg), where [O] is an OutNode, [I] is an InNode, and the cables between those Connection objects. Something very simple. I'm not sure how to start. – whitenoisedb Mar 26 '15 at 04:19
  • I would start with simple interface with methods "input, output, process", than you can create classes which implements it. In your main class you should create some type of engine, which will input, output and process all the instances. – libik Mar 26 '15 at 08:03
  • In the order they were created? considering I'm using ArrayLists to store each Connection – whitenoisedb Mar 26 '15 at 15:29
  • I dont know how exactly your system should work, but yes, in general, storing all items in one list, which type is their ancestor or implementing interface, is good approach - you access all items equally, no matter what they actual type is - it is good for adding new classes, behaviour etc. – libik Mar 26 '15 at 22:21

1 Answers1

-1

Since you're asking for a keyword real-time design patterns, overly OOP is often a performance bottleneck to real-time applications, since all the objects (and I guess polymorphism to some extent) add overhead.

Why real-time application? The graph you provided looks very sophisticated, You process the incoming data multiple times in parallel, split it up, merge it and so on.

Every node in the graph adds different effects and makes different computations, where some computations may take longer than others - this leads to the conclusion, that in order to have uniform data (sound), you have to keep the data in sync. This is no trivial task.


I guess some other keywords would be: sound processing, filter. Or you could ask companies that work in that area for literature.


Leaving the time sensitivity aside, I constructed a little OOP example, maybe an approach like that is sufficient for less complex scenarios

public class ConnectionCable implements Runnable, Closeable {
    private final InputLine in;
    private final OutputLine out;

    public ConnectionCable(InputLine in, OutputLine out) {
        this.in = in;
        this.out = out;
        // cable connects open lines and closes them upon connection
        if (in.isOpen() && out.isOpen()) {
            in.close();
            out.close();
        }
    }

    @Override
    public void run() {
        byte[] data = new byte[1024];
        // cable connects output line to input line
        while (out.read(data) > 0)
            in.write(data);
    }

    @Override
    public void close() throws IOException {
        in.open();
        out.open();
    }
}

interface Line {
    void open();
    void close();
    boolean isOpen();
    boolean isClosed();
}

interface InputLine extends Line {
    int write(byte[] data);
}

interface OutputLine extends Line {
    int read(byte[] data);
}
mike
  • 4,929
  • 4
  • 40
  • 80
  • Who said anything about real-time? Nothing to do with it. – user207421 Apr 03 '15 at 23:51
  • I did, and I stated my reasons in the second and third paragraph. – mike Apr 03 '15 at 23:52
  • And how exactly do your reasons relate to the question? – user207421 Apr 03 '15 at 23:58
  • From my understanding the image illustrates the configuration via view, and OP now wants to design the according model. If you incorporate the comments, and OPs answers to them, one can assume that he wants to design some kind of synthesizer. But I have to admit the question per se is not very clear, at least it was to me. – mike Apr 04 '15 at 00:04
  • He is drawing plugs. He isn't producing sound. There is no discernable real-time aspect to this question. – user207421 Apr 04 '15 at 00:07
  • So you're saying it's not about the model - whatever that may be related to - it's about the view/ view model? – mike Apr 04 '15 at 00:12