I need to draw a waveform in an NSView. (I have all the samples in an array). The drawing must be efficient and really fast without clipping, flickering, etc, it must be smooth. The waveform will be “moving” according to the song position and some changes to the samples (DSP processing) will be shown as visual representation onto NSView in realtime.
I’m familiar drawing lines, arcs, etc onto canvas objects and I have developed apps doing such things but not on Mac OS X …
I want to ask if anyone can guide me where to start drawing! Core Animation, OpenGL, simple override drawing methods, ??, etc. Which would be the best practice – API to use?
I would keep it simple and create an
NSViewsubclass with anaudioDataproperty that uses Cocoa drawing. You could call[view setAudioData:waveArray]which would in turn call[self setNeedsDisplay:YES].In your
drawRect:method you could then iterate through the samples and useNSRectFill()accordingly. Heresample‘svalueis between 0 and 1.This code isn’t exact, and you should be sure to make it more efficent by only drawing samples inside
dirtyRect.