-
Notifications
You must be signed in to change notification settings - Fork 1
/
Controller.rb
executable file
·92 lines (70 loc) · 1.93 KB
/
Controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Controller.rb
# AiffPlayer
#
# Created by koji on 10/12/17.
# Copyright 2010 __MyCompanyName__. All rights reserved.
framework "CoreAudio"
class Controller
attr_accessor :label_freq,:slider_freq
def awakeFromNib()
NSLog("Controller.rb awaked from nib")
NSLog("Running on MacRuby " + MACRUBY_VERSION)
@auProcessor = AUProcessor.new
#NSApp.delegate = self
puts "#{NSApp.delegate }"
end
def hello(sender)
puts "Controller#hello"
end
def initCoreAudio(sender)
@auProcessor.initCoreAudio
end
def start(sender)
@auProcessor.start
end
def stop(sender)
#puts "Controller.stop"
@auProcessor.stop
end
def listOutputDevices(sender)
@auProcessor.listOutputDevices
end
def listOutputDevices_ruby(sender)
pSize = Pointer.new("I");
r = AudioHardwareGetPropertyInfo(KAudioHardwarePropertyDevices, pSize, nil)
puts pSize[0]
count = pSize[0] / 4 #is there any way to do sizeof(type??)
pDeviceIDs = Pointer.new("I", count)
r = AudioHardwareGetProperty(KAudioHardwarePropertyDevices, pSize, pDeviceIDs)
deviceIDs = Array.new
count.times do |i|
deviceIDs << pDeviceIDs[i]
end
#AudioStreamRangedDescription
deviceIDs.each do |devID|
pName = Pointer.new("c",256)
pSize = Pointer.new("I")
pSize.assign(256)
#p devID
#AudioStreamBasicDescriptions
r = AudioDeviceGetProperty(devID,0,0,KAudioDevicePropertyDeviceName, pSize,pName)
#p pSize[0]
name = String.new
(pSize[0]-1).times do |n| #NULL文字も入ってくるので -1。
name << pName[n]
end
puts "device - id:#{devID} name:#{name}"
end
#kAudioStreamPropertyAvailableVirtualFormats
end
#freq slider handler (should use Cocoa-Bind)
def freq_slider_changed(sender)
@label_freq.stringValue = sender.intValue().to_s
@auProcessor.setFreq(sender.intValue)
end
#delegation method
def applicationShouldTerminateAfterLastWindowClosed(sender)
puts "last window closed"
return true
end
end