File: freaky-coo.e

package info (click to toggle)
entity 1.0.1-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,604 kB
  • ctags: 5,394
  • sloc: ansic: 64,242; sh: 7,377; makefile: 776; perl: 319
file content (259 lines) | stat: -rw-r--r-- 6,160 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<object name="mp3_player" default-lang="c">
  <window title="Freaky-Coo-MP3" name="mp3_player"
          ondelete="close_down"
          height="570" width="650">
    <halign>
      <frame visible="true" title="Play Queue" expand="true">
        <ctree name="playqueue" cols="3" onselect="play_song"
               expand="true" height="140" >
          <ctree-column name="filename" title="Filename" auto-resize="true"/>
              <ctree-column name="length" title="Length" auto-resize="true"/>
              <ctree-column name="bitrate" title="Bitrate" auto-resize="true"/>
        </ctree>
      </frame>
      <vslider name="vol" onchange="set_vol"/>
    </halign>

    <frame title="Database">
      <entry name="search_path" text="/home/john/music"/>
      <halign>
        <button onclick="rebuild_db" label="Rebuild the database"/>
        <button onclick="append_db" label="Append to database"/>
        <button onclick="stop" label="Stop mpg123"/>
      </halign>
    </frame>

    <frame title="Search">
      <entry name="search" text="" onenter="find_songs"/>
    </frame>

    <frame expand="true" title="Results">
      <scrollwindow expand="true">
        <ctree name="mp3s" cols="1" onselect="move_to_queue" 
               expand="true">
	  <ctree-column name="file" title="Filename"/>
        </ctree>
      </scrollwindow>
    </frame>
  </window>
  <data name="appenders" />
  <io name="rebuild" mode="line" onnewdata="append_to_db" />
  <include file="freaky-coo-code.e"/>
  <norender><perl><![CDATA[

/* The perl implementation. */
#if 0

use Symbol;
use POSIX ":sys_wait_h";
%ENV;
$HOME = $ENV{HOME};
$table_file = "$HOME/.mp3list";  # Where the list goes.
load_db();
load_mixer_settings();

sub load_mixer_settings
{
	my $output = `aumix -v q`;    # Returns "vol 46, 46"

	my @words = split(/\ /, $output);

	my $vol = $words[2];
	print "Starting volume is $vol\n";

	my $slider = enode("vslider.vol");
	$slider->attrib("value" => $vol);
}

sub set_vol
{
	my $spinner = shift;
	my $val = $spinner->attrib("value");
	`aumix -v $val`;
}

sub query_playing_song
{
	my $timer = shift;
	my $pid = $timer->attrib("pid");

	if (-1 == waitpid($pid, &WNOHANG) )
	{
		my $row = enode( $timer->attrib("row") );
		$row->destroy();
		$timer->destroy();
		play_queue_marshall_next();
	}
}

sub load_db
{
	open TABLE_FILE, "<$table_file";
	@mp3s = <TABLE_FILE>;
}

sub append_to_db
{
	my ($io, $data, $size) = @_;   # $data is a line (mp3)
	if (0 == $size)
	{
		print "closing time\n";
		close ( $io->attrib("fh") );
		$io->attrib("fd" => "-1");

		if ($io->attrib_is_true ("rebuild") )
		{
			enode ("button.rebuild")->attrib ("sensitive" => "true");
		}
		$io->destroy();
		my $object = enode("object.mp3_player");
		$object->new_child("io.rebuild",
		                   "mode" => "line",
		                   "onnewdata" => "append_to_db");
		return;
	}
	
	push @mp3s, $data;
	print TABLE_FILE $data;
}

sub rebuild_db
{
	my $rebuild_button = shift;

	my $io = enode("io.rebuild");
	my $fh = FH.$io;
	my $entry = enode("entry.search_path");
	my $search_path = $entry->attrib("text");

	# The SLOW_IS_A_GOOBER factor.
	# $rebuild_button->attrib ("sensitive" => "false");

	enode ("data.appenders")->destroy_children ();

	close TABLE_FILE;
	unlink($table_file);                 # Delete the file.
	open TABLE_FILE, ">$table_file";

	@mp3s = ();                          # DB gone too.

	open ($fh, "find $search_path -name '*.mp3*'|");
	$io->attrib("fd" => fileno($fh), "fh" => $fh, "rebuild" => "true");
}

sub append_db
{
	my $io_holder = enode("data.appenders");
	my $io = $io_holder->new_child ("io",
	                                "mode" => "line",
	                                "onnewdata" => "append_to_db");

	my $fh = FH.$io;
	my $entry = enode("entry.search_path");
	my $search_path = $entry->attrib("text");
	
	open ($fh, "find $search_path -name '*.mp3*'|");
	$io->attrib("fd" => fileno($fh), "fh" => $fh);
}

sub find_songs
{
	my $entry = shift;
	my $request = $entry->attrib("text");
	my $ctree = enode("ctree.mp3s");

	$ctree->attrib("frozen" => "true");
	#$ctree->destroy_children();

	foreach my $row ($ctree->children() )
	{
		$row->destroy();
	}

	$ctree->attrib("frozen" => "false");

	#print "starting search for --$request--\n";
	$ctree->attrib("frozen" => "true");
	foreach my $mp3 (@mp3s)
	{
		if($mp3 =~ /$request/)   ###    && $mp3 !~ /\&|\'/)
		{
			#print "$mp3 matches\n";

			my $ctree_row = $ctree->new_child("ctree-row");
			my $cell = $ctree_row->new_child("ctree-cell.mp3",
			                                 "text" => "$mp3");
		}
	}
	$ctree->attrib("frozen" => "false");
}
my $mpg123_PID;
sub play_song
{
	my $ctree_row = shift;
	my $filename_cell = $ctree_row->child("ctree-cell.filename");
	my $filename = $filename_cell->attrib("text");

	if ($mpg123_PID)
	{
		kill (9, $mpg123_PID);
	}
	close (MP3);
	chop $filename;
	$filename = qq!"!.$filename.qq!"\n!;  #put ""s and newline
	print "mpg123 $filename";
	$mpg123_PID = open (MP3, "|mpg123 -b 512 $filename");

	#$ctree_row->destroy();     # Remove the entry from the ctree.
	my $cell = $ctree_row->child("ctree-cell");
	$cell->attrib("image" => "playing.xpm");

	my $object = enode("object");
	my $timer_xml = qq!
	<timer name="cursong" pid="$mpg123_PID"
	       interval="300" action="query_playing_song" row="$ctree_row">!;

	$object->append_xml($timer_xml);
}
sub move_to_queue
{
	my $ctree_row = shift;
	my $cell = $ctree_row->child("ctree-cell.mp3");
	my $filename = $cell->attrib("text");

	my $ctree = enode("ctree.playqueue");

	my $new_row = $ctree->new_child("ctree-row");
	$new_row->new_child("ctree-cell.filename", "text" => "$filename");
	$new_row->new_child("ctree-cell.length", "text" => "unknown");
	$new_row->new_child("ctree-cell.bitrate", "text" => "unknown");
}
sub play_queue_marshall_next
{
	my $ctree = enode("ctree.playqueue");
	my $row = $ctree->child("ctree-row");
	if ($row)
	{
		$row->attrib("selected" => "true");
	}
}
sub stop
{
	if($mpg123_PID)
	{
		kill (9, $mpg123_PID);
	}
	close (MP3);
}

sub close_down
{
	if($mpg123_PID)
	{
		kill (9, $mpg123_PID);
	}
	close (MP3);
	exit();
}
  ]]></perl></norender>
</object>