Module: Wax
- Includes:
- Observable
- Defined in:
- lib/gswax/Wax.rb
Instance Attribute Summary collapse
-
#wax_batter ⇒ Object
Returns the value of attribute wax_batter.
-
#wax_coverart ⇒ Object
Returns the value of attribute wax_coverart.
-
#wax_duration ⇒ Object
Returns the value of attribute wax_duration.
-
#wax_info ⇒ Object
Returns the value of attribute wax_info.
-
#wax_lineup ⇒ Object
Returns the value of attribute wax_lineup.
-
#wax_lupine ⇒ Object
Returns the value of attribute wax_lupine.
-
#wax_pipeline ⇒ Object
Returns the value of attribute wax_pipeline.
-
#wax_state ⇒ Object
Returns the value of attribute wax_state.
Instance Method Summary collapse
- #batter_up_wax ⇒ Object
- #get_wax_duration ⇒ Object
- #get_wax_tags ⇒ Object
-
#init_wax ⇒ Object
———————- INITIALIZE ———————-.
- #next_wax ⇒ Object
- #pause_wax ⇒ Object
-
#play_wax ⇒ Object
———————————————————– PLAY / GET DURATION / GET TAGS ———————————————————–.
-
#playpause_wax ⇒ Object
———————– TRANSPORT ———————–.
- #prev_wax ⇒ Object
- #read_wax_lineup ⇒ Object
- #resume_wax ⇒ Object
-
#seek_to_wax(position_in_ms) ⇒ Object
———————————— SEEK / SEND / SAVE ————————————.
- #send_wax_info(info) ⇒ Object
- #stop_wax ⇒ Object
- #toggle_wax_shuffle ⇒ Object
- #xsave_wax_settings(settings) ⇒ Object
Instance Attribute Details
#wax_batter ⇒ Object
Returns the value of attribute wax_batter.
16 17 18 |
# File 'lib/gswax/Wax.rb', line 16 def wax_batter @wax_batter end |
#wax_coverart ⇒ Object
Returns the value of attribute wax_coverart.
16 17 18 |
# File 'lib/gswax/Wax.rb', line 16 def wax_coverart @wax_coverart end |
#wax_duration ⇒ Object
Returns the value of attribute wax_duration.
16 17 18 |
# File 'lib/gswax/Wax.rb', line 16 def wax_duration @wax_duration end |
#wax_info ⇒ Object
Returns the value of attribute wax_info.
16 17 18 |
# File 'lib/gswax/Wax.rb', line 16 def wax_info @wax_info end |
#wax_lineup ⇒ Object
Returns the value of attribute wax_lineup.
16 17 18 |
# File 'lib/gswax/Wax.rb', line 16 def wax_lineup @wax_lineup end |
#wax_lupine ⇒ Object
Returns the value of attribute wax_lupine.
16 17 18 |
# File 'lib/gswax/Wax.rb', line 16 def wax_lupine @wax_lupine end |
#wax_pipeline ⇒ Object
Returns the value of attribute wax_pipeline.
16 17 18 |
# File 'lib/gswax/Wax.rb', line 16 def wax_pipeline @wax_pipeline end |
#wax_state ⇒ Object
Returns the value of attribute wax_state.
16 17 18 |
# File 'lib/gswax/Wax.rb', line 16 def wax_state @wax_state end |
Instance Method Details
#batter_up_wax ⇒ Object
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_duration ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/gswax/Wax.rb', line 112 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_tags ⇒ Object
133 134 135 136 137 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 |
# File 'lib/gswax/Wax.rb', line 133 def @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_wax ⇒ Object
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_wax ⇒ Object
204 205 206 207 208 209 |
# File 'lib/gswax/Wax.rb', line 204 def next_wax @wax_pipeline.stop @wax_batter += 1 batter_up_wax play_wax end |
#pause_wax ⇒ Object
218 219 220 221 |
# File 'lib/gswax/Wax.rb', line 218 def pause_wax @wax_pipeline.pause if @wax_pipeline @wax_state = "paused" end |
#play_wax ⇒ Object
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 |
# File 'lib/gswax/Wax.rb', line 75 def play_wax if @wax_lineup.empty? batter_up_wax end if Settings.at_bat if File.exists?(Settings.at_bat) @wax_pipeline.uri= GLib.filename_to_uri(Settings.at_bat) bus = @wax_pipeline.bus @tagMsg = [] bus.add_watch {|bus, | case .type when Gst::Message::ERROR p .parse when Gst::Message::EOS @wax_state = "stopped" next_wax send_wax_info("eos") when Gst::Message::TAG @tagMsg << .structure.entries end true } @wax_pipeline.play @wax_state = "playing" get_wax_duration end else @wax_info = "no tracks" send_wax_info("wax_info") end end |
#playpause_wax ⇒ Object
TRANSPORT
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/gswax/Wax.rb', line 188 def playpause_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 |
#prev_wax ⇒ Object
211 212 213 214 215 216 |
# File 'lib/gswax/Wax.rb', line 211 def prev_wax @wax_pipeline.stop @wax_batter -= 1 batter_up_wax play_wax end |
#read_wax_lineup ⇒ Object
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 = [] unless Settings.line_up.empty? @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_wax ⇒ Object
223 224 225 226 |
# File 'lib/gswax/Wax.rb', line 223 def resume_wax @wax_pipeline.play @wax_state = "playing" end |
#seek_to_wax(position_in_ms) ⇒ Object
SEEK / SEND / SAVE
243 244 245 246 247 248 249 250 |
# File 'lib/gswax/Wax.rb', line 243 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
253 254 255 256 |
# File 'lib/gswax/Wax.rb', line 253 def send_wax_info(info) changed notify_observers(info) end |
#stop_wax ⇒ Object
228 229 230 231 |
# File 'lib/gswax/Wax.rb', line 228 def stop_wax @wax_pipeline.stop if @wax_pipeline @wax_state = "stopped" end |
#toggle_wax_shuffle ⇒ Object
233 234 235 236 |
# File 'lib/gswax/Wax.rb', line 233 def toggle_wax_shuffle Settings.shuffle = !Settings.shuffle @wax_batter = @wax_lineup.index(Settings.at_bat) end |
#xsave_wax_settings(settings) ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/gswax/Wax.rb', line 258 def xsave_wax_settings(settings) settings[0] = @wax_roster if @wax_shuffle == true settings[1] = "shuffle on" else settings[1] = "shuffle off" end settings[2] = Settings.at_bat File.open(@settings_file, "w"){|file| settings.each{|entry| file.puts(entry)} } end |