gtk2mp3 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,18 +18,16 @@ program = Program.new( {
18
18
  'website' => 'http://ruby-gnome-apps.blogspot.com/search/label/MP3',
19
19
  'website-label' => 'Ruby-Gnome MP3',
20
20
  'license' => 'GPL',
21
- 'copyright' => '2010-10-08 17:51:32',
21
+ 'copyright' => '2010-10-12 13:46:50',
22
22
  } )
23
23
 
24
- IO.popen(PLAYER,'w+') do |pipe|
25
- begin
26
- require 'gtk2mp3'
27
- Gtk2MP3::Couple.load
28
- program.window{|window| Gtk2MP3::GUI.new(window,pipe,program)}
29
- rescue Exception
30
- $!.puts_bang!
31
- ensure
32
- Gtk2MP3::Couple.dump
33
- program.finalize
34
- end
24
+ begin
25
+ require 'gtk2mp3'
26
+ Gtk2MP3::Couple.load
27
+ program.window{|window| Gtk2MP3::GUI.new(window,program)}
28
+ rescue Exception
29
+ $!.puts_bang!
30
+ ensure
31
+ Gtk2MP3::Couple.dump
32
+ program.finalize
35
33
  end
@@ -4,8 +4,55 @@ require 'gtk2mp3/couple'
4
4
  module Gtk2MP3
5
5
  MP3 = '.mp3'
6
6
 
7
+ class Pipe
8
+ def _read
9
+ @thread = Thread.new do
10
+ @pipe.each do |line|
11
+ line.strip!
12
+ $stderr.puts line if $trace
13
+ if line =~ /^\@I\s+(\S.*)$/ then
14
+ # :-??
15
+ elsif line == '@P 0' then
16
+ if @gui.continue then
17
+ @gui.couple.promote
18
+ @gui.previous = @gui.current
19
+ @gui.load_song
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ def open
26
+ if !@pipe then
27
+ @pipe = IO.popen(Configuration::PLAYER,'w+')
28
+ self.puts C_SILENCE
29
+ self._read
30
+ end
31
+ end
32
+ def puts(string)
33
+ self.open
34
+ @pipe.puts string
35
+ @pipe.flush
36
+ end
37
+ def close
38
+ if @pipe then
39
+ @thread.kill
40
+ @thread = nil
41
+ @pipe.close
42
+ @pipe = nil
43
+ end
44
+ end
45
+ def initialize(gui)
46
+ @gui = gui
47
+ self.open
48
+ end
49
+ end
50
+
7
51
  class GUI
8
52
  include Configuration
53
+ attr_reader :continue, :couple, :current
54
+ attr_writer :previous
55
+
9
56
  def random_song
10
57
  plays = false
11
58
  while !plays do
@@ -20,7 +67,7 @@ module Gtk2MP3
20
67
  def load_song
21
68
  self.random_song
22
69
  @info.text = File.basename(@current,MP3)
23
- @pipe.puts "#{C_LOAD} #{@current}"; @pipe.flush
70
+ @pipe.puts "#{C_LOAD} #{@current}"
24
71
  end
25
72
 
26
73
  def skip_song
@@ -30,9 +77,10 @@ module Gtk2MP3
30
77
 
31
78
  def stop_song
32
79
  if @continue then
33
- @pipe.puts C_STOP; @pipe.flush
80
+ @pipe.puts C_STOP
34
81
  @previous = ''
35
82
  @continue = false
83
+ @pipe.close
36
84
  else
37
85
  @continue = true
38
86
  self.load_song
@@ -40,7 +88,7 @@ module Gtk2MP3
40
88
  end
41
89
 
42
90
  def pause_song
43
- @pipe.puts C_PAUSE; @pipe.flush
91
+ @pipe.puts C_PAUSE
44
92
  end
45
93
 
46
94
  def delete_song
@@ -50,12 +98,14 @@ module Gtk2MP3
50
98
  self.load_song
51
99
  end
52
100
 
53
- def initialize(window,pipe,program)
54
- @pipe = pipe
101
+
102
+ def initialize(window,program)
55
103
  @playlist = Gtk2MP3::Playlist.new(DIRECTORY)
56
104
  @current = ''
57
105
  @previous = ''
58
106
  @continue = true
107
+ @pipe = Pipe.new(self)
108
+ window.signal_connect('destroy'){ @pipe.close }
59
109
 
60
110
  vbox = Widgets::VBox.new(window)
61
111
 
@@ -85,24 +135,7 @@ module Gtk2MP3
85
135
  end
86
136
  Widgets::Label.new(*SPACER4, hbox) # Spacer
87
137
 
88
- @pipe.puts C_SILENCE; @pipe.flush
89
138
  self.load_song
90
- Thread.new do
91
- @pipe.each do |line|
92
- line.strip!
93
- $stderr.puts line if $trace
94
- if line =~ /^\@I\s+(\S.*)$/ then
95
- # :-??
96
- elsif line == '@P 0' then
97
- if @continue then
98
- @couple.promote
99
- @previous = @current
100
- self.load_song
101
- end
102
- end
103
- end
104
- false
105
- end
106
139
 
107
140
  program.append_app_menu(RELOAD){ @playlist.reload }
108
141
  program.append_dock_menu(PAUSE.first){ self.pause_song } if PAUSE
@@ -29,13 +29,13 @@ module Configuration
29
29
 
30
30
  CLICKED = 'clicked' # Signal (should be no need to edit)
31
31
  NEXT = ['Next!', OPTIONS, CLICKED].freeze
32
- PAUSE = nil # ['Pause', OPTIONS, CLICKED].freeze # By default, want to keep it simple
33
- STOP = ['Stop', OPTIONS, CLICKED].freeze
34
- DELETE = ['Delete', OPTIONS, CLICKED].freeze
32
+ PAUSE = ['Pause', OPTIONS, CLICKED].freeze # this one can be set to nil
33
+ STOP = ['Stop', OPTIONS, CLICKED].freeze # this one can be set to nil
34
+ DELETE = ['Delete', OPTIONS, CLICKED].freeze # this one can be set to nil
35
35
 
36
36
  SELECT_A_FILE = [['Select a file', Gtk::FileChooser::ACTION_OPEN],HNIL].freeze
37
37
 
38
- PLAYER = 'mpg123 -q -R' # 'mpg123 -q -a hw:0,0 -R'
38
+ PLAYER = 'mpg123 -q -a hw:0,0 -R' # 'mpg123 -q -R'
39
39
  # mpg123 commands
40
40
  C_PAUSE = 'P'
41
41
  C_STOP = 'S'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtk2mp3
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - carlosjhr64@gmail.com
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-08 00:00:00 -07:00
18
+ date: 2010-10-12 00:00:00 -07:00
19
19
  default_executable: gtk2mp3
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency