-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderechart.rb
105 lines (97 loc) · 2.75 KB
/
derechart.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
93
94
95
96
97
98
99
100
101
102
103
104
105
=begin
DereChart.rb
Starlight Stage Note Compilation
=end
require_relative 'rhythm'
require_relative 'deremod'
# INCLUSION LINE STARTS HERE
module Deresute
module Structured
BeatSet = Struct.new( :timing, :bpm ) do
def initialize(*args)
opts = args.last.is_a?(Hash) ? args.pop : Hash.new
super *args
opts.select! { |k| members.include? k }
opts.each_pair do |k, v|
send "#{k}=", v
end
self.timing = Timing(0) if timing.nil?
self.bpm = BPMData(120) if bpm.nil?
end
redefine :timing= do |redef,value|
case value
when Timing
redef.call value
when Array
redef.call *value
when Integer
redef.call value
else
self.timing
end
end
redefine :bpm= do |redef,value|
return self.bpm if !value.is_a?(BPMData)
redef.call value
end
def to_json
[timing.to_f,bpm.to_f]
end
undef :[]
undef :[]=
undef :select
end
class TimingSet
def initialize
@offset = 0.0
@beatset = [BeatSet(Timing(0),BPMData(120))]
end
def set_first_timing(bpm,offset:nil)
@offset = Float(offset) rescue @offset
end
@beatset.first.bpm = bpm
[@offset,@beatset]
end
def <<(obj)
case obj
when BeatSet
@beatset << obj
when Array # (timing,bpm) order
@beatset << BeatSet(*obj)
when Hash # timing: bpm:
@beatset << BeatSet(**obj.map{|k,v|[k.to_s.to_sym,v]}.to_h)
else
fail TypeError, "unexpected object, given #{obj.class}"
end
self
end
def each(&block);@beatset.each(&block);end
def delete(id);@beatset.delete(id) if (id.is_a?(Integer))&&(id>0);end
def pop(amount=1);@beatset.pop(amount) if (amount.is_a?(Integer))&&(amount > 0)&&@beatset.size.pred.nonzero?;end
def push(*items);items.each { |o| self<<o };self;end
def inspect
"<TimingSet %#016x %s>" % [
self.__id__,
@beatset * ', '
]
end
end
class NoteLine < TypedArray; build base_class: [BaseNote,MixNotes], size: 5; end
class NoteSet < TypedArray; build direct_class: [NoteLine]; end
class PatternSet < TypedArray; build direct_class: [NoteSet]; end
class SlideSet < TypedArray; build direct_class: [SlidePath]; end
class DereChart
"Chart class with sophiscated structure"
def initialize
@timingset = Timingset.new
@notes = NoteSet.new
end
end
end
GlobalConstDeclare(self)
end
# INCLUSION LINE ENDS HERE
if __FILE__ == $0 then
puts("Loaded main module.")
end