-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.rb
65 lines (57 loc) · 1.78 KB
/
module.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
require 'yaml'
def update_action(base,file)
home = YAML::load(ENV["HOME"] + "/live_set/temperature/config.yml")["home"]
temp = nil
swt = nil
if file == "tmp" then
i = 0
File.open(base + "/" + file) do |f|
while line = f.gets
if line.length > 0 then
temp = home["min_temp"]
swt = 1
i = i + 1
#off信号判定
if i == home["off"] && line.split(" ")[1].to_i > home["threshold"] then
swt = 0
end
#温度判定
if i == home["temperature"]["1bit"] && line.split(" ")[1].to_i > home["threshold"] then
temp = temp + 1
end
if i == home["temperature"]["2bit"] && line.split(" ")[1].to_i > home["threshold"] then
temp = temp + 2
end
if i == home["temperature"]["3bit"] && line.split(" ")[1].to_i > home["threshold"] then
temp = temp + 4
end
if i == home["temperature"]["4bit"] && line.split(" ")[1].to_i > home["threshold"] then
temp = temp + 8
end
end
end
end
#tmpファイルがいっぱいになるので削除する
if i > 1 then
p base
p file
File.open(base + "/" + file,'w'){|f| f = nil}
end
end
return {"temp" => temp, "swt" => swt}
end
def temp2freq(temp)
#0度をMIDIノートナンバー0(C-1)とし、基準音をA-1(13.75Hz)とする
temp = temp - 5
oct = temp.div(7)
note = temp.modulo(7)
frequency = 13.75 * (2 ** oct)
#3度までは度数分の全音階
if note < 3 then
frequency = frequency * (2 ** ((note * 2).quo(12))).to_f
#4~7度は度数-1分の全音階+半音
else
frequency = frequency * (2 ** ((note * 2 - 1).quo(12))).to_f
end
return frequency
end