📄 cdplayer.c
字号:
/******************************************************************
* SEAL 2.0 *
* Copyright (c) 1999-2002 SEAL Developers. All Rights Reserved. *
* *
* Web site: http://sealsystem.sourceforge.net/ *
* E-mail (current maintainer): orudge@users.sourceforge.net *
******************************************************************/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Revision History:
*
* 13/04/2000 - Florian Xaver:
* + supports more than 1 cd drive
* + shows time
* + supports: forward/rewind ( << >> )
*
* 08/06/2001 - jdh added sane (==nasty text) defaults if fonts not found
*
* 30/03/2002 - Added About dialog (orudge)
*
* 04/04/2002 - Updated with new icon (orudge)
*/
#include <allegro.h>
#include "seal.h"
#include "menus.h"
#include "app.h"
#include "button.h"
#include "dialogs.h"
#include "iodlg.h"
#include "bcd.h"
#include "txts.h"
SetInfoAppName("CD Player");
SetInfoDesciption("CD Player");
SetInfoCopyright("Copyright (c) Michal Stencl 1999-2000");
SetInfoManufacturer("Michal Stencl");
/* text infos */
#define TXT_ERRORINLOADINGAUDIO INI_TEXT("Error in loading audio")
#define TXT_TITEL INI_TEXT("CD Player - drive %c:")
#define TXT_CDPLAYER INI_TEXT("CD Player")
#define TXT_STOP INI_TEXT("Stops playing")
#define TXT_PLAY INI_TEXT("Plays/resumes pause")
#define TXT_PAUSE INI_TEXT("Pause")
#define TXT_LAST INI_TEXT("Plays last track")
#define TXT_NEXT INI_TEXT("Plays next track")
#define TXT_REWIND INI_TEXT("Rewind (~4 seconds)")
#define TXT_FORWARD INI_TEXT("Forward (~4 seconds)")
#define TXT_OPEN_CLOSE INI_TEXT("Opens/closes CD-ROM")
#undef TXT_TIME
#define TXT_TIME INI_TEXT("Chooses which time ( /r) or address (a) is displayed")
#define TXT_DRIVE INI_TEXT("Changes CD-ROM drive, if more than one are avaiable")
#define TXT_PLAYBACKGROUND INI_TEXT("Closes CD Player without stopping")
/* messages */
#define MSG_PLAY 10001
#define MSG_PAUSE 10002
#define MSG_STOP 10003
#define MSG_RR 10004
#define MSG_FF 10005
#define MSG_OUT 10006
#define MSG_PREV 10007
#define MSG_NEXT 10008
#define MSG_RBACK 10009
#define MSG_PLAYATBACKGROUND 10010
#define MSG_TIME 10011
#define MSG_DRIVE 10012
l_int cd_track = 1;
l_int cd_track_max = 1;
l_int cd_track_pause = 0;
l_int cd_track_in_background = 0;
l_long cd_track_start = 0;
l_int time_type = 0;
int cur_drive_no=0;
void update_titel(p_object o,l_text text)
{
/// Redraws the titel from the window
_free(WINDOW(o)->caption);
WINDOW(o)->caption = set_format_text(NULL, "%s", text);
/* title, but not redraw any objects in the title such as X */
TEST_SUB_VIEWS(VIEW(o), WINDOW(o)->draw_title(WINDOW(o)));
}
static l_text return_hsg(int hsg) {
l_int hours, minutes, seconds;
l_text time_string;
seconds = hsg / 75;
minutes = seconds / 60;
seconds %= 60;
hours = minutes / 60;
minutes %= 60;
time_string = set_format_text(NULL, "%d:%02d:%02d", hours, minutes, seconds);
return time_string;
}
l_text get_song_time()
{
l_int start;
l_int len;
l_text time_string;
l_int track = bcd_now_playing();
l_int current_address;
if (track == 0) return "";
current_address = bcd_audio_position();
bcd_get_track_address(track, &start, &len);
switch (time_type)
{
case 0:
time_string = set_format_text(NULL, "%s", return_hsg(current_address - start));
break;
case 1:
time_string = set_format_text(NULL, "r%s", return_hsg(start + len - current_address));
break;
case 2:
default: // stop complaint about uninitialised string
time_string = set_format_text(NULL, "a%d", current_address);
break;
};
return time_string;
}
void trackinfo_draw ( p_view o )
{
t_rect r = o->get_local_extent(o);
t_point p;
BITMAP *out ;
out = o->begin_paint(o, &p, r);
if ( out ) {
l_text about;
if (cd_track_pause == 0)
about = set_format_text(NULL, "[song %i/%i %s]", cd_track, bcd_get_audio_info(), get_song_time());
else
about = set_format_text(NULL, "[song %i/%i] %s", cd_track, bcd_get_audio_info(), TXT_PAUSE); // OCR - 29/3/2002
o->background(o, out, rect_move(r, p.x, p.y));
button(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y,
0, makecol(255,255,255));
textout_draw_rect(out, o->font, about, -1, r.a.x+p.x+2, r.a.y+p.y+2,
r.b.x+p.x-2, r.b.y+p.y-2, TX_ALIGN_CENTER, makecol(255,255,255), TX_NOCOLOR, 0);
_free(about);
};
o->end_of_paint(o, r);
};
void trackinfo_func_callback ( p_object s ) /* it's call each second */
{
l_int p = bcd_now_playing();
VIEW(s)->draw_view(VIEW(s));
if ( p ) cd_track = p;
};
p_view trackinfo_init ( p_view o, t_rect r )
{
if ( !o ) return NULL;
view_init(o, r);
OBJECT(o)->process_tick = 1000; /* each second rewrite it */
OBJECT(o)->func_callback = &trackinfo_func_callback;
o->draw = &trackinfo_draw;
o->font = get_font_in_size("ActivaCE", 14, 14);
if(!o->font)o->font=font_system;
OBJECT(o)->set_options(OBJECT(o), OB_OF_SELECTABLE+OB_OF_ENABLE, false);
OBJECT(o)->set_options(OBJECT(o), OB_OF_STILLPROCESS, true);
VIEW(o)->brush.color = 0;
return o;
};
static void bcd_play_to_end ( l_int track)
{
// ff_re, to play forward or rewind, else 0
l_int start;
l_int len;
l_int t = cd_track_max = bcd_get_audio_info();
bcd_get_track_address(track, &start, &len);
while ( t > track ) {
l_int l;
l_int s;
bcd_get_track_address(t, &s, &l);
len += l;
t--;
};
bcd_play(start, len); // play track.
};
// ff_re, to play forward or rewind
static void bcd_play_ff_or_re ( signed int ff_re)
{
l_int cur_track = bcd_now_playing();
l_int len;
l_int start;
l_int t = cd_track_max = bcd_get_audio_info();
bcd_get_track_address(cur_track, &start, &len);
while ( t > cur_track ) {
l_int l;
l_int s;
bcd_get_track_address(t, &s, &l);
len += l;
t--;
};
bcd_play(bcd_audio_position() + ff_re, len); // if forward or rewind
};
/* cd - player translate event function */
void trans_ev ( p_object o, p_event event )
{
if ( event->type == EV_MESSAGE ) {
switch ( event->message ) {
case MSG_PLAYATBACKGROUND : {
clear_event(event);
set_event(event, EV_MESSAGE, MSG_CLOSE, o);
cd_track_in_background = 1;
o->put_event(o, event);
clear_event(event);
}; break;
case MSG_PLAY : {
clear_event(event);
if ( !cd_track_pause )
bcd_play_to_end(cd_track);
else bcd_resume();
cd_track_pause = 0;
}; break;
case MSG_PAUSE : {
clear_event(event);
if (cd_track_pause == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -