hindbaer 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -24,7 +24,7 @@ Parse a session file:
24
24
  session.info.description
25
25
  session.info.author
26
26
  session.info.album
27
- session.ínfo.album_track
27
+ session.ínfo.track
28
28
  session.info.keywords
29
29
  # etc.
30
30
 
@@ -36,15 +36,13 @@ Render Session object as xml:
36
36
 
37
37
  Retrieve all tracks:
38
38
 
39
- tracks = session.tracks
40
- track = tracks.first
39
+ track = session.tracks.first
41
40
  track.name
42
- track.panning
41
+ track.pan
43
42
 
44
43
  Retrieve all track plugins:
45
44
 
46
- plugins = track.plugins
47
- plugin = plugins.first
45
+ plugin = track.plugins.first
48
46
  plugin.id
49
47
  plugin.name
50
48
  plugin.uid
@@ -53,11 +51,10 @@ There is currently support for the four default plugins and their attributes.
53
51
 
54
52
  Retrieve all regions for a given track:
55
53
 
56
- regions = tracks.first.regions
57
- region = region.first
58
- region.reference # audio file reference
54
+ region = tracks.first.regions.first
55
+ region.ref # audio file reference
59
56
  region.name
60
- region.start_time
57
+ region.start
61
58
  region.length
62
59
  region.offset
63
60
  region.fade_in
@@ -67,30 +64,26 @@ Retrieve all regions for a given track:
67
64
 
68
65
  Retrieve all fades for a given region:
69
66
 
70
- fades = regions.first.fades
71
- fade = fades.first
72
- fade.start_time
67
+ fade = regions.first.fades.first
68
+ fade.start
73
69
  fade.length
74
70
  fade.gain
75
71
 
76
72
  Retrieve all clipboard groups and their clips:
77
73
 
78
- groups = session.clipboard_groups
79
- group = group.first
74
+ group = session.clipboard_groups.first
80
75
  group.caption
81
- group.num_clips_used
76
+ group.used
82
77
 
83
- clips = group.clips
84
- clip = clips.first
85
- clip.reference
78
+ clip = group.clips.first
79
+ clip.ref
86
80
  clip.name
87
81
  clip.length
88
82
  clip.leq # (long-term equivalent level)
89
83
 
90
84
  Retrieve all markers:
91
85
 
92
- markers = session.markers
93
- marker = markers.first
86
+ marker = session.markers.first
94
87
  marker.id
95
88
  marker.name
96
89
  marker.time
@@ -105,11 +98,20 @@ Retrieve all audio file references:
105
98
  file.id
106
99
  file.name
107
100
  file.duration
108
- file.num_channels
101
+ file.channels
109
102
  file.leq # (long-term equivalent level)
110
- file.dynamics
103
+ file.dyn
111
104
  file.original_path # original file path
112
105
 
106
+ Add a new track:
107
+
108
+ new_track = Hindbaer::Track.new do |t|
109
+ t.name = 'Foo'
110
+ t.pan = '-1'
111
+ end
112
+ session.tracks << new_track
113
+ session.to_xml
114
+
113
115
  License
114
116
  -------
115
117
 
@@ -1,20 +1,37 @@
1
1
  module Hindbaer
2
2
  class AudioPool
3
3
 
4
- def initialize(fragment)
5
- @doc = fragment
6
- end
4
+ ATTRIBUTES = %w{
5
+ path location
6
+ }
7
+
8
+ attr_accessor *ATTRIBUTES
9
+ attr_accessor :files
7
10
 
8
- def path
9
- @doc['Path']
11
+ def self.parse(doc)
12
+ new do
13
+ ATTRIBUTES.each do |attribute|
14
+ self.send("#{attribute.to_sym}=", doc[attribute.capitalize])
15
+ end
16
+
17
+ self.files = doc.css('File').map do |f|
18
+ Hindbaer::File.parse(f)
19
+ end
20
+ end
10
21
  end
11
22
 
12
- def location
13
- @doc['Location']
23
+ def initialize(&block)
24
+ self.files = []
25
+
26
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
14
27
  end
15
28
 
16
- def files
17
- @doc.css('File').map { |f| Hindbaer::File.new(f.dup.unlink) }
29
+ def to_xml(xml)
30
+ xml.AudioPool Path: path, Location: location do
31
+ files.each do |file|
32
+ file.to_xml(xml)
33
+ end
34
+ end
18
35
  end
19
36
 
20
37
  end
data/lib/hindbaer/clip.rb CHANGED
@@ -1,29 +1,27 @@
1
1
  module Hindbaer
2
2
  class Clip
3
3
 
4
- def initialize(fragment, group)
5
- @doc = fragment
6
- @group = group
7
- end
8
-
9
- attr_reader :group
4
+ ATTRIBUTES = %w{
5
+ ref name length leq
6
+ }
7
+
8
+ attr_accessor *ATTRIBUTES
10
9
 
11
- def reference
12
- id = @doc['Ref'].to_i
13
- self.group.session.audio_pool.files.find { |a| a.id == id }
10
+ def self.parse(doc)
11
+ new do
12
+ ATTRIBUTES.each do |attribute|
13
+ self.send("#{attribute.to_sym}=", doc[attribute.capitalize])
14
+ end
15
+ end
14
16
  end
15
17
 
16
- def name
17
- @doc['Name']
18
+ def initialize(&block)
19
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
18
20
  end
19
21
 
20
- def length
21
- @doc['Length']
22
+ def to_xml(xml)
23
+ xml.Clip Ref: ref, Name: name, Length: length, Leq: leq
22
24
  end
23
25
 
24
- def leq
25
- return '-' if @doc['Leq'] == '-'
26
- @doc['Leq'].to_f
27
- end
28
26
  end
29
27
  end
data/lib/hindbaer/fade.rb CHANGED
@@ -1,20 +1,26 @@
1
1
  module Hindbaer
2
2
  class Fade
3
3
 
4
- def initialize(fragment)
5
- @doc = fragment
6
- end
4
+ ATTRIBUTES = %w{
5
+ start length gain
6
+ }
7
+
8
+ attr_accessor *ATTRIBUTES
7
9
 
8
- def start_time
9
- @doc['Start']
10
+ def self.parse(doc)
11
+ new do
12
+ ATTRIBUTES.each do |attribute|
13
+ self.send("#{attribute.to_sym}=", doc[attribute.capitalize])
14
+ end
15
+ end
10
16
  end
11
17
 
12
- def length
13
- @doc['Length']
18
+ def initialize(&block)
19
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
14
20
  end
15
21
 
16
- def gain
17
- @doc['Gain']
22
+ def to_xml(xml)
23
+ xml.Fade Start: start, Length: length, Gain: gain
18
24
  end
19
25
 
20
26
  end
data/lib/hindbaer/file.rb CHANGED
@@ -1,36 +1,34 @@
1
1
  module Hindbaer
2
2
  class File
3
- def initialize(fragment)
4
- @doc = fragment
5
- end
6
-
7
- def id
8
- @doc['Id'].to_i
9
- end
10
3
 
11
- def name
12
- @doc['Name']
13
- end
4
+ ATTRIBUTES = %w{
5
+ id name duration
6
+ channels leq dyn
7
+ }
8
+
9
+ attr_accessor *ATTRIBUTES
10
+ attr_accessor :original_path
14
11
 
15
- def duration
16
- @doc['Duration']
12
+ def self.parse(doc)
13
+ new do
14
+ ATTRIBUTES.each do |attribute|
15
+ self.send("#{attribute.to_sym}=", doc[attribute.capitalize])
16
+ end
17
+
18
+ self.original_path = doc.at_css('MetaData')['OriginalPath'] if
19
+ doc.at_css('MetaData')
20
+ end
17
21
  end
18
22
 
19
- def num_channels
20
- @doc['Channels'].to_i
23
+ def initialize(&block)
24
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
21
25
  end
22
26
 
23
- def leq
24
- @doc['Leq'].to_f || 0
27
+ def to_xml(xml)
28
+ xml.File Id: id, Name: name, Duration: duration, Channels: channels, Leq: leq do
29
+ xml.MetaData OriginalPath: original_path
30
+ end
25
31
  end
26
32
 
27
- def dynamics
28
- @doc['Dyn'].to_f || 0
29
- end
30
-
31
- def original_path
32
- return unless md = @doc.at_css('MetaData')
33
- md['OriginalPath']
34
- end
35
33
  end
36
34
  end
@@ -1,23 +1,38 @@
1
1
  module Hindbaer
2
2
  class Group
3
3
 
4
- def initialize(fragment, session)
5
- @doc = fragment
6
- @session = session
4
+ ATTRIBUTES = %w{
5
+ caption used
6
+ }
7
+
8
+ attr_accessor *ATTRIBUTES
9
+ attr_accessor :clips
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
+ end
19
+
20
+ self.clips = fragment.css('Clip').map { |c| Hindbaer::Clip.parse(c) }
21
+ end
7
22
  end
8
23
 
9
- attr_reader :session
10
-
11
- def caption
12
- @doc['Caption']
13
- end
14
-
15
- def num_clips_used
16
- @doc['Used'].to_i
24
+ def initialize(&block)
25
+ self.clips = []
26
+
27
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
17
28
  end
18
29
 
19
- def clips
20
- @doc.css('Clip').map { |c| Hindbaer::Clip.new(c.dup.unlink, self) }
30
+ def to_xml(xml)
31
+ xml.Group Caption: caption, Used: used do
32
+ clips.each do |clip|
33
+ clip.to_xml(xml)
34
+ end
35
+ end
21
36
  end
22
37
 
23
38
  end
data/lib/hindbaer/info.rb CHANGED
@@ -1,80 +1,33 @@
1
1
  module Hindbaer
2
2
  class Info
3
3
 
4
- def initialize(fragment)
5
- @doc = fragment
6
- end
7
-
8
- def name
9
- @doc['Name']
10
- end
11
-
12
- def title
13
- @doc['Title']
14
- end
15
-
16
- def subtitle
17
- @doc['Subtitle']
18
- end
19
-
20
- def author
21
- @doc['Author']
22
- end
23
-
24
- def link
25
- @doc['Link']
26
- end
27
-
28
- def email
29
- @doc['Email']
30
- end
31
-
32
- def description
33
- @doc['Description']
34
- end
35
-
36
- def album
37
- @doc['Album']
38
- end
39
-
40
- def album_track
41
- @doc['Track']
42
- end
43
-
44
- def artist
45
- @doc['Artist']
46
- end
47
-
48
- def composer
49
- @doc['Composer']
50
- end
51
-
52
- def date
53
- @doc['Date']
54
- end
55
-
56
- def genre
57
- @doc['Genre']
58
- end
59
-
60
- def copyright
61
- @doc['Copyright']
62
- end
63
-
64
- def explicit?
65
- @doc['Explicit'] == 'Yes'
66
- end
67
-
68
- def keywords
69
- @doc['Keywords'].split(',').map { |k| k.strip }
70
- end
71
-
72
- def identifier
73
- @doc['Identifier']
74
- end
75
-
76
- def reference
77
- @doc['Reference']
4
+ ATTRIBUTES = %w{
5
+ name title subtitle author link email
6
+ description album track artist composer
7
+ date genre copyright explicit keywords
8
+ identifier reference
9
+ }
10
+
11
+ attr_accessor *ATTRIBUTES
12
+
13
+ def self.parse(fragment)
14
+ new do
15
+ ATTRIBUTES.each do |attribute|
16
+ self.send("#{attribute.to_sym}=", fragment[attribute.capitalize])
17
+ end
18
+
19
+ self.keywords = keywords.split(',').map &:strip
20
+ end
21
+ end
22
+
23
+ def initialize(&block)
24
+ self.keywords = []
25
+
26
+ block.arity > 0 ? block.call(self) : instance_eval(&block)
27
+ end
28
+
29
+ def to_xml(xml)
30
+ xml.Info Subtitle: subtitle, Album: album, Composer: composer, Track: track, Genre: genre, Author: author, Link: link, Email: email, Description: description, Artist: artist, Date: date, Title: title, Explicit: explicit, Copyright: copyright, Identifier: identifier, Keywords: keywords.join(', '), Reference: reference
78
31
  end
79
32
 
80
33
  end