SwiftとCocoa

clockBargraph2

全てをSwiftで書こうとしているところです。

//  MyView.swift

import Cocoa

class MyView: NSView {
    
    override func drawRect(dirtyRect: NSRect) {
        super.drawRect(dirtyRect)
        
        NSColor.brownColor().set()
        NSRectFill(self.bounds)
        
        let font = NSFont.boldSystemFontOfSize(70)
        let textFontAttributes = [
            NSFontAttributeName: font,
            NSForegroundColorAttributeName: NSColor.whiteColor()
        ]
        
        let now = NSDate()
        let df = NSDateFormatter()
        df.dateFormat = "HH:mm:ss"
        var s = df.stringFromDate(now)
        s.drawInRect(self.bounds, withAttributes: textFontAttributes)
        
        let hhmmss: [String] = ["hh", "mm", "ss"]
        
        for (var j: Int = 0; j<3; j++) {
            
            df.dateFormat = hhmmss[j]
            s = df.stringFromDate(now)
            switch j {
            case 0: NSColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0).set()
            case 1: NSColor(red: 0.0, green: 1.0, blue: 0.0, alpha: 1.0).set()
            case 2: NSColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 1.0).set()
            default: break
            }
            for (var i: Int = 0; i<Int(s); i++) {
                let x = CGFloat(  20 + 10*i )
                let y = CGFloat( 150 + i%10 - j*50)
                let rect = NSMakeRect(x, y, 7, 40)
                NSRectFill(rect)
            }
            
        }
    }
}
//  AppDelegate.swift

import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate {

    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var myCustomView: NSView!

    func applicationDidFinishLaunching(aNotification: NSNotification) {
        // Insert code here to initialize your application
        
        self.window.delegate = self
        NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: "update", userInfo: nil, repeats: true)
    }

    func applicationWillTerminate(aNotification: NSNotification) {
        // Insert code here to tear down your application
    }

    func update() {
        myCustomView.display()
    }
}

AVAudioPlayer

//
//  AppDelegate.swift
//

import Cocoa
import AVFoundation

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!
    
    func applicationDidFinishLaunching(aNotification: NSNotification) {
        let audioPath = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("test", ofType: "wav")!)
        let player : AVAudioPlayer
        player = try! AVAudioPlayer(contentsOfURL: audioPath, fileTypeHint: nil)
        player.prepareToPlay()
        player.play()
    }
}

私はXcode 7.2.1を使っていることに留意して下さい。第16行であなたがもしtryを使わなければ、あなたはエラー・メッセージCall can throw, but it is not marked with `try’ and the error is not handled.を受け取るでしょう。

try

私はエラー伝搬を止めるために、try!を使っています。

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ErrorHandling.html

trybang

GLFWとXcode

project102

どうやってGLFWを、Xcodeで使うか。

project102a

最初に、いくつかのフレームワークを追加します。

project102b

それから、ヘッダーファイルとライブラリのサーチパスを。

project102c

最後に、リンカー・フラッグです。

ココア プログラミング

cocoa-cover

私は、私がこの本“Cocoa Programming: For Mac OS X (5th Edition)”を読むべきかどうか分かりません。なぜなら、私は物事をドラッグするのを楽しんだことがないからです。

cocoaDrag

あなたは、amazon.comで無料のサンプルをダウンロードすることができますし、練習問題の回答をhttps://github.com/bignerdranch/cocoa-programming-for-osx-5eで、Xcodeのプロジェクトとして得ることもできます。

cocoaXcode

LIGOがブラックホールからの重力波を検出

LIGO1

いいえ、これはCW信号のウォータフォールではありません。

2015年9月14日09:50:45 UTCに、LIGOの2つの検出器が同時に重力波信号の変化を観測しました。この信号は、周波数で35Hzから250Hzへ連続的に上昇し、重力波によるピークの歪は1.0 × 10−21でした。

この論文、Observation of Gravitational Waves from a Binary Black Hole Mergerは、ここにあります:http://journals.aps.org/prl/pdf/10.1103/PhysRevLett.116.061102

LIGO2

非常に綺麗な結果で、正に理論とシミュレーションとで予想されていたとおりです。

31分:11秒に、進んで下さい。

OrpheusとMac mini

orpheus

Thunderbolt-FireWireアダプターと、FireWire 800-400(9Pin-6Pin)ケーブルを用いて、私は私のOrpheusをMac mini (El Capitan 10.11.3)に接続しました。

CarminaCeltica

私は192kHz/24bitのオーディオファイルを正常に再生することができましたが、内部で何が起きているかは分かりません。

orpheus2