Patch by Vasilis Kaoutsis:

* Fixed several missing incorrect initializations from fYear.
* Style cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21739 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-07-29 21:12:21 +00:00
parent 620f852c78
commit 3dab566b3a
7 changed files with 1556 additions and 1402 deletions

View File

@ -15,6 +15,7 @@
#ifndef BUTTON_BITMAPS_H
#define BUTTON_BITMAPS_H
#include <SupportDefs.h>
// #pragma mark play

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,28 @@
/*
* Copyright (c) 2006-2007, Haiku, Inc.
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT license.
*
* Author:
* DarkWyrm <bpmagic@columbus.rr.com>
* DarkWyrm, bpmagic@columbus.rr.com
*/
#ifndef CDAUDIODEVICE_H
#define CDAUDIODEVICE_H
#include <SupportDefs.h>
#include <String.h>
#include <List.h>
#include <String.h>
#include <SupportDefs.h>
// The SCSI table of contents consists of a 4-byte header followed by 100 track
// descriptors, which are each 8 bytes. We don't really need the first 5 bytes
// of the track descriptor, so we'll just ignore them. All we really want is the
// length of each track, which happen to be the last 3 bytes of the descriptor.
// fLength of each track, which happen to be the last 3 bytes of the descriptor.
typedef struct {
uint8 reserved;
uint8 adr_control; // bytes 0-3 are control, 4-7 are ADR
uint8 track_number;
uint8 reserved2;
uint8 reserved3;
uint8 min;
uint8 sec;
@ -29,7 +30,7 @@ typedef struct {
} TrackDescriptor;
enum CDState {
kNoCD=0,
kNoCD = 0,
kStopped,
kPaused,
kPlaying,
@ -38,79 +39,104 @@ enum CDState {
kInit
};
class cdaudio_time
{
public:
cdaudio_time(const int32 min=-1,const int32 &sec=-1);
cdaudio_time(const cdaudio_time &from);
cdaudio_time &operator=(const cdaudio_time &from);
cdaudio_time operator+(const cdaudio_time &from);
cdaudio_time operator-(const cdaudio_time &from);
int32 minutes;
int32 seconds;
class CDAudioTime {
public:
CDAudioTime(const int32 min = -1, const int32 &sec = -1);
CDAudioTime(const CDAudioTime &from);
CDAudioTime &operator=(const CDAudioTime &from);
CDAudioTime operator+(const CDAudioTime &from);
CDAudioTime operator-(const CDAudioTime &from);
void SetMinutes(const int32& minutes)
{
fMinutes = minutes;
}
void SetSeconds(const int32& seconds)
{
fSeconds = seconds;
}
int32 GetMinutes() const
{
return fMinutes;
}
int32 GetSeconds() const
{
return fSeconds;
}
private:
int32 fMinutes;
int32 fSeconds;
};
class cdaudio_data
{
public:
cdaudio_data(const int32 &id = -1, const int32 &count = -1,
const int32 &disclength = -1);
cdaudio_data(const cdaudio_data &from);
cdaudio_data &operator=(const cdaudio_data &from);
int32 disc_id;
int32 track_count;
int32 length;
BString frame_offsets;
class CDAudioData {
public:
CDAudioData(const int32 &id = -1, const int32 &count = -1,
const int32 &discLength = -1);
CDAudioData(const CDAudioData &from);
CDAudioData &operator=(const CDAudioData &from);
private:
int32 fDiscId;
int32 fTrackCount;
int32 fLength;
BString fFrameOffsets;
};
class CDAudioDevice
{
public:
CDAudioDevice(void);
~CDAudioDevice(void);
bool Play(const int16 &track);
bool Pause(void);
bool Resume(void);
bool Stop(void);
bool Eject(void);
bool StartFastFwd(void);
bool StopFastFwd(void);
bool StartRewind(void);
bool StopRewind(void);
bool SetVolume(uint8 value);
uint8 GetVolume(void);
CDState GetState(void);
int16 CountTracks(void);
int16 GetTrack(void);
uint8 CountDrives(void);
bool SetDrive(const int32 &drive);
const char * GetDrivePath(void) const;
int32 GetDrive(void) const { return fDriveIndex; }
bool GetTime(cdaudio_time &track, cdaudio_time &disc);
bool GetTimeForTrack(const int16 &index, cdaudio_time &track);
bool GetTimeForDisc(cdaudio_time &disc);
int32 GetDiscID(void);
bool IsDataTrack(const int16 &track);
private:
int32 FindDrives(const char *path);
int fFileHandle;
BString * fDrivePath;
BList fDriveList;
int32 fDriveIndex;
class CDAudioDevice {
public:
CDAudioDevice();
~CDAudioDevice();
bool Play(const int16 &track);
bool Pause();
bool Resume();
bool Stop();
bool Eject();
bool StartFastFwd();
bool StopFastFwd();
bool StartRewind();
bool StopRewind();
bool SetVolume(uint8 value);
uint8 GetVolume();
CDState GetState();
int16 CountTracks();
int16 GetTrack();
uint8 CountDrives();
bool SetDrive(const int32 &drive);
const char* GetDrivePath() const;
int32 GetDrive() const
{
return fDriveIndex;
}
bool GetTime(CDAudioTime &track, CDAudioTime &disc);
bool GetTimeForTrack(const int16 &index, CDAudioTime &track);
bool GetTimeForDisc(CDAudioTime &disc);
int32 GetDiscID();
bool IsDataTrack(const int16 &track);
private:
int32 _FindDrives(const char *path);
int fFileHandle;
BString* fDrivePath;
BList fDriveList;
int32 fDriveIndex;
};
#endif
#endif // CDAUDIODEVICE_H

File diff suppressed because it is too large Load Diff

View File

@ -1,149 +1,212 @@
#ifndef CDDBSUPPORT_H
#define CDDBSUPPORT_H
#include <NetEndpoint.h>
#include <String.h>
#include <scsi.h>
#include <vector>
#include "CDAudioDevice.h"
#include <Entry.h>
#include <List.h>
#include "CDAudioDevice.h"
#include <NetEndpoint.h>
#include <String.h>
#include <scsi.h>
#include <vector>
using std::vector;
class CDDBData
{
public:
CDDBData(int32 discid=-1);
CDDBData(const CDDBData &from);
~CDDBData(void);
CDDBData & operator=(const CDDBData &from);
status_t Load(const entry_ref &ref);
status_t Save(const char *filename);
status_t Load(void);
status_t Save(void);
void MakeEmpty(void);
void SetDiscID(const int32 &id) { fDiscID=id; }
int32 DiscID(void) const { return fDiscID; }
uint16 CountTracks(void) const;
const char * TrackAt(const int16 &index) const;
bool RenameTrack(const int32 &index, const char *newname);
void AddTrack(const char *track, const cdaudio_time &time,
const int16 &index=-1);
void RemoveTrack(const int16 &index);
cdaudio_time * TrackTimeAt(const int16 &index);
void SetDiscTime(const cdaudio_time time) { fDiscTime = time; }
cdaudio_time * DiscTime(void) { return &fDiscTime; }
void SetGenre(const char *genre) { fGenre=genre; }
const char * Genre(void) { return fGenre.String(); }
void SetArtist(const char *artist) { fArtist=artist; }
const char * Artist(void) const { return fArtist.String(); }
void SetAlbum(const char *album) { fAlbum=album; }
const char * Album(void) const { return fAlbum.String(); }
void SetYear(const int16 &year) { fYear=year; }
int16 Year(void) const { return fYear; }
private:
void EmptyLists(void);
int32 fDiscID;
BString fArtist;
BString fAlbum;
BString fGenre;
BList fTrackList;
BList fTimeList;
cdaudio_time fDiscTime;
int32 fYear;
class CDDBData {
public:
CDDBData(int32 discid = -1);
CDDBData(const CDDBData &from);
~CDDBData();
CDDBData& operator=(const CDDBData &from);
status_t Load(const entry_ref &ref);
status_t Save(const char *filename);
status_t Load();
status_t Save();
void MakeEmpty();
void SetDiscID(const int32 &id)
{
fDiscID = id;
}
int32 DiscID() const
{
return fDiscID;
}
uint16 CountTracks() const;
const char* TrackAt(const int16 &index) const;
bool RenameTrack(const int32 &index, const char *newname);
void AddTrack(const char *track, const CDAudioTime &time,
const int16 &index=-1);
void RemoveTrack(const int16 &index);
CDAudioTime* TrackTimeAt(const int16 &index);
void SetDiscTime(const CDAudioTime time)
{
fDiscTime = time;
}
CDAudioTime* DiscTime()
{
return &fDiscTime;
}
void SetGenre(const char *genre)
{
fGenre=genre;
}
const char* Genre()
{
return fGenre.String();
}
void SetArtist(const char *artist)
{
fArtist = artist;
}
const char* Artist() const
{
return fArtist.String();
}
void SetAlbum(const char *album)
{
fAlbum = album;
}
const char* Album() const
{
return fAlbum.String();
}
void SetYear(const int16 &year)
{
fYear = year;
}
int16 Year() const
{
return fYear;
}
private:
void _EmptyLists();
int32 fDiscID;
BString fArtist;
BString fAlbum;
BString fGenre;
BList fTrackList;
BList fTimeList;
CDAudioTime fDiscTime;
int32 fYear;
};
// based on Jukebox by Chip Paul
class CDDBQuery
{
public:
CDDBQuery(const char *server, int32 port = 888);
~CDDBQuery(void);
void SetToSite(const char *server, int32 port);
status_t GetSites(bool (*)(const char *site, int port,
const char *latitude, const char *longitude,
const char *description, void *state), void *);
void SetToCD(const char *devicepath);
const char * GetArtist(void) { return fCDData.Artist(); }
const char * GetAlbum(void) { return fCDData.Album(); }
const char * GetGenre(void) { return fCDData.Genre(); }
bool GetData(CDDBData *data, bigtime_t timeout);
void SetData(const CDDBData &data);
bool Ready() const { return fState == kDone; }
int32 CurrentDiscID() const { return fCDData.DiscID(); }
class CDDBQuery {
public:
CDDBQuery(const char *server, int32 port = 888);
~CDDBQuery();
void SetToSite(const char *server, int32 port);
status_t GetSites(bool (*)(const char *site, int port,
const char *latitude, const char *longitude,
const char *description, void *state), void *);
static int32 GetDiscID(const scsi_toc *);
static int32 GetTrackCount(const scsi_toc *);
static cdaudio_time GetDiscTime(const scsi_toc *);
static void GetTrackTimes(const scsi_toc *, vector<cdaudio_time> &times);
static BString OffsetsToString(const scsi_toc *);
private:
status_t Connect();
void Disconnect();
bool IsConnected() const;
static int32 QueryThread(void *);
void SetToCD(const char *devicepath);
// cached retrieved data
enum State
{
kInitial,
kReading,
kDone,
kInterrupting,
kError
};
void SetDefaultInfo(void);
status_t OpenContentFile(const int32 &discID);
status_t ReadFromServer(BString &data);
void ParseData(const BString &data);
void WriteFile(void);
void ReadLine(BString &);
status_t IdentifySelf();
const char* GetArtist()
{
return fCDData.Artist();
}
const char * GetToken(const char *, BString &);
const char* GetAlbum()
{
return fCDData.Album();
}
const char* GetGenre()
{
return fCDData.Genre();
}
bool GetData(CDDBData *data, bigtime_t timeout);
void SetData(const CDDBData &data);
bool Ready() const
{
return fState == kDone;
}
int32 CurrentDiscID() const
{
return fCDData.DiscID();
}
static int32 GetDiscID(const scsi_toc *);
static int32 GetTrackCount(const scsi_toc *);
static CDAudioTime GetDiscTime(const scsi_toc *);
static void GetTrackTimes(const scsi_toc *, vector<CDAudioTime> &times);
static BString OffsetsToString(const scsi_toc *);
private:
status_t _Connect();
void _Disconnect();
bool _IsConnected() const;
static int32 _QueryThread(void *);
// cached retrieved data
enum State {
kInitial,
kReading,
kDone,
kInterrupting,
kError
};
void _SetDefaultInfo();
status_t _OpenContentFile(const int32 &discID);
status_t _ReadFromServer(BString &data);
void _ParseData(const BString &data);
void _WriteFile();
void _ReadLine(BString &);
status_t _IdentifySelf();
const char* _GetToken(const char*, BString &);
// state data
BString fServerName;
BNetEndpoint fSocket;
int32 fPort;
bool fConnected;
thread_id fThread;
State fState;
status_t fResult;
// state data
BString fServerName;
BNetEndpoint fSocket;
int32 fPort;
bool fConnected;
thread_id fThread;
State fState;
status_t fResult;
// disc information
CDDBData fCDData;
BString fFrameOffsetString;
scsi_toc fSCSIData;
// disc information
CDDBData fCDData;
BString fFrameOffsetString;
scsi_toc fSCSIData;
};
BString GetLineFromString(const char *string);
#endif
#endif // CDDBSUPPORT_H

View File

@ -1,13 +1,22 @@
/*
* Copyright (c) 2006-2007, Haiku, Inc.
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT license.
*
* Author:
* DarkWyrm <bpmagic@columbus.rr.com>
* DarkWyrm, bpmagic@columbus.rr.com
*/
#include "ButtonBitmaps.h"
#include "CDPlayer.h"
#include "DrawButton.h"
#include "DoubleShotDrawButton.h"
#include "TwoStateDrawButton.h"
#include <Alert.h>
#include <Application.h>
#include <Bitmap.h>
#include <BitmapStream.h>
#include <Box.h>
#include <Button.h>
#include <Debug.h>
@ -17,20 +26,14 @@
#include <MenuItem.h>
#include <PopUpMenu.h>
#include <Roster.h>
#include <TranslatorFormats.h>
#include <TranslatorRoster.h>
#include <TranslationUtils.h>
#include <Window.h>
#include <stdlib.h>
#include <string.h>
#include "ButtonBitmaps.h"
#include "CDPlayer.h"
#include "DrawButton.h"
#include "DoubleShotDrawButton.h"
#include "TwoStateDrawButton.h"
#include <TranslationUtils.h>
#include <TranslatorFormats.h>
#include <TranslatorRoster.h>
#include <BitmapStream.h>
enum {
M_STOP = 'mstp',
@ -47,46 +50,50 @@ enum {
M_SET_CD_TITLE
};
class CDPlayerWindow : public BWindow
{
public:
CDPlayerWindow(void);
bool QuitRequested(void);
class CDPlayerWindow : public BWindow {
public:
CDPlayerWindow();
bool QuitRequested();
};
inline void
SetLabel(BStringView *label, const char *text)
{
if (strcmp(label->Text(),text) != 0)
if (strcmp(label->Text(), text) != 0)
label->SetText(text);
}
// #pragma mark -
CDPlayer::CDPlayer(BRect frame, const char *name, uint32 resizeMask, uint32 flags)
: BView(frame, name, resizeMask, flags | B_FRAME_EVENTS),
: BView(frame, name, resizeMask, flags | B_FRAME_EVENTS),
fCDQuery("freedb.freedb.org")
{
SetViewColor(216,216,216);
fVolume = 255;
BuildGUI();
if (fCDDrive.CountDrives() < 1) {
BAlert *alert = new BAlert("CDPlayer","It appears that there are no CD drives"
BAlert *alert = new BAlert("CDPlayer", "It appears that there are no CD drives"
" on your computer or there is no system software"
" to support one. Sorry.","OK");
" to support one. Sorry.", "OK");
alert->Go();
be_app->PostMessage(B_QUIT_REQUESTED);
}
fWindowState = fCDDrive.GetState();
fVolumeSlider->SetValue(fCDDrive.GetVolume());
if (fVolumeSlider->Value() <= 2) {
fCDDrive.SetVolume(255);
fVolumeSlider->SetValue(255);
}
WatchCDState();
_WatchCDState();
}
@ -97,147 +104,143 @@ CDPlayer::~CDPlayer()
void
CDPlayer::BuildGUI(void)
CDPlayer::BuildGUI()
{
fStopColor.red = 80;
fStopColor.green = 164;
fStopColor.blue = 80;
fStopColor.alpha = 255;
fPlayColor.red = 40;
fPlayColor.green = 230;
fPlayColor.blue = 40;
fPlayColor.alpha = 255;
BRect r(Bounds().InsetByCopy(10,10));
BBox *box = new BBox(r,"",B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
BRect r(Bounds().InsetByCopy(10, 10));
BBox *box = new BBox(r, "", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
AddChild(box);
r = box->Bounds().InsetByCopy(10,10);
r = box->Bounds().InsetByCopy(10, 10);
r.bottom = 25;
float labelWidth, labelHeight;
fCDTitle = new BStringView(r,"CDTitle","CD drive is empty", B_FOLLOW_LEFT_RIGHT);
fCDTitle = new BStringView(r, "CDTitle", "CD drive is empty", B_FOLLOW_LEFT_RIGHT);
fCDTitle->GetPreferredSize(&labelWidth, &labelHeight);
fCDTitle->ResizeTo(r.Width(), labelHeight);
box->AddChild(fCDTitle);
r.bottom = r.top + labelHeight;
r.OffsetBy(0, r.Height() + 5);
fCurrentTrack = new BStringView(r,"TrackNumber","",B_FOLLOW_LEFT_RIGHT);
fCurrentTrack = new BStringView(r, "TrackNumber", "", B_FOLLOW_LEFT_RIGHT);
box->AddChild(fCurrentTrack);
r.OffsetBy(0, r.Height() + 5);
r.right = r.left + (r.Width() / 2);
fTrackTime = new BStringView(r,"TrackTime","Track: --:-- / --:--",B_FOLLOW_LEFT_RIGHT);
fTrackTime = new BStringView(r, "TrackTime", "Track: --:-- / --:--", B_FOLLOW_LEFT_RIGHT);
box->AddChild(fTrackTime);
r.OffsetTo(box->Bounds().right / 2, r.top);
fDiscTime = new BStringView(r,"DiscTime","Disc: --:-- / --:--",B_FOLLOW_RIGHT);
fDiscTime = new BStringView(r, "DiscTime", "Disc: --:-- / --:--", B_FOLLOW_RIGHT);
fDiscTime->ResizeToPreferred();
fDiscTime->ResizeBy(10,0);
fDiscTime->ResizeBy(10, 0);
box->AddChild(fDiscTime);
box->ResizeTo(fCDTitle->Frame().right + 5, fDiscTime->Frame().bottom + 10);
fStop = new DrawButton(BRect(0,0,1,1), "Stop",
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_down"),
new BMessage(M_STOP), B_FOLLOW_BOTTOM, B_WILL_DRAW);
fStop = new DrawButton(BRect(0, 0, 1, 1), "Stop",
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "stop_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "stop_down"),
new BMessage(M_STOP), B_FOLLOW_BOTTOM, B_WILL_DRAW);
fStop->ResizeToPreferred();
fStop->MoveTo(10, box->Frame().bottom + 15);
fStop->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_disabled"));
fStop->SetDisabled(BTranslationUtils::GetBitmap(B_PNG_FORMAT, "stop_disabled"));
AddChild(fStop);
float stopTop = fStop->Frame().top;
fPlay = new TwoStateDrawButton(BRect(0,0,1,1), "Play",
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up_on"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"),
new BMessage(M_PLAY), B_FOLLOW_NONE, B_WILL_DRAW);
fPlay = new TwoStateDrawButton(BRect(0, 0, 1, 1), "Play",
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_up_on"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"),
new BMessage(M_PLAY), B_FOLLOW_NONE, B_WILL_DRAW);
fPlay->ResizeToPreferred();
fPlay->MoveTo(fStop->Frame().right + 2, stopTop);
AddChild(fPlay);
fPrevTrack = new DrawButton(BRect(0,0,1,1), "PrevTrack",
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"prev_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"prev_down"),
new BMessage(M_PREV_TRACK), 0,
B_WILL_DRAW);
fPrevTrack = new DrawButton(BRect(0, 0, 1, 1), "PrevTrack",
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "prev_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "prev_down"),
new BMessage(M_PREV_TRACK), 0, B_WILL_DRAW);
fPrevTrack->ResizeToPreferred();
fPrevTrack->MoveTo(fPlay->Frame().right + 20, stopTop);
AddChild(fPrevTrack);
fNextTrack = new DrawButton(BRect(0,0,1,1), "NextTrack",
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"next_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"next_down"),
new BMessage(M_NEXT_TRACK), 0,
B_WILL_DRAW);
fNextTrack = new DrawButton(BRect(0, 0, 1, 1), "NextTrack",
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "next_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "next_down"),
new BMessage(M_NEXT_TRACK), 0, B_WILL_DRAW);
fNextTrack->ResizeToPreferred();
fNextTrack->MoveTo(fPrevTrack->Frame().right + 1, stopTop);
AddChild(fNextTrack);
fRewind = new DoubleShotDrawButton(BRect(0,0,1,1), "Rewind",
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_down"),
new BMessage(M_REWIND), 0, B_WILL_DRAW);
fRewind = new DoubleShotDrawButton(BRect(0, 0, 1, 1), "Rewind",
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "rew_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "rew_down"),
new BMessage(M_REWIND), 0, B_WILL_DRAW);
fRewind->ResizeToPreferred();
fRewind->MoveTo(fNextTrack->Frame().right + 20, stopTop);
AddChild(fRewind);
fFastFwd = new DoubleShotDrawButton(BRect(0,0,1,1), "FastFwd",
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_down"),
new BMessage(M_FFWD), 0, B_WILL_DRAW);
fFastFwd = new DoubleShotDrawButton(BRect(0, 0, 1, 1), "FastFwd",
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "ffwd_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "ffwd_down"),
new BMessage(M_FFWD), 0, B_WILL_DRAW);
fFastFwd->ResizeToPreferred();
fFastFwd->MoveTo(fRewind->Frame().right + 1, stopTop);
AddChild(fFastFwd);
r.left = 10;
r.right = fPlay->Frame().right;
r.top = fStop->Frame().bottom + 14;
r.bottom = r.top + kVolumeSliderBitmapHeight - 1.0;
fVolumeSlider = new VolumeSlider(r,"VolumeSlider",0,255, new BMessage(M_SET_VOLUME),
this);
fVolumeSlider = new VolumeSlider(r, "VolumeSlider",
0, 255, new BMessage(M_SET_VOLUME), this);
fVolumeSlider->ResizeToPreferred();
AddChild(fVolumeSlider);
fRepeat = new TwoStateDrawButton( BRect(0,0,1,1), "Repeat",
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_up_off"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_down"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_up_on"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_down"),
new BMessage(M_REPEAT), B_FOLLOW_NONE, B_WILL_DRAW);
fRepeat = new TwoStateDrawButton(BRect(0, 0, 1, 1), "Repeat",
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "repeat_up_off"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "repeat_down"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "repeat_up_on"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "repeat_down"),
new BMessage(M_REPEAT), B_FOLLOW_NONE, B_WILL_DRAW);
fRepeat->ResizeToPreferred();
fRepeat->MoveTo(fPrevTrack->Frame().left,
fVolumeSlider->Frame().top -
((fRepeat->Frame().Height() - fVolumeSlider->Frame().Height()) / 2));
fRepeat->MoveTo(fPrevTrack->Frame().left, fVolumeSlider->Frame().top -
((fRepeat->Frame().Height() - fVolumeSlider->Frame().Height()) / 2));
AddChild(fRepeat);
fShuffle = new TwoStateDrawButton(BRect(0,0,1,1), "Shuffle",
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_up_off"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_down"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_up_on"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_down"),
new BMessage(M_SHUFFLE), B_FOLLOW_NONE, B_WILL_DRAW);
fShuffle = new TwoStateDrawButton(BRect(0, 0, 1, 1), "Shuffle",
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "shuffle_up_off"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "shuffle_down"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "shuffle_up_on"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "shuffle_down"),
new BMessage(M_SHUFFLE), B_FOLLOW_NONE, B_WILL_DRAW);
fShuffle->ResizeToPreferred();
fShuffle->MoveTo(fRepeat->Frame().right + 2,fRepeat->Frame().top);
fShuffle->MoveTo(fRepeat->Frame().right + 2, fRepeat->Frame().top);
AddChild(fShuffle);
fEject = new DrawButton(BRect(0,0,1,1), "Eject",
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"eject_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"eject_down"),
new BMessage(M_EJECT), 0, B_WILL_DRAW);
fEject = new DrawButton(BRect(0, 0, 1, 1), "Eject",
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "eject_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "eject_down"),
new BMessage(M_EJECT), 0, B_WILL_DRAW);
fEject->ResizeToPreferred();
fEject->MoveTo(fFastFwd->Frame().left, fShuffle->Frame().top);
AddChild(fEject);
ResizeTo(box->Frame().right + 10, fVolumeSlider->Frame().bottom + 10);
ResizeTo(box->Frame().right + 10, fVolumeSlider->Frame().bottom + 10);
}
@ -245,44 +248,45 @@ void
CDPlayer::MessageReceived(BMessage *msg)
{
switch (msg->what) {
case M_SET_VOLUME: {
case M_SET_VOLUME:
fCDDrive.SetVolume(fVolumeSlider->Value());
break;
}
case M_STOP: {
case M_STOP:
if (fWindowState == kPaused) {
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"));
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"));
fPlay->SetState(1);
}
fWindowState = kStopped;
fCDDrive.Stop();
break;
}
case M_PLAY: {
case M_PLAY:
// If we are currently playing, then we will be showing
// the pause images and will want to switch back to the play images
if (fWindowState == kPlaying) {
fWindowState = kPaused;
fCDDrive.Pause();
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT,"paused_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"));
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT, "paused_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"));
} else if (fWindowState == kPaused) {
fWindowState = kPlaying;
fCDDrive.Resume();
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"));
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_up"),
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"));
} else {
fWindowState = kPlaying;
fCDDrive.Play(fPlayList.GetCurrentTrack());
}
break;
}
case M_EJECT: {
case M_EJECT:
fCDDrive.Eject();
break;
}
case M_NEXT_TRACK: {
case M_NEXT_TRACK:
{
int16 next = fPlayList.GetNextTrack();
if (next <= 0) {
// force a "wrap around" when possible. This makes it
@ -290,11 +294,11 @@ CDPlayer::MessageReceived(BMessage *msg)
// back to the first track from the last one with 1 button push
next = fPlayList.GetFirstTrack();
}
if (next > 0) {
CDState state = fCDDrive.GetState();
if (state == kPlaying) {
while(!fCDDrive.Play(next)) {
while (!fCDDrive.Play(next)) {
next = fPlayList.GetNextTrack();
if (next < 1) {
fWindowState = kStopped;
@ -312,11 +316,13 @@ CDPlayer::MessageReceived(BMessage *msg)
fPlayList.SetCurrentTrack(next);
// Force an update for better responsiveness
WatchCDState();
_WatchCDState();
}
break;
}
case M_PREV_TRACK: {
case M_PREV_TRACK:
{
int16 prev = fPlayList.GetPreviousTrack();
if (prev <= 0) {
// force a "wrap around" when possible. This makes it
@ -324,11 +330,11 @@ CDPlayer::MessageReceived(BMessage *msg)
// back to the first track from the last one with 1 button push
prev = fPlayList.GetLastTrack();
}
if (prev > 0) {
CDState state = fCDDrive.GetState();
if (state == kPlaying) {
while(!fCDDrive.Play(prev)) {
while (!fCDDrive.Play(prev)) {
prev = fPlayList.GetPreviousTrack();
if (prev < 1) {
fWindowState = kStopped;
@ -344,25 +350,26 @@ CDPlayer::MessageReceived(BMessage *msg)
fPlayList.SetCurrentTrack(prev);
// Force an update for better responsiveness
WatchCDState();
_WatchCDState();
}
break;
}
case M_FFWD: {
case M_FFWD:
if (fFastFwd->Value() == B_CONTROL_ON)
fCDDrive.StartFastFwd();
else
fCDDrive.StopFastFwd();
break;
}
case M_REWIND: {
case M_REWIND:
if (fRewind->Value() == B_CONTROL_ON)
fCDDrive.StartRewind();
else
fCDDrive.StopRewind();
break;
}
case M_SHUFFLE: {
case M_SHUFFLE:
if (fPlayList.IsShuffled()) {
int16 track = fPlayList.GetCurrentTrack();
fPlayList.SetShuffle(false);
@ -375,8 +382,8 @@ CDPlayer::MessageReceived(BMessage *msg)
fShuffle->SetState(1);
}
break;
}
case M_REPEAT: {
case M_REPEAT:
if (fPlayList.IsLoop()) {
fPlayList.SetLoop(false);
fRepeat->SetState(0);
@ -385,11 +392,11 @@ CDPlayer::MessageReceived(BMessage *msg)
fRepeat->SetState(1);
}
break;
}
default: {
default:
BView::MessageReceived(msg);
break;
}
}
}
@ -412,203 +419,206 @@ CDPlayer::AttachedToWindow()
void
CDPlayer::Pulse()
{
WatchCDState();
_WatchCDState();
}
void
CDPlayer::WatchCDState(void)
CDPlayer::_WatchCDState()
{
// One watcher function to rule them all
// first, watch the one setting independent of having a CD: volume
uint8 drivevolume = fCDDrive.GetVolume();
if (fVolume == drivevolume) {
fVolume = drivevolume;
uint8 driveVolume = fCDDrive.GetVolume();
if (fVolume == driveVolume) {
fVolume = driveVolume;
fVolumeSlider->SetValue(fVolume);
}
// Second, establish whether or not we have a CD in the drive
CDState playstate = fCDDrive.GetState();
bool internal_track_change = false;
if (playstate == kNoCD) {
CDState playState = fCDDrive.GetState();
bool internalTrackChange = false;
if (playState == kNoCD) {
// Yes, we have no bananas!
// Do something only if there is a change in the app's play state
if (fWindowState != kNoCD) {
// We have just discovered that we have no bananas
fWindowState = kNoCD;
// Because we are changing play states, we will need to update the GUI
fCDData.SetDiscID(-1);
SetLabel(fCDTitle,"CD drive is empty");
SetLabel(fCurrentTrack,"");
SetLabel(fTrackTime,"Track: --:-- / --:--");
SetLabel(fDiscTime,"Disc: --:-- / --:--");
SetLabel(fCDTitle, "CD drive is empty");
SetLabel(fCurrentTrack, "");
SetLabel(fTrackTime, "Track: --:-- / --:--");
SetLabel(fDiscTime, "Disc: --:-- / --:--");
fPlayList.SetTrackCount(0);
fPlayList.SetStartingTrack(1);
fPlayList.SetCurrentTrack(1);
if (fPlay->GetState() == 1)
fPlay->SetState(0);
}
return;
}
// Now otherwise handle the play state
if (playstate == kStopped) {
if (playState == kStopped) {
if (fWindowState == kPlaying) {
internal_track_change = true;
internalTrackChange = true;
// This means that the drive finished playing the song, so get the next one
// from the list and play it
int16 next = fPlayList.GetNextTrack();
if (next > 0)
fCDDrive.Play(next);
}
if (fPlay->GetState() == 1)
fPlay->SetState(0);
} else if (playstate == kPlaying) {
} else if (playState == kPlaying) {
if (fPlay->GetState() == 0)
fPlay->SetState(1);
} else if (playstate == kPaused) {
} else if (playState == kPaused)
fPlay->SetState(0);
}
// If we got this far, then there must be a CD in the drive. The next order on the agenda
// is to find out which CD it is
int32 discid = fCDDrive.GetDiscID();
bool update_track_gui = false;
if (discid != fCDData.DiscID()) {
update_track_gui = true;
int32 discId = fCDDrive.GetDiscID();
bool updateTrackGui = false;
if (discId != fCDData.DiscID()) {
updateTrackGui = true;
// Apparently the disc has changed since we last looked.
if (fCDQuery.CurrentDiscID() != discid)
if (fCDQuery.CurrentDiscID() != discId)
fCDQuery.SetToCD(fCDDrive.GetDrivePath());
if (fCDQuery.Ready()) {
// Note that we only update the CD title for now. We still need a track number
// in order to update the display for the selected track
if (fCDQuery.GetData(&fCDData, 1000000)) {
BString display(fCDData.Artist());
display << " - " << fCDData.Album();
SetLabel(fCDTitle,display.String());
} else {
SetLabel(fCDTitle,"Audio CD");
}
SetLabel(fCDTitle, display.String());
} else
SetLabel(fCDTitle, "Audio CD");
}
}
// Now that we know which CD it is, update the track info
int16 drivecount = fCDDrive.CountTracks();
int16 drivetrack = fCDDrive.GetTrack();
int16 playlisttrack = fPlayList.GetCurrentTrack();
int16 playlistcount = fPlayList.TrackCount();
if (playstate == kPlaying) {
if (playlisttrack != drivetrack) {
playlisttrack = drivetrack;
if (!internal_track_change) {
int16 driveCount = fCDDrive.CountTracks();
int16 driveTrack = fCDDrive.GetTrack();
int16 playlistTrack = fPlayList.GetCurrentTrack();
int16 playlistCount = fPlayList.TrackCount();
if (playState == kPlaying) {
if (playlistTrack != driveTrack) {
playlistTrack = driveTrack;
if (!internalTrackChange) {
// The main thing is that we need to make sure that the playlist and the drive's track
// stay in sync. The CD's track may have been changed by an outside source, so if
// the drive is playing, check for playlist sync.
fPlayList.SetTrackCount(drivecount);
fPlayList.SetCurrentTrack(drivetrack);
fPlayList.SetTrackCount(driveCount);
fPlayList.SetCurrentTrack(driveTrack);
}
}
update_track_gui = true;
updateTrackGui = true;
} else {
if (playlistcount != drivecount) {
if (playlistCount != driveCount) {
// This happens only when CDs are changed
if (drivecount < 0) {
if (driveCount < 0) {
// There is no CD in the drive. The playlist needs to have its track
// count set to 0 and it also needs to be rewound.
fPlayList.SetStartingTrack(1);
fPlayList.SetTrackCount(0);
playlisttrack = 1;
playlistcount = 0;
playlistTrack = 1;
playlistCount = 0;
} else {
// Two possible cases here: playlist is empty or playlist has a different
// number of tracks. In either case, the playlist needs to be reinitialized
// to the current track data
fPlayList.SetStartingTrack(1);
fPlayList.SetTrackCount(drivecount);
playlisttrack = fPlayList.GetCurrentTrack();
playlistcount = drivecount;
fPlayList.SetTrackCount(driveCount);
playlistTrack = fPlayList.GetCurrentTrack();
playlistCount = driveCount;
}
} else {
// update only with a track change
if (playlisttrack != drivetrack)
update_track_gui = true;
if (playlistTrack != driveTrack)
updateTrackGui = true;
}
}
if (update_track_gui) {
if (updateTrackGui) {
BString currentTrackName;
if (playlisttrack >= 0) {
int16 whichtrack = playlisttrack;
if (whichtrack == 0)
whichtrack++;
currentTrackName << "Track " << whichtrack << ": " << fCDData.TrackAt(whichtrack-1);
SetLabel(fCurrentTrack,currentTrackName.String());
} else {
SetLabel(fCurrentTrack,"");
}
if (playlistTrack >= 0) {
int16 whichTrack = playlistTrack;
if (whichTrack == 0)
whichTrack++;
currentTrackName << "Track " << whichTrack << ": " << fCDData.TrackAt(whichTrack - 1);
SetLabel(fCurrentTrack, currentTrackName.String());
} else
SetLabel(fCurrentTrack, "");
}
// Now update the time info
cdaudio_time tracktime;
cdaudio_time disctime;
cdaudio_time tracktotal;
cdaudio_time disctotal;
char timestring[1024];
if (fCDDrive.GetTime(tracktime, disctime)) {
fCDDrive.GetTimeForDisc(disctotal);
sprintf(timestring,"Disc: %ld:%.2ld / %ld:%.2ld",disctime.minutes,disctime.seconds,
disctotal.minutes,disctotal.seconds);
SetLabel(fDiscTime,timestring);
fCDDrive.GetTimeForTrack(playlisttrack,tracktotal);
sprintf(timestring,"Track: %ld:%.2ld / %ld:%.2ld",tracktime.minutes,tracktime.seconds,
tracktotal.minutes,tracktotal.seconds);
SetLabel(fTrackTime,timestring);
CDAudioTime trackTime;
CDAudioTime discTime;
CDAudioTime trackTotal;
CDAudioTime discTotal;
char timeString[1024];
if (fCDDrive.GetTime(trackTime, discTime)) {
fCDDrive.GetTimeForDisc(discTotal);
sprintf(timeString, "Disc: %ld:%.2ld / %ld:%.2ld", discTime.GetMinutes(),
discTime.GetSeconds(), discTotal.GetMinutes(), discTotal.GetSeconds());
SetLabel(fDiscTime, timeString);
fCDDrive.GetTimeForTrack(playlistTrack, trackTotal);
sprintf(timeString, "Track: %ld:%.2ld / %ld:%.2ld", trackTime.GetMinutes(),
trackTime.GetSeconds(), trackTotal.GetMinutes(), trackTotal.GetSeconds());
SetLabel(fTrackTime, timeString);
} else {
SetLabel(fTrackTime,"Track: --:-- / --:--");
SetLabel(fDiscTime,"Disc: --:-- / --:--");
SetLabel(fTrackTime, "Track: --:-- / --:--");
SetLabel(fDiscTime, "Disc: --:-- / --:--");
}
}
CDPlayerWindow::CDPlayerWindow(void)
: BWindow(BRect (100, 100, 405, 280), "CD Player", B_TITLED_WINDOW, B_NOT_RESIZABLE |
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
// #pragma mark -
CDPlayerWindow::CDPlayerWindow()
: BWindow(BRect (100, 100, 405, 280), "CD Player", B_TITLED_WINDOW, B_NOT_RESIZABLE |
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
{
}
bool
CDPlayerWindow::QuitRequested(void)
CDPlayerWindow::QuitRequested()
{
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}
// #pragma mark -
CDPlayerApplication::CDPlayerApplication()
: BApplication("application/x-vnd.Haiku-CDPlayer")
: BApplication("application/x-vnd.Haiku-CDPlayer")
{
BWindow *window = new CDPlayerWindow();
BView *view = new CDPlayer(window->Bounds(), "CD");

View File

@ -7,84 +7,81 @@
#ifndef CDPLAYER_H
#define CDPLAYER_H
#include <Application.h>
#include <View.h>
#include <Window.h>
#include <View.h>
#include <Button.h>
#include <TextControl.h>
#include <StringView.h>
#include "CDAudioDevice.h"
#include "CDDBSupport.h"
#include "PlayList.h"
#include "VolumeSlider.h"
#include <Application.h>
#include <Button.h>
#include <StringView.h>
#include <TextControl.h>
#include <View.h>
#include <Window.h>
class DrawButton;
class DoubleShotDrawButton;
class TwoStateDrawButton;
class CDPlayer : public BView
{
public:
CDPlayer(BRect frame, const char *name,
uint32 resizeMask = B_FOLLOW_ALL,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE |
B_PULSE_NEEDED);
virtual ~CDPlayer();
void BuildGUI(void);
virtual void AttachedToWindow();
virtual void Pulse();
virtual void MessageReceived(BMessage *);
private:
void WatchCDState(void);
DrawButton *fStop,
*fNextTrack,
*fPrevTrack,
*fEject;
DoubleShotDrawButton
*fFastFwd,
*fRewind;
TwoStateDrawButton *fShuffle,
*fRepeat,
*fPlay;
VolumeSlider *fVolumeSlider;
BStringView *fCDTitle,
*fCurrentTrack,
*fTrackTime,
*fDiscTime;
BBox *fCDBox,
*fTrackBox,
*fTimeBox;
CDState fCDState;
rgb_color fStopColor;
rgb_color fPlayColor;
CDAudioDevice fCDDrive;
PlayList fPlayList;
CDState fWindowState;
CDDBQuery fCDQuery;
CDDBData fCDData;
uint8 fVolume;
class CDPlayer : public BView {
public:
CDPlayer(BRect frame, const char *name, uint32 resizeMask = B_FOLLOW_ALL,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_PULSE_NEEDED);
virtual ~CDPlayer();
void BuildGUI();
virtual void AttachedToWindow();
virtual void Pulse();
virtual void MessageReceived(BMessage *);
private:
void _WatchCDState();
DrawButton *fStop,
*fNextTrack,
*fPrevTrack,
*fEject;
DoubleShotDrawButton
*fFastFwd,
*fRewind;
TwoStateDrawButton *fShuffle,
*fRepeat,
*fPlay;
VolumeSlider *fVolumeSlider;
BStringView *fCDTitle,
*fCurrentTrack,
*fTrackTime,
*fDiscTime;
BBox *fCDBox,
*fTrackBox,
*fTimeBox;
CDState fCDState;
rgb_color fStopColor;
rgb_color fPlayColor;
CDAudioDevice fCDDrive;
PlayList fPlayList;
CDState fWindowState;
CDDBQuery fCDQuery;
CDDBData fCDData;
uint8 fVolume;
};
class CDPlayerApplication : public BApplication
{
public:
CDPlayerApplication();
class CDPlayerApplication : public BApplication {
public:
CDPlayerApplication();
};
#endif
#endif // CDPLAYER_H