# # AudioView.py # SoundFarmer # # Created by Donovan Preston on 8/26/04. # Copyright (c) 2004 Ulaluma. All rights reserved. # from PyObjCTools import NibClassBuilder import AppKit from OpenGL import GL as G class NotAudioView(NibClassBuilder.AutoBaseClass): playing = False def acceptsFirstResponder(self): return True def initWithFrame_(self, frame): return super(AudioView, self).initWithFrame_pixelFormat_( frame, AppKit.NSOpenGLPixelFormat.alloc().initWithAttributes_( [ AppKit.NSOpenGLPFANoRecovery, AppKit.NSOpenGLPFAWindow, AppKit.NSOpenGLPFAAccelerated, AppKit.NSOpenGLPFADoubleBuffer, AppKit.NSOpenGLPFAColorSize, 24, AppKit.NSOpenGLPFAAlphaSize, 8, AppKit.NSOpenGLPFADepthSize, 24, AppKit.NSOpenGLPFAStencilSize, 8, AppKit.NSOpenGLPFAAccumSize, 0 ])) def drawRect_(self, updateRect): ## Right now I'm not using the update rect. Use it. # channels = self.document.channels # if not channels: return channels = 2 visible = self.visibleRect() # width = int(visible[1][0]) width = 2048 height = int(visible[1][1]) start = int(visible[0][0]) G.glViewport(0, 0, width, height) G.glClear( G.GL_COLOR_BUFFER_BIT| G.GL_DEPTH_BUFFER_BIT| G.GL_STENCIL_BUFFER_BIT) G.glLoadIdentity() G.glOrtho(0, width, 0, channels*2, 1, -1) for chan in range(channels): ## Draw a dividing line between channels; ## don't draw it before the first channel. if chan: G.glBegin(G.GL_LINES) G.glVertex2f (0, chan*2) G.glVertex2f (width, chan*2) G.glEnd() ## Draw the waveform for this channel. G.glBegin(G.GL_LINE_STRIP) samples = self.document.samplesForChannel_start_stop_( chan, start, width+start) for x, y in enumerate(samples): G.glVertex2f (x, y+chan*2+1) G.glEnd() self.openGLContext().flushBuffer() def awakeFromNib(self): import ToolbarHelper, os self._toolbarHelper = ToolbarHelper.ToolbarHelper.alloc( ).initWithToolbarDescriptionFile_toolbarIdentifier_window_target_( 'toolbar.csv', "SoundFarmer Toolbar", self.window(), self) self.window().setDelegate_(self) # frame = self.frame() # self.setFrame_((frame[0], (self.document.frames, frame[1][1]))) def toggle_(self, sender): self.drawer.toggle_(sender) def play_(self, sender): AppKit.NSApplication.sharedApplication().delegate().play_(sender) sender.setLabel_('Stop') sender.setAction_('stop:') sender.setImage_(AppKit.NSImage.imageNamed_('Stop')) self.playing = True def stop_(self, sender): AppKit.NSApplication.sharedApplication().delegate().stop_(sender) sender.setLabel_('Play') sender.setAction_('play:') sender.setImage_(AppKit.NSImage.imageNamed_('Play')) self.playing = False def windowWillClose_(self, notification): if self.playing: self.stop_(self)