hindbaer 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,30 @@
1
1
  module Hindbaer
2
2
  class Marker
3
- def initialize(fragment)
4
- @doc = fragment
5
- end
6
3
 
7
- def id
8
- @doc['Id'].to_i
4
+ ATTRIBUTES = %w{
5
+ id name time
6
+ }
7
+
8
+ attr_accessor *ATTRIBUTES
9
+
10
+ def self.parse(fragment)
11
+ new do
12
+ ATTRIBUTES.each do |attribute|
13
+ self.send(
14
+ "#{attribute.to_sym}=",
15
+ fragment[attribute.split('_').map(&:capitalize).join]
16
+ )
17
+ end
18
+ end
9
19
  end
10
20
 
11
- def name
12
- @doc['Name']
21
+ def initialize(&block)
22
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
13
23
  end
14
24
 
15
- def time
16
- @doc['Time']
25
+ def to_xml(xml)
26
+ xml.Marker Id: id, Name: name, Time: time
17
27
  end
28
+
18
29
  end
19
30
  end
@@ -7,16 +7,16 @@ module Hindbaer
7
7
  module Plugin
8
8
  extend self
9
9
 
10
- def create(fragment)
10
+ def parse(fragment)
11
11
  case fragment['UID']
12
12
  when 'nheq'
13
- Hindbaer::Plugin::Equalizer.new(fragment)
13
+ Hindbaer::Plugin::Equalizer.parse(fragment)
14
14
  when 'nhcl'
15
- Hindbaer::Plugin::Compressor.new(fragment)
15
+ Hindbaer::Plugin::Compressor.parse(fragment)
16
16
  when 'nhlu'
17
- Hindbaer::Plugin::Base.new(fragment)
17
+ Hindbaer::Plugin::Base.parse(fragment)
18
18
  when 'nhft'
19
- Hindbaer::Plugin::VoiceProfiler.new(fragment)
19
+ Hindbaer::Plugin::VoiceProfiler.parse(fragment)
20
20
  end
21
21
  end
22
22
 
@@ -2,20 +2,30 @@ module Hindbaer
2
2
  module Plugin
3
3
  class Base
4
4
 
5
- def initialize(fragment)
6
- @doc = fragment
7
- end
5
+ ATTRIBUTES = %w{
6
+ id name bypass
7
+ }
8
8
 
9
- def id
10
- @doc['Id'].to_i
11
- end
9
+ attr_accessor *ATTRIBUTES, :uid
12
10
 
13
- def name
14
- @doc['Name']
11
+ def self.parse(fragment)
12
+ new do
13
+ ATTRIBUTES.each do |attribute|
14
+ self.send(
15
+ "#{attribute.to_sym}=",
16
+ fragment[attribute.split('_').map(&:capitalize).join]
17
+ )
18
+ end
19
+ self.uid = fragment['UID']
20
+ end
15
21
  end
16
-
17
- def uid
18
- @doc['UID']
22
+
23
+ def initialize(&block)
24
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
25
+ end
26
+
27
+ def to_xml(xml)
28
+ xml.Plugin Id: id, Name: name, UID: uid, Bypass: bypass
19
29
  end
20
30
 
21
31
  end
@@ -2,16 +2,18 @@ module Hindbaer
2
2
  module Plugin
3
3
  class Compressor < Hindbaer::Plugin::Base
4
4
 
5
- def uid
6
- 'nhcl'
7
- end
8
-
9
- def name
10
- 'Compressor'
5
+ attr_accessor :comp
6
+
7
+ def self.parse(fragment)
8
+ plugin = super(fragment)
9
+
10
+ plugin.comp = fragment['Comp']
11
+
12
+ plugin
11
13
  end
12
-
13
- def comp
14
- @doc['Comp']
14
+
15
+ def to_xml(xml)
16
+ xml.Plugin Id: id, Name: name, UID: uid, Bypass: bypass, Comp: comp
15
17
  end
16
18
 
17
19
  end
@@ -1,61 +1,35 @@
1
1
  module Hindbaer
2
2
  module Plugin
3
3
  class Equalizer < Hindbaer::Plugin::Base
4
+
5
+ attr_accessor :low_freq_freq, :low_freq_gain, :low_freq_q
6
+ attr_accessor :mid_freq_freq, :mid_freq_gain, :mid_freq_q
7
+ attr_accessor :high_freq_freq, :high_freq_gain, :high_freq_q
8
+ attr_accessor :low_freq_type, :high_freq_type
4
9
 
5
- def uid
6
- 'nheq'
7
- end
8
-
9
- def name
10
- 'Equalizer'
11
- end
12
-
13
- def bypass
14
- @doc['Bypass']
15
- end
16
-
17
- def low_freq_freq
18
- @doc['LF_Freq']
19
- end
20
-
21
- def low_freq_gain
22
- @doc['LF_Gain']
23
- end
24
-
25
- def low_freq_q
26
- @doc['LF_Q']
27
- end
28
-
29
- def low_freq_type
30
- @doc['LF_Type']
31
- end
32
-
33
- def mid_freq_freq
34
- @doc['MF_Freq']
35
- end
36
-
37
- def mid_freq_gain
38
- @doc['MF_Gain']
39
- end
40
-
41
- def mid_freq_q
42
- @doc['MF_Q']
43
- end
44
-
45
- def high_freq_freq
46
- @doc['HF_Freq']
47
- end
48
-
49
- def high_freq_gain
50
- @doc['HF_Gain']
51
- end
52
-
53
- def high_freq_q
54
- @doc['HF_Q']
10
+
11
+ def self.parse(fragment)
12
+ plugin = super(fragment)
13
+
14
+ plugin.low_freq_freq = fragment['LF_Freq']
15
+ plugin.low_freq_gain = fragment['LF_Gain']
16
+ plugin.low_freq_q = fragment['LF_Q']
17
+ plugin.low_freq_type = fragment['LF_Type']
18
+
19
+ plugin.mid_freq_freq = fragment['MF_Freq']
20
+ plugin.mid_freq_gain = fragment['MF_Gain']
21
+ plugin.mid_freq_q = fragment['MF_Q']
22
+
23
+ plugin.high_freq_freq = fragment['HF_Freq']
24
+ plugin.high_freq_gain = fragment['HF_Gain']
25
+ plugin.high_freq_q = fragment['HF_Q']
26
+ plugin.high_freq_type = fragment['HF_Type']
27
+
28
+ plugin
55
29
  end
56
-
57
- def high_freq_type
58
- @doc['HF_Type']
30
+
31
+ def to_xml(xml)
32
+ xml.Plugin Id: id, Name: name, UID: uid, Bypass: bypass, LF_Freq: low_freq_freq, LF_Gain: low_freq_gain, LF_Q: low_freq_q, LF_Type: low_freq_type, MF_Freq: mid_freq_freq, MF_Gain: mid_freq_gain, MF_Q: mid_freq_q, HF_Freq: high_freq_freq, HF_Gain: high_freq_gain, HF_Q: high_freq_q, HF_Type: high_freq_type
59
33
  end
60
34
 
61
35
  end
@@ -2,62 +2,38 @@ module Hindbaer
2
2
  module Plugin
3
3
  class VoiceProfiler < Hindbaer::Plugin::Base
4
4
 
5
- def uid
6
- 'nhft'
5
+ attr_accessor :comp
6
+ attr_accessor :low_freq_freq, :low_freq_gain, :low_freq_q
7
+ attr_accessor :mid_freq_freq, :mid_freq_gain, :mid_freq_q
8
+ attr_accessor :high_freq_freq, :high_freq_gain, :high_freq_q
9
+ attr_accessor :high_pass_freq, :high_pass_gain
10
+
11
+ def self.parse(fragment)
12
+ plugin = super(fragment)
13
+
14
+ plugin.comp = fragment['Comp']
15
+
16
+ plugin.low_freq_freq = fragment['LF_Freq']
17
+ plugin.low_freq_gain = fragment['LF_Gain']
18
+ plugin.low_freq_q = fragment['LF_Q']
19
+
20
+ plugin.mid_freq_freq = fragment['MF_Freq']
21
+ plugin.mid_freq_gain = fragment['MF_Gain']
22
+ plugin.mid_freq_q = fragment['MF_Q']
23
+
24
+ plugin.high_freq_freq = fragment['HF_Freq']
25
+ plugin.high_freq_gain = fragment['HF_Gain']
26
+ plugin.high_freq_q = fragment['HF_Q']
27
+
28
+ plugin.high_pass_freq = fragment['HP_Freq']
29
+ plugin.high_pass_gain = fragment['HP_Gain']
30
+
31
+ plugin
32
+ end
33
+
34
+ def to_xml(xml)
35
+ xml.Plugin Id: id, Name: name, UID: uid, Bypass: bypass, LF_Freq: low_freq_freq, LF_Gain: low_freq_gain, LF_Q: low_freq_q, MF_Freq: mid_freq_freq, MF_Gain: mid_freq_gain, MF_Q: mid_freq_q, HF_Freq: high_freq_freq, HF_Gain: high_freq_gain, HF_Q: high_freq_q, HP_Freq: high_pass_freq, HP_Gain: high_pass_gain, Comp: comp
7
36
  end
8
-
9
- def name
10
- 'Voice Profiler'
11
- end
12
-
13
- def low_freq_freq
14
- @doc['LF_Freq']
15
- end
16
-
17
- def low_freq_gain
18
- @doc['LF_Gain']
19
- end
20
-
21
- def low_freq_q
22
- @doc['LF_Q']
23
- end
24
-
25
- def mid_freq_freq
26
- @doc['MF_Freq']
27
- end
28
-
29
- def mid_freq_gain
30
- @doc['MF_Gain']
31
- end
32
-
33
- def mid_freq_q
34
- @doc['MF_Q']
35
- end
36
-
37
- def high_freq_freq
38
- @doc['HF_Freq']
39
- end
40
-
41
- def high_freq_gain
42
- @doc['HF_Gain']
43
- end
44
-
45
- def high_freq_q
46
- @doc['HF_Q']
47
- end
48
-
49
- def high_pass_freq
50
- @doc['HP_Freq']
51
- end
52
-
53
- def high_pass_gain
54
- @doc['HP_Gain']
55
- end
56
-
57
- def comp
58
- @doc['Comp']
59
- end
60
-
61
37
  end
62
38
  end
63
39
  end
@@ -1,59 +1,35 @@
1
1
  module Hindbaer
2
2
  class Region
3
- def initialize(fragment, track = nil)
4
- @doc = fragment
5
- @track = track
6
- end
7
-
8
- attr_reader :track
9
-
10
- def reference
11
- id = @doc['Ref'].to_i
12
- self.track.session.audio_pool.files.find { |a| a.id == id }
13
- end
14
-
15
- def name
16
- @doc['Name']
17
- end
18
-
19
- def start_time
20
- @doc['Start'] || '00.0'
21
- end
22
-
23
- def length
24
- @doc['Length']
25
- end
26
-
27
- def relative_length
28
- length / track.session.length
29
- end
30
3
 
31
- def offset
32
- @doc['Offset'] || '00:00'
4
+ ATTRIBUTES = %w{
5
+ ref name start offset length fade_in fade_out gain leq dynamics
6
+ }
7
+
8
+ attr_accessor *ATTRIBUTES
9
+ attr_accessor :fades
10
+
11
+ def self.parse(fragment)
12
+ new do
13
+ ATTRIBUTES.each do |attribute|
14
+ self.send(
15
+ "#{attribute.to_sym}=",
16
+ fragment[attribute.split('_').map(&:capitalize).join]
17
+ )
18
+
19
+ self.start = '00.0' unless start
20
+
21
+ self.fades = fragment.css('Fade').map do |f|
22
+ Hindbaer::Fade.parse(f)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ def initialize(&block)
29
+ self.fades = []
30
+
31
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
33
32
  end
34
33
 
35
- def fade_in
36
- @doc['FadeIn']|| '00.0'
37
- end
38
-
39
- def fade_out
40
- @doc['FadeOut'] || '00.0'
41
- end
42
-
43
- def gain
44
- @doc['Gain'].to_f || 0.0
45
- end
46
-
47
- def leq
48
- @doc['Leq'].to_f || 0.0
49
- end
50
-
51
- def dynamics
52
- @doc['Dyn'].to_f || 0.0
53
- end
54
-
55
- def fades
56
- @doc.css('Fade').map { |f| Hindbaer::Fade.new(f.dup.unlink) }
57
- end
58
34
  end
59
35
  end
@@ -1,38 +1,49 @@
1
1
  module Hindbaer
2
-
3
2
  class Session
4
- def initialize(file)
5
- ::File.open(file, 'r') do |file|
6
- @doc = Nokogiri::XML(file)
7
- end
8
- end
9
-
10
- def software_version
11
- @doc.at_css('Session')['Version']
12
- end
13
-
14
- def sample_rate
15
- @doc.at_css('Session')['Samplerate']
16
- end
17
3
 
18
- def info
19
- Hindbaer::Info.new(@doc.at_css('Info').dup.unlink)
20
- end
21
-
22
- def audio_pool
23
- Hindbaer::AudioPool.new(@doc.at_css('AudioPool').dup.unlink)
24
- end
25
-
26
- def tracks
27
- @doc.css('Tracks Track').map { |t| Hindbaer::Track.new(t.dup.unlink, self) }
28
- end
4
+ ATTRIBUTES = %w{
5
+ version samplerate
6
+ }
7
+
8
+ attr_accessor *ATTRIBUTES
9
+ attr_accessor :info, :audio_pool, :tracks, :clipboard_groups, :markers
29
10
 
30
- def clipboard_groups
31
- @doc.css('Clipboard Group').map { |g| Hindbaer::Group.new(g.dup.unlink, self) }
11
+ def self.parse(xml)
12
+ doc = Nokogiri::XML(xml)
13
+
14
+ new do
15
+ ATTRIBUTES.each do |attribute|
16
+ self.send("#{attribute.to_sym}=",
17
+ doc.at_css('Session')[attribute.capitalize])
18
+ end
19
+
20
+ self.info = Hindbaer::Info.parse(doc.at_css('Info'))
21
+
22
+ self.audio_pool =
23
+ Hindbaer::AudioPool.parse(doc.at_css('AudioPool'))
24
+
25
+ self.tracks = doc.css('Tracks Track').map do |t|
26
+ Hindbaer::Track.parse(t)
27
+ end
28
+
29
+ self.clipboard_groups = doc.css('Clipboard Group').map do |g|
30
+ Hindbaer::Group.parse(g)
31
+ end
32
+
33
+ self.markers = doc.css('Markers Marker').map do |m|
34
+ Hindbaer::Marker.parse(m)
35
+ end
36
+ end
32
37
  end
33
38
 
34
- def markers
35
- @doc.css('Markers Marker').map { |m| Hindbaer::Marker.new(m.dup.unlink) }
39
+ def initialize(&block)
40
+ self.info = {}
41
+ self.audio_pool = {}
42
+ self.tracks = []
43
+ self.clipboard_groups = []
44
+ self.markers = []
45
+
46
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
36
47
  end
37
48
 
38
49
  def length
@@ -41,65 +52,29 @@ module Hindbaer
41
52
  end.compact
42
53
 
43
54
  regions.map do |r|
44
- Hindbaer.tc_to_secs(r.start_time) +
55
+ Hindbaer.tc_to_secs(r.start) +
45
56
  Hindbaer.tc_to_secs(r.length)
46
57
  end.max
47
58
  end
48
59
 
49
60
  def to_xml
50
61
  Nokogiri::XML::Builder.new do |xml|
51
- xml.Session Version: software_version, Samplerate: sample_rate do
52
- xml.Info Subtitle: info.subtitle, Album: info.album, Composer: info.composer, Track: info.album_track, Genre: info.genre, Author: info.author, Link: info.link, Email: info.email, Description: info.description, Artist: info.artist, Date: info.date, Title: info.title, Explicit: info.explicit? ? 'YES' : 'NO', Copyright: info.copyright, Identifier: info.identifier, Keywords: info.keywords.join(', '), Reference: info.reference
53
- xml.AudioPool Path: audio_pool.path, Location: audio_pool.location do
54
- audio_pool.files.each do |file|
55
- xml.File Id: file.id, Name: file.name, Duration: file.duration, Channels: file.num_channels, Leq: file.leq do
56
- xml.MetaData OriginalPath: file.original_path
57
- end
58
- end
59
- end
62
+ xml.Session Version: version, Samplerate: samplerate do
63
+ info.to_xml(xml)
64
+ audio_pool.to_xml(xml)
60
65
  xml.Tracks do
61
66
  tracks.each do |track|
62
- xml.Track Name: track.name, Pan: track.pan do
63
- track.regions.each do |region|
64
- xml.Region Ref: region.reference.id, Name: region.name, Start: region.start_time, Length: region.length, Offset: region.offset, FadeIn: region.fade_in, FadeOut: region.fade_out, Gain: region.gain, Leq: region.leq do
65
- region.fades.each do |fade|
66
- xml.Fade Start: fade.start_time, Length: fade.length, Gain: fade.gain
67
- end
68
- end
69
- end
70
- unless track.plugins.empty?
71
- xml.Plugins do
72
- track.plugins.each do |plugin|
73
- case plugin.uid
74
- when 'nheq'
75
- xml.Plugin Id: plugin.id, Name: plugin.name, UID: plugin.uid, Bypass: plugin.bypass, LF_Freq: plugin.low_freq_freq, LF_Gain: plugin.low_freq_gain, LF_Q: plugin.low_freq_q, LF_Type: plugin.low_freq_type, MF_Freq: plugin.mid_freq_freq, MF_Gain: plugin.mid_freq_gain, MF_Q: plugin.mid_freq_q, HF_Freq: plugin.high_freq_freq, HF_Gain: plugin.high_freq_gain, HF_Q: plugin.high_freq_q, HF_Type: plugin.high_freq_type do
76
- xml.cdata('')
77
- end
78
- when 'nhcl'
79
- xml.Plugin Id: plugin.id, Name: plugin.name, UID: plugin.uid, Comp: plugin.comp
80
- when 'nhlu'
81
- xml.Plugin Id: plugin.id, Name: plugin.name, UID: plugin.uid
82
- when 'nhft'
83
- xml.Plugin Id: plugin.id, Name: plugin.name, UID: plugin.uid, LF_Freq: plugin.low_freq_freq, LF_Gain: plugin.low_freq_gain, LF_Q: plugin.low_freq_q, MF_Freq: plugin.mid_freq_freq, MF_Gain: plugin.mid_freq_gain, MF_Q: plugin.mid_freq_q, HF_Freq: plugin.high_freq_freq, HF_Gain: plugin.high_freq_gain, HF_Q: plugin.high_freq_q, HP_Freq: plugin.high_pass_freq, HP_Gain: plugin.high_pass_gain, Comp: plugin.comp
84
- end
85
- end
86
- end
87
- end
88
- end
67
+ track.to_xml(xml)
89
68
  end
90
69
  end
91
70
  xml.Clipboard do
92
71
  clipboard_groups.each do |group|
93
- xml.Group Caption: group.caption, Used: group.num_clips_used do
94
- group.clips.each do |clip|
95
- xml.Clip Ref: clip.reference.id, Name: clip.name, Length: clip.length, Leq: clip.leq
96
- end
97
- end
72
+ group.to_xml(xml)
98
73
  end
99
74
  end
100
75
  xml.Markers do
101
76
  markers.each do |marker|
102
- xml.Marker Id: marker.id, Name: marker.name, Time: marker.time
77
+ marker.to_xml(xml)
103
78
  end
104
79
  end
105
80
  end