Module: Wax

Includes:
Observable
Defined in:
lib/gswax/Wax.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#wax_batterObject

Returns the value of attribute wax_batter.



16
17
18
# File 'lib/gswax/Wax.rb', line 16

def wax_batter
  @wax_batter
end

#wax_coverartObject

Returns the value of attribute wax_coverart.



16
17
18
# File 'lib/gswax/Wax.rb', line 16

def wax_coverart
  @wax_coverart
end

#wax_durationObject

Returns the value of attribute wax_duration.



16
17
18
# File 'lib/gswax/Wax.rb', line 16

def wax_duration
  @wax_duration
end

#wax_infoObject

Returns the value of attribute wax_info.



16
17
18
# File 'lib/gswax/Wax.rb', line 16

def wax_info
  @wax_info
end

#wax_lineupObject

Returns the value of attribute wax_lineup.



16
17
18
# File 'lib/gswax/Wax.rb', line 16

def wax_lineup
  @wax_lineup
end

#wax_lupineObject

Returns the value of attribute wax_lupine.



16
17
18
# File 'lib/gswax/Wax.rb', line 16

def wax_lupine
  @wax_lupine
end

#wax_pipelineObject

Returns the value of attribute wax_pipeline.



16
17
18
# File 'lib/gswax/Wax.rb', line 16

def wax_pipeline
  @wax_pipeline
end

#wax_stateObject

Returns the value of attribute wax_state.



16
17
18
# File 'lib/gswax/Wax.rb', line 16

def wax_state
  @wax_state
end

#wax_trackingObject

Returns the value of attribute wax_tracking.



16
17
18
# File 'lib/gswax/Wax.rb', line 16

def wax_tracking
  @wax_tracking
end

Instance Method Details

#batter_up_waxObject



60
61
62
63
64
65
66
67
68
# File 'lib/gswax/Wax.rb', line 60

def batter_up_wax
@wax_batter = 0 unless @wax_batter
  @wax_lupine = @wax_lineup.shuffle if @wax_lupine.empty?
  if Settings.shuffle
    Settings.at_bat = @wax_lupine[@wax_batter] 
  else
    Settings.at_bat = @wax_lineup[@wax_batter]
  end
end

#get_wax_durationObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/gswax/Wax.rb', line 117

def get_wax_duration
  now = Time.now.sec.to_f
  now = 0.0 if now == 59.0
  @limit = now + 2.0
  
  GLib::Timeout.add(100){
    @qd = Gst::QueryDuration.new(3)#(Gst::Format::Type::TIME)
    @wax_pipeline.query(@qd)
    @wax_duration = @qd.parse[1]/1000000000
    if @wax_duration > 0
		send_wax_info("TRACK_PROGRESS")
      false
    elsif
      Time.now.sec.to_f > @limit
      false
    else
      true
    end
  }
end

#get_wax_tagsObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/gswax/Wax.rb', line 138

def get_wax_tags
  @gotTags = false
  @tags = @tagMsg.flatten
  
  if @tags.include?("title")
    @title = @tags[@tags.index("title") + 1]; @gotTags = true
  else @title = nil; end
  if @tags.include?("artist")
    @artist = @tags[@tags.index("artist") + 1]; @gotTags = true
  else @artist = nil; end
  if @tags.include?("album")
    @album = @tags[@tags.index("album") + 1]; @gotTags = true
  else @album = nil; end
  if @tags.include?("comments")
    @comments = @tags[@tags.index("comments") + 1]; @gotTags = true
  else @comments = nil; end
  if @tags.include?("track-number")
    @tracknumber = @tags[@tags.index("track-number") + 1]; @gotTags = true
  else @tracknumber = nil; end
  if @tags.include?("genre")
    @genre = @tags[@tags.index("genre") + 1]; @gotTags = true
  else @genre = nil; end
  if @tags.include?("album-artist")
    @albumartist = @tags[@tags.index("album-artist") + 1]; @gotTags = true
  else @albumartist = nil; end

  split = Settings.title_format.split("#")
  @infoentries = []
  split.each{|i|
    i = @title if i == "title"
    i = @album if i == "album"
    i = @artist if i == "artist"
    i = @genre if i == "genre"
    i = @albumartist if i == "album-artist"
    i = @tracknumber if i == "track-number"
    i = @comments if i == "comments"
    @infoentries << i
  }

  if @gotTags == false
    @wax_info = File.basename(Settings.at_bat)
    send_wax_info("wax_info")
  else
    @infoentries.compact!
    @wax_info = @infoentries.join
    send_wax_info("wax_info")
  end
end

#init_waxObject


INITIALIZE



23
24
25
26
27
28
29
# File 'lib/gswax/Wax.rb', line 23

def init_wax
Settings.read
  @wax_pipeline = Gst::ElementFactory.make("playbin2")
  @wax_state = "stopped"
  @wax_info = ""
  read_wax_lineup
end

#next_waxObject



208
209
210
211
212
213
# File 'lib/gswax/Wax.rb', line 208

def next_wax
  @wax_pipeline.stop
  @wax_batter += 1
  batter_up_wax
  play_wax
end

#pause_waxObject



222
223
224
225
# File 'lib/gswax/Wax.rb', line 222

def pause_wax
  @wax_pipeline.pause if @wax_pipeline
  @wax_state = "paused"
end

#play_pause_waxObject


TRANSPORT



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/gswax/Wax.rb', line 192

def play_pause_wax
  if Settings.at_bat
    if @wax_state == "stopped"
      play_wax
    elsif @wax_state == "paused"
      resume_wax
    else
      pause_wax
    end
    
  else
    @wax_info = "no tracks"
    send_wax_info("wax_info")
  end
end

#play_waxObject


PLAY / GET DURATION / GET TAGS



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
106
107
108
109
110
111
112
113
114
115
# File 'lib/gswax/Wax.rb', line 75

def play_wax
  if @wax_lineup.empty?
    batter_up_wax
  end
if @stream_thread; @stream_thread.exit; @stream_thread = nil; end
  if Settings.at_bat
	if Settings.at_bat =~ /http:/
		@wax_pipeline.uri = Settings.at_bat
		@wax_tracking = false
      @wax_state = "playing"
		@wax_info = "Stream: #{Settings.at_bat}"
		send_wax_info("wax_info")
		@stream_thread = Thread.new{@wax_pipeline.play}
    elsif File.exists?(Settings.at_bat)
      @wax_pipeline.uri= GLib.filename_to_uri(Settings.at_bat)
		@wax_tracking = true
      @wax_pipeline.play
      @wax_state = "playing"
      get_wax_duration
    end
	@tagMsg = []
	@wax_pipeline.bus.add_watch{|bus, message|
		case message.type
			when Gst::Message::ERROR
				p message.parse
			when Gst::Message::EOS
				@wax_state = "stopped"
				next_wax
				send_wax_info("eos")
			when Gst::Message::TAG
				@tagMsg << message.structure.entries
				get_wax_tags
		end
		true
	}
  else
    @wax_info = "no tracks"
    send_wax_info("wax_info")
    
  end
end

#prev_waxObject



215
216
217
218
219
220
# File 'lib/gswax/Wax.rb', line 215

def prev_wax
  @wax_pipeline.stop
  @wax_batter -= 1
  batter_up_wax
  play_wax
end

#read_wax_lineupObject



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
# File 'lib/gswax/Wax.rb', line 31

def read_wax_lineup
   @wax_lineup = []
	if Settings.line_up
		@wax_lineup = Settings.line_up
		@wax_info = "gsWax - ready to rock"
	else
		@wax_info = "gsWax"
		send_wax_info("wax_info")
	end
	@wax_lineup.compact!
	@wax_lupine = @wax_lineup.shuffle
	
	if Settings.shuffle
		if Settings.at_bat
			@wax_batter = @wax_lupine.index(Settings.at_bat)
		else
			@wax_batter = 0
		end
	else
		if Settings.at_bat
			@wax_batter = @wax_lineup.index(Settings.at_bat)
		else
			@wax_batter = 0
		end
	end
	
	batter_up_wax
end

#resume_waxObject



227
228
229
230
# File 'lib/gswax/Wax.rb', line 227

def resume_wax
  @wax_pipeline.play
  @wax_state = "playing"
end

#seek_to_wax(position_in_ms) ⇒ Object


SEEK / SEND / SAVE



247
248
249
250
251
252
253
254
# File 'lib/gswax/Wax.rb', line 247

def seek_to_wax(position_in_ms)
  if @wax_pipeline
    @wax_pipeline.send_event(Gst::EventSeek.new(1.0, 
    Gst::Format::Type::TIME, 
    Gst::Seek::FLAG_FLUSH.to_i | Gst::Seek::FLAG_KEY_UNIT.to_i, 
    Gst::Seek::TYPE_SET, position_in_ms * 1000000, Gst::Seek::TYPE_NONE, -1))
  end
end

#send_wax_info(info) ⇒ Object



257
258
259
260
# File 'lib/gswax/Wax.rb', line 257

def send_wax_info(info)
  changed
  notify_observers(info)
end

#stop_waxObject



232
233
234
235
# File 'lib/gswax/Wax.rb', line 232

def stop_wax
  @wax_pipeline.stop if @wax_pipeline
  @wax_state = "stopped"
end

#toggle_wax_shuffleObject



237
238
239
240
# File 'lib/gswax/Wax.rb', line 237

def toggle_wax_shuffle
Settings.shuffle  = !Settings.shuffle
  @wax_batter = @wax_lineup.index(Settings.at_bat)
end