Skip to content

Instantly share code, notes, and snippets.

@henry0312
Last active August 29, 2015 14:02
Show Gist options
  • Save henry0312/c36f70f2d8bcddb8546a to your computer and use it in GitHub Desktop.
Save henry0312/c36f70f2d8bcddb8546a to your computer and use it in GitHub Desktop.
TracMix written in Swift
import Cocoa
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet var window: NSWindow
var track: Track!
@IBOutlet var textField : NSTextField
@IBOutlet var slider : NSSlider
@IBAction func mute(sender : AnyObject) {
//NSLog("received a mute: message")
track.volume = 0.0
updateUserInterface()
}
@IBAction func takeFloatValueForVolumeFrom(sender : AnyObject) {
/*
var senderName: String
if sender is NSTextField {
senderName = "textField"
} else {
senderName = "slider"
}
NSLog("%@ sent takeFloatValueForVolumeFrom: with value %1.2f", senderName, sender.floatValue)
*/
let newValue = sender.doubleValue
track.volume = newValue
updateUserInterface()
}
func updateUserInterface() {
let volume = track.volume
self.textField.doubleValue = volume
self.slider.doubleValue = volume
}
func applicationDidFinishLaunching(aNotification: NSNotification?) {
// Insert code here to initialize your application
track = Track()
updateUserInterface()
}
func applicationWillTerminate(aNotification: NSNotification?) {
// Insert code here to tear down your application
}
}
import Cocoa
class Track: NSObject {
var volume: Double
init() {
volume = 0.0
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment