First time here? Check out the FAQ!
x

What is a simple way to display a wavetable in a Tool?

0 votes
171 views

Hi there,

I'm reading a wavetable in a Tool using the message: 

aCollection := aSamplesFile getSamplesFromMonoWavetableFileStartingAt: 0 length: 4096.

Once I collected the samples this way I want to display them on aView. Do I need to use lines? I tried to mod the logisticMap tool but it seems very complicated for this simple thing. 

Basically I want to get a view that looks similar to the window I get when I use: 

XYGraphView openOnValues: aCollection.

Any ideas?

Thanks!

asked Jun 8, 2016 in Capytalk & Smalltalk by kymaguy (Virtuoso) (10,580 points)
also somehow related: When the wavetable that I want to read is stereo, how can I read only the left channel?
XYGraphView openOnValues: aCollection --- neat!
Unfortunately, there is not yet a simple way to display the XYGraph in an arbitrary view.
ok, I see.. I'll try to use lines then

1 Answer

+2 votes
 
Best answer

Not the simple way but this method lets you display a 4096 samp wavetable in a view:

DrawA := [ :samples |
    | gc bnds x y x2 y2 |
    gc := ViewA graphicsContext.
    bnds := ViewA bounds.
    gc clearWith: ColorValue white.
    gc lineWidth: 1.
    gc displayLineFrom: (0 @ ((bnds height / 2) rounded)) to: ((bnds width) @ ((bnds height / 2) rounded)).

    x := 0.
    y := ((bnds height / 2) + (((bnds height / 2) - 4) * ((samples at: 1) * -1))) rounded.

    1 to: 4095 do: [ :i |

        x2 := (bnds width * i / 4095) rounded.
        y2 := ((bnds height / 2) + (((bnds height / 2) - 4) * ((samples at: (i+1)) * -1))) rounded.

        gc lineWidth: 2.
        gc displayLineFrom: (x @ y) to: (x2 @ y2).

        x := x2.
        y := y2.
    ].
].

To use the method you need to send it a collection with 4096 elements:

DrawA value: aCollection

 

Solved :)

answered Jun 16, 2016 by kymaguy (Virtuoso) (10,580 points)
this is very cool!
...