Just wanted everyone to know that I’m still interested in seeing a solution. Thanks![/quote]
There are probably many approaches to take to do this, but here’s a fairly straightforward approach. its by no means perfect but should get you up and running fairly quickly. (also, this is all from memory so please forgive any mistakes!)
The Juce Demo might a good place to start to get a window displaying - but you can strip out almost everything - you just need a window with a single content component filling it.
Once you have this, the first thing you’ll need is a class to represent a “signal”. Call it SignalBase or something. You’re likely to derive classes from this later.
This will describe the signal but not be reponsible for drawing it. Its generally considered good practice for your interface classes to be separate from your data model.
One of the main things you’ll want to do with a signal will be to get its output value at a given time.
So give your class a member funtion: virtual double GetOutputValue(double time ) . Time can be in any units you want, milliseconds, microseconds, seconds?
You can worry about the implementation of this function later, for now you can make it return 0.0, or a random number or anything you want. Any classes that you derive from this can implement GetOutputValue() differently. For example, a derived class SignalClock would clearly switch from 0->1->0 periodically.
So the next thing we want to do is display this Signal data somehow.
One way would be to create a new class derived form Component. Call it SignalViewComponent (or anything that makes sense to you). You’ll need a way of associating your Signal data with this class, so add a function called SetDataSource( Signal *p_signal ). this function could store the pointer to the Signal object internally within SignalViewComponent, perhaps in a variable called PSignalData;
Now, the main point of SignalViewComponent is to draw the signal waveform, so you’ll need to override its paint() method. This should call PSignalData->GetOutputValue(t) for each pixel (left to right) where ‘t’ is the time that each pixel represents (you could have each pixel be a millisecond - so pixel 5 corresponds to millisecond 5 - to start with, but more than likely you’ll eventually want to change this to take into account zooming/scrolling.)
The Y coordinate of the pixel will be the value you get back from PSignalData->GetOutputValue(t), scaled up (or down) enough so that you can see it (you’ll probably want to scale it so the range of the signal fits into the height of your component - which you can get by calling getHeight() ). For now, just draw a single point at this x,y cordinate (the x cordinate is t) - this will leave “holes” if the output value changes by more than one pixel for each increment of x, but we can improve this later.
So to test if these things work, create a SignalViewComponent component and add it to your main window component (use addAndMakeVisible() ). You’ll have to call setBounds so it’s the size and position you want. Its probably worth creating an array of these as you’ll eventually want several. Then create a new Signal object for each component - store these in a seprate array. (this isn’t necessarily the ideal way to structure your program - the signal data objects probably shouldn’t be “owned” by the window(!) - but it will do for now, you can reorganize it later). Then for each component/Signal pair, call SetDataSource(signal) to associate your data object with its view component.
So this should give you a way of displaying multiple signals… to get them to display something sensible you’ll need to implement GetOutputValue() correctly, and you’ll need to do further work to sum/combine them (Note this logic will take place on the Signal objects and doesn’t concern the SignalViewComponents )
The interface is also likely going to be much more complex than just adding SignalViewComponents to the main window component, but this can be improved once you have the basics working.
Anyway, this is long and rambling - i hope some of it helps (or at least makes sense!)