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:
@@ -15,6 +15,7 @@
|
|||||||
#ifndef BUTTON_BITMAPS_H
|
#ifndef BUTTON_BITMAPS_H
|
||||||
#define BUTTON_BITMAPS_H
|
#define BUTTON_BITMAPS_H
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
// #pragma mark play
|
// #pragma mark play
|
||||||
|
|
||||||
|
|||||||
+130
-117
@@ -1,127 +1,163 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2007, Haiku, Inc.
|
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
*
|
*
|
||||||
* Author:
|
* Author:
|
||||||
* DarkWyrm <bpmagic@columbus.rr.com>
|
* DarkWyrm, bpmagic@columbus.rr.com
|
||||||
*/
|
*/
|
||||||
#include "CDAudioDevice.h"
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdio.h>
|
#include "CDAudioDevice.h"
|
||||||
#include <stdlib.h>
|
#include "scsi.h"
|
||||||
#include <String.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include "scsi.h"
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
cdaudio_data::cdaudio_data(const int32 &id, const int32 &count,
|
struct ConvertedToc {
|
||||||
const int32 &disclength)
|
int32 min;
|
||||||
: disc_id(id),
|
int32 sec;
|
||||||
track_count(count),
|
int32 frame;
|
||||||
length(disclength)
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static int32
|
||||||
|
cddb_sum(int n)
|
||||||
|
{
|
||||||
|
char buf[12];
|
||||||
|
int32 ret = 0;
|
||||||
|
|
||||||
|
sprintf(buf, "%u", n);
|
||||||
|
for (const char *p = buf; *p != '\0'; p++)
|
||||||
|
ret += (*p - '0');
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
CDAudioData::CDAudioData(const int32 &id, const int32 &count, const int32 &discLength)
|
||||||
|
:
|
||||||
|
fDiscId(id),
|
||||||
|
fTrackCount(count),
|
||||||
|
fLength(discLength)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cdaudio_data::cdaudio_data(const cdaudio_data &from)
|
CDAudioData::CDAudioData(const CDAudioData &from)
|
||||||
: disc_id(from.disc_id),
|
:
|
||||||
track_count(from.track_count),
|
fDiscId(from.fDiscId),
|
||||||
length(from.length)
|
fTrackCount(from.fTrackCount),
|
||||||
|
fLength(from.fLength)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cdaudio_data &
|
CDAudioData &
|
||||||
cdaudio_data::operator=(const cdaudio_data &from)
|
CDAudioData::operator=(const CDAudioData &from)
|
||||||
{
|
{
|
||||||
disc_id = from.disc_id;
|
fDiscId = from.fDiscId;
|
||||||
track_count = from.track_count;
|
fTrackCount = from.fTrackCount;
|
||||||
length = from.length;
|
fLength = from.fLength;
|
||||||
frame_offsets = from.frame_offsets;
|
fFrameOffsets = from.fFrameOffsets;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cdaudio_time::cdaudio_time(const int32 min,const int32 &sec)
|
// #pragma mark -
|
||||||
: minutes(min),
|
|
||||||
seconds(sec)
|
|
||||||
|
CDAudioTime::CDAudioTime(const int32 min,const int32 &sec)
|
||||||
|
:
|
||||||
|
fMinutes(min),
|
||||||
|
fSeconds(sec)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cdaudio_time::cdaudio_time(const cdaudio_time &from)
|
CDAudioTime::CDAudioTime(const CDAudioTime &from)
|
||||||
: minutes(from.minutes),
|
:
|
||||||
seconds(from.seconds)
|
fMinutes(from.fMinutes),
|
||||||
|
fSeconds(from.fSeconds)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cdaudio_time &
|
CDAudioTime &
|
||||||
cdaudio_time::operator=(const cdaudio_time &from)
|
CDAudioTime::operator=(const CDAudioTime &from)
|
||||||
{
|
{
|
||||||
minutes = from.minutes;
|
fMinutes = from.fMinutes;
|
||||||
seconds = from.seconds;
|
fSeconds = from.fSeconds;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cdaudio_time
|
CDAudioTime
|
||||||
cdaudio_time::operator+(const cdaudio_time &from)
|
CDAudioTime::operator+(const CDAudioTime &from)
|
||||||
{
|
{
|
||||||
cdaudio_time time;
|
CDAudioTime time;
|
||||||
|
|
||||||
time.minutes = minutes + from.minutes;
|
time.fMinutes = fMinutes + from.fMinutes;
|
||||||
time.seconds = seconds + from.seconds;
|
time.fSeconds = fSeconds + from.fSeconds;
|
||||||
|
|
||||||
while (time.seconds > 59) {
|
while (time.fSeconds > 59) {
|
||||||
time.minutes++;
|
time.fMinutes++;
|
||||||
time.seconds-=60;
|
time.fSeconds -= 60;
|
||||||
}
|
}
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cdaudio_time
|
CDAudioTime
|
||||||
cdaudio_time::operator-(const cdaudio_time &from)
|
CDAudioTime::operator-(const CDAudioTime &from)
|
||||||
{
|
{
|
||||||
cdaudio_time time;
|
CDAudioTime time;
|
||||||
|
|
||||||
int32 tsec = ((minutes * 60) + seconds) - ((from.minutes * 60) + from.seconds);
|
int32 tsec = ((fMinutes * 60) + fSeconds) - ((from.fMinutes * 60) + from.fSeconds);
|
||||||
if (tsec < 0) {
|
if (tsec < 0) {
|
||||||
time.minutes = 0;
|
time.fMinutes = 0;
|
||||||
time.seconds = 0;
|
time.fSeconds = 0;
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
time.minutes = tsec / 60;
|
time.fMinutes = tsec / 60;
|
||||||
time.seconds = tsec % 60;
|
time.fSeconds = tsec % 60;
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CDAudioDevice::CDAudioDevice(void)
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
CDAudioDevice::CDAudioDevice()
|
||||||
{
|
{
|
||||||
FindDrives("/dev/disk");
|
_FindDrives("/dev/disk");
|
||||||
if (CountDrives() > 0)
|
if (CountDrives() > 0)
|
||||||
SetDrive(0);
|
SetDrive(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CDAudioDevice::~CDAudioDevice(void)
|
CDAudioDevice::~CDAudioDevice()
|
||||||
{
|
{
|
||||||
for (int32 i = 0; i < fDriveList.CountItems(); i++)
|
for (int32 i = 0; i < fDriveList.CountItems(); i++)
|
||||||
delete (BString*) fDriveList.ItemAt(i);
|
delete (BString*) fDriveList.ItemAt(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This plays only one track - the track specified
|
|
||||||
|
//! This plays only one track - the track specified
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::Play(const int16 &track)
|
CDAudioDevice::Play(const int16 &track)
|
||||||
{
|
{
|
||||||
@@ -149,7 +185,7 @@ CDAudioDevice::Play(const int16 &track)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::Pause(void)
|
CDAudioDevice::Pause()
|
||||||
{
|
{
|
||||||
status_t result = ioctl(fFileHandle, B_SCSI_PAUSE_AUDIO);
|
status_t result = ioctl(fFileHandle, B_SCSI_PAUSE_AUDIO);
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
@@ -161,7 +197,7 @@ CDAudioDevice::Pause(void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::Resume(void)
|
CDAudioDevice::Resume()
|
||||||
{
|
{
|
||||||
CDState state = GetState();
|
CDState state = GetState();
|
||||||
if (state == kNoCD) {
|
if (state == kNoCD) {
|
||||||
@@ -183,7 +219,7 @@ CDAudioDevice::Resume(void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::Stop(void)
|
CDAudioDevice::Stop()
|
||||||
{
|
{
|
||||||
status_t result = ioctl(fFileHandle, B_SCSI_STOP_AUDIO);
|
status_t result = ioctl(fFileHandle, B_SCSI_STOP_AUDIO);
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
@@ -194,9 +230,9 @@ CDAudioDevice::Stop(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// open or close the CD tray
|
//! Open or close the CD tray
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::Eject(void)
|
CDAudioDevice::Eject()
|
||||||
{
|
{
|
||||||
status_t media_status = B_DEV_NO_MEDIA;
|
status_t media_status = B_DEV_NO_MEDIA;
|
||||||
|
|
||||||
@@ -205,8 +241,7 @@ CDAudioDevice::Eject(void)
|
|||||||
|
|
||||||
// if door open, load the media, else eject the CD
|
// if door open, load the media, else eject the CD
|
||||||
status_t result = ioctl(fFileHandle,
|
status_t result = ioctl(fFileHandle,
|
||||||
media_status == B_DEV_DOOR_OPEN ?
|
media_status == B_DEV_DOOR_OPEN ? B_LOAD_MEDIA : B_EJECT_DEVICE);
|
||||||
B_LOAD_MEDIA : B_EJECT_DEVICE);
|
|
||||||
|
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
printf("Couldn't eject CD: %s\n", strerror(errno));
|
printf("Couldn't eject CD: %s\n", strerror(errno));
|
||||||
@@ -217,7 +252,7 @@ CDAudioDevice::Eject(void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::StartFastFwd(void)
|
CDAudioDevice::StartFastFwd()
|
||||||
{
|
{
|
||||||
scsi_scan scan;
|
scsi_scan scan;
|
||||||
scan.direction = 1;
|
scan.direction = 1;
|
||||||
@@ -232,7 +267,7 @@ CDAudioDevice::StartFastFwd(void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::StopFastFwd(void)
|
CDAudioDevice::StopFastFwd()
|
||||||
{
|
{
|
||||||
scsi_scan scan;
|
scsi_scan scan;
|
||||||
scan.direction = 0;
|
scan.direction = 0;
|
||||||
@@ -247,7 +282,7 @@ CDAudioDevice::StopFastFwd(void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::StartRewind(void)
|
CDAudioDevice::StartRewind()
|
||||||
{
|
{
|
||||||
scsi_scan scan;
|
scsi_scan scan;
|
||||||
scan.direction = -1;
|
scan.direction = -1;
|
||||||
@@ -262,7 +297,7 @@ CDAudioDevice::StartRewind(void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::StopRewind(void)
|
CDAudioDevice::StopRewind()
|
||||||
{
|
{
|
||||||
scsi_scan scan;
|
scsi_scan scan;
|
||||||
scan.direction = 0;
|
scan.direction = 0;
|
||||||
@@ -282,10 +317,10 @@ CDAudioDevice::SetVolume(uint8 value)
|
|||||||
scsi_volume vol;
|
scsi_volume vol;
|
||||||
|
|
||||||
// change only port0's volume
|
// change only port0's volume
|
||||||
vol.flags=2;
|
vol.flags = 2;
|
||||||
vol.port0_volume=value;
|
vol.port0_volume = value;
|
||||||
|
|
||||||
status_t result = ioctl(fFileHandle,B_SCSI_SET_VOLUME,&vol);
|
status_t result = ioctl(fFileHandle, B_SCSI_SET_VOLUME, &vol);
|
||||||
if (result != B_OK) {
|
if (result != B_OK) {
|
||||||
printf("Couldn't set volume: %s\n", strerror(errno));
|
printf("Couldn't set volume: %s\n", strerror(errno));
|
||||||
return false;
|
return false;
|
||||||
@@ -295,7 +330,7 @@ CDAudioDevice::SetVolume(uint8 value)
|
|||||||
|
|
||||||
|
|
||||||
uint8
|
uint8
|
||||||
CDAudioDevice::GetVolume(void)
|
CDAudioDevice::GetVolume()
|
||||||
{
|
{
|
||||||
scsi_volume vol;
|
scsi_volume vol;
|
||||||
ioctl(fFileHandle, B_SCSI_GET_VOLUME, &vol);
|
ioctl(fFileHandle, B_SCSI_GET_VOLUME, &vol);
|
||||||
@@ -303,9 +338,9 @@ CDAudioDevice::GetVolume(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// check the current CD play state
|
//! Check the current CD play state
|
||||||
CDState
|
CDState
|
||||||
CDAudioDevice::GetState(void)
|
CDAudioDevice::GetState()
|
||||||
{
|
{
|
||||||
scsi_position pos;
|
scsi_position pos;
|
||||||
status_t media_status = B_DEV_NO_MEDIA;
|
status_t media_status = B_DEV_NO_MEDIA;
|
||||||
@@ -328,7 +363,7 @@ CDAudioDevice::GetState(void)
|
|||||||
|
|
||||||
|
|
||||||
int16
|
int16
|
||||||
CDAudioDevice::CountTracks(void)
|
CDAudioDevice::CountTracks()
|
||||||
{
|
{
|
||||||
scsi_toc toc;
|
scsi_toc toc;
|
||||||
status_t result = ioctl(fFileHandle, B_SCSI_GET_TOC, &toc);
|
status_t result = ioctl(fFileHandle, B_SCSI_GET_TOC, &toc);
|
||||||
@@ -340,9 +375,9 @@ CDAudioDevice::CountTracks(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get the 0-based index of the current track
|
//! Get the 0-based index of the current track
|
||||||
int16
|
int16
|
||||||
CDAudioDevice::GetTrack(void)
|
CDAudioDevice::GetTrack()
|
||||||
{
|
{
|
||||||
scsi_position pos;
|
scsi_position pos;
|
||||||
|
|
||||||
@@ -365,7 +400,7 @@ CDAudioDevice::GetTrack(void)
|
|||||||
|
|
||||||
|
|
||||||
uint8
|
uint8
|
||||||
CDAudioDevice::CountDrives(void)
|
CDAudioDevice::CountDrives()
|
||||||
{
|
{
|
||||||
return fDriveList.CountItems();
|
return fDriveList.CountItems();
|
||||||
}
|
}
|
||||||
@@ -392,7 +427,7 @@ CDAudioDevice::SetDrive(const int32 &drive)
|
|||||||
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
CDAudioDevice::GetDrivePath(void) const
|
CDAudioDevice::GetDrivePath() const
|
||||||
{
|
{
|
||||||
if (!fDrivePath)
|
if (!fDrivePath)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -402,7 +437,7 @@ CDAudioDevice::GetDrivePath(void) const
|
|||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
CDAudioDevice::FindDrives(const char *path)
|
CDAudioDevice::_FindDrives(const char *path)
|
||||||
{
|
{
|
||||||
BDirectory dir(path);
|
BDirectory dir(path);
|
||||||
|
|
||||||
@@ -428,14 +463,13 @@ CDAudioDevice::FindDrives(const char *path)
|
|||||||
// ignore floppy -- it is not silent
|
// ignore floppy -- it is not silent
|
||||||
if (strcmp(e.name, "floppy") == 0)
|
if (strcmp(e.name, "floppy") == 0)
|
||||||
continue;
|
continue;
|
||||||
else
|
else if (strcmp(e.name, "ata") == 0)
|
||||||
if (strcmp(e.name, "ata") == 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Note that if we check for the count here, we could
|
// Note that if we check for the count here, we could
|
||||||
// just search for one drive. However, we want to find *all* drives
|
// just search for one drive. However, we want to find *all* drives
|
||||||
// that are available, so we keep searching even if we've found one
|
// that are available, so we keep searching even if we've found one
|
||||||
FindDrives(name);
|
_FindDrives(name);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
int devfd;
|
int devfd;
|
||||||
@@ -461,7 +495,7 @@ CDAudioDevice::FindDrives(const char *path)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::GetTime(cdaudio_time &track, cdaudio_time &disc)
|
CDAudioDevice::GetTime(CDAudioTime &track, CDAudioTime &disc)
|
||||||
{
|
{
|
||||||
scsi_position pos;
|
scsi_position pos;
|
||||||
|
|
||||||
@@ -482,16 +516,16 @@ CDAudioDevice::GetTime(cdaudio_time &track, cdaudio_time &disc)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
disc.minutes = pos.position[9];
|
disc.SetMinutes(pos.position[9]);
|
||||||
disc.seconds = pos.position[10];
|
disc.SetSeconds(pos.position[10]);
|
||||||
track.minutes = pos.position[13];
|
track.SetMinutes(pos.position[13]);
|
||||||
track.seconds = pos.position[14];
|
track.SetSeconds(pos.position[14]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::GetTimeForTrack(const int16 &index, cdaudio_time &track)
|
CDAudioDevice::GetTimeForTrack(const int16 &index, CDAudioTime &track)
|
||||||
{
|
{
|
||||||
scsi_toc toc;
|
scsi_toc toc;
|
||||||
status_t result = ioctl(fFileHandle, B_SCSI_GET_TOC, &toc);
|
status_t result = ioctl(fFileHandle, B_SCSI_GET_TOC, &toc);
|
||||||
@@ -508,16 +542,16 @@ CDAudioDevice::GetTimeForTrack(const int16 &index, cdaudio_time &track)
|
|||||||
|
|
||||||
int32 tracktime = (desc[index].min * 60) + desc[index].sec;
|
int32 tracktime = (desc[index].min * 60) + desc[index].sec;
|
||||||
|
|
||||||
tracktime -= (desc[index-1].min * 60) + desc[index-1].sec;
|
tracktime -= (desc[index - 1].min * 60) + desc[index - 1].sec;
|
||||||
track.minutes = tracktime / 60;
|
track.SetMinutes(tracktime / 60);
|
||||||
track.seconds = tracktime % 60;
|
track.SetSeconds(tracktime % 60);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDAudioDevice::GetTimeForDisc(cdaudio_time &disc)
|
CDAudioDevice::GetTimeForDisc(CDAudioTime &disc)
|
||||||
{
|
{
|
||||||
scsi_toc toc;
|
scsi_toc toc;
|
||||||
status_t result = ioctl(fFileHandle, B_SCSI_GET_TOC, &toc);
|
status_t result = ioctl(fFileHandle, B_SCSI_GET_TOC, &toc);
|
||||||
@@ -528,35 +562,15 @@ CDAudioDevice::GetTimeForDisc(cdaudio_time &disc)
|
|||||||
int16 trackcount = toc.toc_data[3] - toc.toc_data[2] + 1;
|
int16 trackcount = toc.toc_data[3] - toc.toc_data[2] + 1;
|
||||||
TrackDescriptor *desc = (TrackDescriptor*)&(toc.toc_data[4]);
|
TrackDescriptor *desc = (TrackDescriptor*)&(toc.toc_data[4]);
|
||||||
|
|
||||||
disc.minutes = desc[trackcount].min;
|
disc.SetMinutes(desc[trackcount].min);
|
||||||
disc.seconds = desc[trackcount].sec;
|
disc.SetSeconds(desc[trackcount].sec);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct ConvertedToc {
|
|
||||||
int32 min;
|
|
||||||
int32 sec;
|
|
||||||
int32 frame;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static int32
|
|
||||||
cddb_sum(int n)
|
|
||||||
{
|
|
||||||
char buf[12];
|
|
||||||
int32 ret = 0;
|
|
||||||
|
|
||||||
sprintf(buf, "%u", n);
|
|
||||||
for (const char *p = buf; *p != '\0'; p++)
|
|
||||||
ret += (*p - '0');
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
CDAudioDevice::GetDiscID(void)
|
CDAudioDevice::GetDiscID()
|
||||||
{
|
{
|
||||||
// Read the disc
|
// Read the disc
|
||||||
scsi_toc toc;
|
scsi_toc toc;
|
||||||
@@ -573,9 +587,9 @@ CDAudioDevice::GetDiscID(void)
|
|||||||
|
|
||||||
// figure out the disc ID
|
// figure out the disc ID
|
||||||
for (int index = 0; index < 100; index++) {
|
for (int index = 0; index < 100; index++) {
|
||||||
tocData[index].min = toc.toc_data[9 + 8*index];
|
tocData[index].min = toc.toc_data[9 + 8 * index];
|
||||||
tocData[index].sec = toc.toc_data[10 + 8*index];
|
tocData[index].sec = toc.toc_data[10 + 8 * index];
|
||||||
tocData[index].frame = toc.toc_data[11 + 8*index];
|
tocData[index].frame = toc.toc_data[11 + 8 * index];
|
||||||
}
|
}
|
||||||
numTracks = toc.toc_data[3] - toc.toc_data[2] + 1;
|
numTracks = toc.toc_data[3] - toc.toc_data[2] + 1;
|
||||||
|
|
||||||
@@ -614,4 +628,3 @@ CDAudioDevice::IsDataTrack(const int16 &track)
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,22 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2007, Haiku, Inc.
|
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT license.
|
* Distributed under the terms of the MIT license.
|
||||||
*
|
*
|
||||||
* Author:
|
* Author:
|
||||||
* DarkWyrm <bpmagic@columbus.rr.com>
|
* DarkWyrm, bpmagic@columbus.rr.com
|
||||||
*/
|
*/
|
||||||
#ifndef CDAUDIODEVICE_H
|
#ifndef CDAUDIODEVICE_H
|
||||||
#define CDAUDIODEVICE_H
|
#define CDAUDIODEVICE_H
|
||||||
|
|
||||||
#include <SupportDefs.h>
|
|
||||||
#include <String.h>
|
|
||||||
#include <List.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
|
// 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
|
// 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
|
// 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 {
|
typedef struct {
|
||||||
uint8 reserved;
|
uint8 reserved;
|
||||||
uint8 adr_control; // bytes 0-3 are control, 4-7 are ADR
|
uint8 adr_control; // bytes 0-3 are control, 4-7 are ADR
|
||||||
@@ -29,7 +30,7 @@ typedef struct {
|
|||||||
} TrackDescriptor;
|
} TrackDescriptor;
|
||||||
|
|
||||||
enum CDState {
|
enum CDState {
|
||||||
kNoCD=0,
|
kNoCD = 0,
|
||||||
kStopped,
|
kStopped,
|
||||||
kPaused,
|
kPaused,
|
||||||
kPlaying,
|
kPlaying,
|
||||||
@@ -38,79 +39,104 @@ enum CDState {
|
|||||||
kInit
|
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;
|
class CDAudioTime {
|
||||||
int32 seconds;
|
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;
|
class CDAudioData {
|
||||||
int32 track_count;
|
public:
|
||||||
int32 length;
|
CDAudioData(const int32 &id = -1, const int32 &count = -1,
|
||||||
|
const int32 &discLength = -1);
|
||||||
|
CDAudioData(const CDAudioData &from);
|
||||||
|
CDAudioData &operator=(const CDAudioData &from);
|
||||||
|
|
||||||
BString frame_offsets;
|
private:
|
||||||
|
int32 fDiscId;
|
||||||
|
int32 fTrackCount;
|
||||||
|
int32 fLength;
|
||||||
|
BString fFrameOffsets;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CDAudioDevice
|
|
||||||
{
|
class CDAudioDevice {
|
||||||
public:
|
public:
|
||||||
CDAudioDevice(void);
|
CDAudioDevice();
|
||||||
~CDAudioDevice(void);
|
~CDAudioDevice();
|
||||||
|
|
||||||
bool Play(const int16 &track);
|
bool Play(const int16 &track);
|
||||||
bool Pause(void);
|
bool Pause();
|
||||||
bool Resume(void);
|
bool Resume();
|
||||||
bool Stop(void);
|
bool Stop();
|
||||||
bool Eject(void);
|
bool Eject();
|
||||||
|
|
||||||
bool StartFastFwd(void);
|
bool StartFastFwd();
|
||||||
bool StopFastFwd(void);
|
bool StopFastFwd();
|
||||||
|
|
||||||
bool StartRewind(void);
|
bool StartRewind();
|
||||||
bool StopRewind(void);
|
bool StopRewind();
|
||||||
|
|
||||||
bool SetVolume(uint8 value);
|
bool SetVolume(uint8 value);
|
||||||
uint8 GetVolume(void);
|
uint8 GetVolume();
|
||||||
|
|
||||||
CDState GetState(void);
|
CDState GetState();
|
||||||
|
|
||||||
int16 CountTracks(void);
|
int16 CountTracks();
|
||||||
int16 GetTrack(void);
|
int16 GetTrack();
|
||||||
|
|
||||||
uint8 CountDrives(void);
|
uint8 CountDrives();
|
||||||
bool SetDrive(const int32 &drive);
|
bool SetDrive(const int32 &drive);
|
||||||
const char * GetDrivePath(void) const;
|
const char* GetDrivePath() const;
|
||||||
int32 GetDrive(void) const { return fDriveIndex; }
|
|
||||||
|
|
||||||
bool GetTime(cdaudio_time &track, cdaudio_time &disc);
|
int32 GetDrive() const
|
||||||
bool GetTimeForTrack(const int16 &index, cdaudio_time &track);
|
{
|
||||||
bool GetTimeForDisc(cdaudio_time &disc);
|
return fDriveIndex;
|
||||||
int32 GetDiscID(void);
|
}
|
||||||
|
|
||||||
|
bool GetTime(CDAudioTime &track, CDAudioTime &disc);
|
||||||
|
bool GetTimeForTrack(const int16 &index, CDAudioTime &track);
|
||||||
|
bool GetTimeForDisc(CDAudioTime &disc);
|
||||||
|
int32 GetDiscID();
|
||||||
|
|
||||||
bool IsDataTrack(const int16 &track);
|
bool IsDataTrack(const int16 &track);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 FindDrives(const char *path);
|
int32 _FindDrives(const char *path);
|
||||||
|
|
||||||
int fFileHandle;
|
int fFileHandle;
|
||||||
BString * fDrivePath;
|
BString* fDrivePath;
|
||||||
BList fDriveList;
|
BList fDriveList;
|
||||||
int32 fDriveIndex;
|
int32 fDriveIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // CDAUDIODEVICE_H
|
||||||
|
|||||||
+224
-180
@@ -6,27 +6,28 @@
|
|||||||
|
|
||||||
#include "CDDBSupport.h"
|
#include "CDDBSupport.h"
|
||||||
|
|
||||||
#include <Debug.h>
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
|
#include <Debug.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <NetAddress.h>
|
|
||||||
#include <fs_attr.h>
|
#include <fs_attr.h>
|
||||||
|
#include <fs_index.h>
|
||||||
|
#include <NetAddress.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
#include <Query.h>
|
#include <Query.h>
|
||||||
|
#include <UTF8.h>
|
||||||
#include <Volume.h>
|
#include <Volume.h>
|
||||||
#include <VolumeRoster.h>
|
#include <VolumeRoster.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fs_index.h>
|
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <UTF8.h>
|
|
||||||
|
|
||||||
//#define DEBUG_CDDB
|
//#define DEBUG_CDDB
|
||||||
|
|
||||||
@@ -51,56 +52,97 @@ typedef struct TrackRecord {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CDDBData::CDDBData(int32 discid)
|
static void
|
||||||
: fDiscID(discid),
|
DoNothing(int)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int32
|
||||||
|
cddb_sum(int n)
|
||||||
|
{
|
||||||
|
char buf[12];
|
||||||
|
int32 ret = 0;
|
||||||
|
|
||||||
|
sprintf(buf, "%u", n);
|
||||||
|
for (const char *p = buf; *p != '\0'; p++)
|
||||||
|
ret += (*p - '0');
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BString
|
||||||
|
GetLineFromString(const char *string)
|
||||||
|
{
|
||||||
|
if (!string)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
BString out(string);
|
||||||
|
|
||||||
|
int32 lineFeed = out.FindFirst("\n");
|
||||||
|
|
||||||
|
if (lineFeed > 0)
|
||||||
|
out.Truncate(lineFeed);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
CDDBData::CDDBData(int32 discId)
|
||||||
|
:
|
||||||
|
fDiscID(discId),
|
||||||
fYear(-1)
|
fYear(-1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CDDBData::CDDBData(const CDDBData &from)
|
CDDBData::CDDBData(const CDDBData &from)
|
||||||
: fDiscID(from.fDiscID),
|
:
|
||||||
|
fDiscID(from.fDiscID),
|
||||||
fArtist(from.fArtist),
|
fArtist(from.fArtist),
|
||||||
fAlbum(from.fAlbum),
|
fAlbum(from.fAlbum),
|
||||||
fGenre(from.fGenre),
|
fGenre(from.fGenre),
|
||||||
fDiscTime(from.fDiscTime),
|
fDiscTime(from.fDiscTime),
|
||||||
fYear(fYear)
|
fYear(from.fYear)
|
||||||
{
|
{
|
||||||
STRACE(("CDDBData::Copy Constructor\n"));
|
STRACE(("CDDBData::Copy Constructor\n"));
|
||||||
|
|
||||||
for (int32 i = 0; i < from.fTrackList.CountItems(); i++) {
|
for (int32 i = 0; i < from.fTrackList.CountItems(); i++) {
|
||||||
BString *string = (BString*)from.fTrackList.ItemAt(i);
|
BString *string = (BString*)from.fTrackList.ItemAt(i);
|
||||||
cdaudio_time *time = (cdaudio_time*)from.fTimeList.ItemAt(i);
|
CDAudioTime *time = (CDAudioTime*)from.fTimeList.ItemAt(i);
|
||||||
|
|
||||||
if (!string || !time)
|
if (!string || !time)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
AddTrack(string->String(),*time);
|
AddTrack(string->String(), *time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CDDBData::~CDDBData(void)
|
CDDBData::~CDDBData()
|
||||||
{
|
{
|
||||||
STRACE(("CDDBData::~CDDBData\n"));
|
STRACE(("CDDBData::~CDDBData\n"));
|
||||||
EmptyLists();
|
_EmptyLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CDDBData &
|
CDDBData &
|
||||||
CDDBData::operator=(const CDDBData &from)
|
CDDBData::operator=(const CDDBData &from)
|
||||||
{
|
{
|
||||||
EmptyLists();
|
_EmptyLists();
|
||||||
fDiscID = from.fDiscID;
|
fDiscID = from.fDiscID;
|
||||||
fArtist = from.fArtist;
|
fArtist = from.fArtist;
|
||||||
fAlbum = from.fAlbum;
|
fAlbum = from.fAlbum;
|
||||||
fGenre = from.fGenre;
|
fGenre = from.fGenre;
|
||||||
fDiscTime = from.fDiscTime;
|
fDiscTime = from.fDiscTime;
|
||||||
fYear = fYear;
|
fYear = from.fYear;
|
||||||
|
|
||||||
for (int32 i = 0; i < from.fTrackList.CountItems(); i++) {
|
for (int32 i = 0; i < from.fTrackList.CountItems(); i++) {
|
||||||
BString *string = (BString*)from.fTrackList.ItemAt(i);
|
BString *string = (BString*)from.fTrackList.ItemAt(i);
|
||||||
cdaudio_time *time = (cdaudio_time*)from.fTimeList.ItemAt(i);
|
CDAudioTime *time = (CDAudioTime*)from.fTimeList.ItemAt(i);
|
||||||
|
|
||||||
if (!string || !time)
|
if (!string || !time)
|
||||||
continue;
|
continue;
|
||||||
@@ -112,25 +154,25 @@ CDDBData::operator=(const CDDBData &from)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBData::MakeEmpty(void)
|
CDDBData::MakeEmpty()
|
||||||
{
|
{
|
||||||
STRACE(("CDDBData::MakeEmpty\n"));
|
STRACE(("CDDBData::MakeEmpty\n"));
|
||||||
|
|
||||||
EmptyLists();
|
_EmptyLists();
|
||||||
fDiscID = -1;
|
fDiscID = -1;
|
||||||
fArtist = "";
|
fArtist = "";
|
||||||
fAlbum = "";
|
fAlbum = "";
|
||||||
fGenre = "";
|
fGenre = "";
|
||||||
fDiscTime.minutes = -1;
|
fDiscTime.SetMinutes(-1);
|
||||||
fDiscTime.seconds = -1;
|
fDiscTime.SetSeconds(-1);
|
||||||
fYear = -1;
|
fYear = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBData::EmptyLists(void)
|
CDDBData::_EmptyLists()
|
||||||
{
|
{
|
||||||
STRACE(("CDDBData::EmptyLists\n"));
|
STRACE(("CDDBData::_EmptyLists\n"));
|
||||||
|
|
||||||
for (int32 i = 0; i < fTrackList.CountItems(); i++) {
|
for (int32 i = 0; i < fTrackList.CountItems(); i++) {
|
||||||
BString *string = (BString*)fTrackList.ItemAt(i);
|
BString *string = (BString*)fTrackList.ItemAt(i);
|
||||||
@@ -139,7 +181,7 @@ CDDBData::EmptyLists(void)
|
|||||||
fTrackList.MakeEmpty();
|
fTrackList.MakeEmpty();
|
||||||
|
|
||||||
for (int32 j = 0; j < fTimeList.CountItems(); j++) {
|
for (int32 j = 0; j < fTimeList.CountItems(); j++) {
|
||||||
cdaudio_time *time = (cdaudio_time*)fTimeList.ItemAt(j);
|
CDAudioTime *time = (CDAudioTime*)fTimeList.ItemAt(j);
|
||||||
delete time;
|
delete time;
|
||||||
}
|
}
|
||||||
fTimeList.MakeEmpty();
|
fTimeList.MakeEmpty();
|
||||||
@@ -149,7 +191,7 @@ CDDBData::EmptyLists(void)
|
|||||||
status_t
|
status_t
|
||||||
CDDBData::Load(const entry_ref &ref)
|
CDDBData::Load(const entry_ref &ref)
|
||||||
{
|
{
|
||||||
STRACE(("CDDBData::Load(%s)\n",ref.name));
|
STRACE(("CDDBData::Load(%s)\n", ref.name));
|
||||||
|
|
||||||
BFile file(&ref, B_READ_ONLY);
|
BFile file(&ref, B_READ_ONLY);
|
||||||
|
|
||||||
@@ -160,53 +202,53 @@ CDDBData::Load(const entry_ref &ref)
|
|||||||
|
|
||||||
attr_info info;
|
attr_info info;
|
||||||
|
|
||||||
if (file.GetAttrInfo("Audio:Genre",&info) == B_OK && info.size > 0) {
|
if (file.GetAttrInfo("Audio:Genre", &info) == B_OK && info.size > 0) {
|
||||||
char genredata[info.size + 2];
|
char genreData[info.size + 2];
|
||||||
|
|
||||||
if (file.ReadAttr("Audio:Genre",B_STRING_TYPE,0,genredata,info.size) > 0)
|
if (file.ReadAttr("Audio:Genre", B_STRING_TYPE, 0, genreData, info.size) > 0)
|
||||||
fGenre = genredata;
|
fGenre = genreData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file.GetAttrInfo("Audio:Year",&info)==B_OK && info.size > 0) {
|
if (file.GetAttrInfo("Audio:Year", &info) == B_OK && info.size > 0) {
|
||||||
int32 data;
|
int32 yearData;
|
||||||
|
|
||||||
if (file.ReadAttr("Audio:Year",B_INT32_TYPE,0,&data,info.size) > 0)
|
if (file.ReadAttr("Audio:Year", B_INT32_TYPE, 0, &yearData, info.size) > 0)
|
||||||
fYear = data;
|
fYear = yearData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Attempt reading the file before attempting to read the attributes
|
// TODO: Attempt reading the file before attempting to read the attributes
|
||||||
if (file.GetAttrInfo("CD:tracks",&info)==B_OK && info.size > 0) {
|
if (file.GetAttrInfo("CD:tracks", &info) == B_OK && info.size > 0) {
|
||||||
char trackdata[info.size + 2];
|
char trackData[info.size + 2];
|
||||||
|
|
||||||
if (file.ReadAttr("CD:tracks",B_STRING_TYPE,0,trackdata,info.size) > 0) {
|
if (file.ReadAttr("CD:tracks", B_STRING_TYPE, 0, trackData, info.size) > 0) {
|
||||||
trackdata[info.size] = 0;
|
trackData[info.size] = 0;
|
||||||
BString tmp = GetLineFromString(trackdata);
|
BString tmp = GetLineFromString(trackData);
|
||||||
char *index;
|
char *index;
|
||||||
|
|
||||||
if (fTrackList.CountItems() > 0)
|
if (fTrackList.CountItems() > 0)
|
||||||
EmptyLists();
|
_EmptyLists();
|
||||||
|
|
||||||
fArtist = tmp;
|
fArtist = tmp;
|
||||||
fArtist.Truncate(fArtist.FindFirst(" - "));
|
fArtist.Truncate(fArtist.FindFirst(" - "));
|
||||||
STRACE(("CDDBData::Load: Artist set to %s\n",fArtist.String()));
|
STRACE(("CDDBData::Load: Artist set to %s\n", fArtist.String()));
|
||||||
|
|
||||||
fAlbum = tmp.String() + (tmp.FindFirst(" - ") + 3);
|
fAlbum = tmp.String() + (tmp.FindFirst(" - ") + 3);
|
||||||
STRACE(("CDDBData::Load: Album set to %s\n",fAlbum.String()));
|
STRACE(("CDDBData::Load: Album set to %s\n", fAlbum.String()));
|
||||||
|
|
||||||
index = strchr(trackdata,'\n') + 1;
|
index = strchr(trackData, '\n') + 1;
|
||||||
while (*index) {
|
while (*index) {
|
||||||
tmp = GetLineFromString(index);
|
tmp = GetLineFromString(index);
|
||||||
|
|
||||||
if (tmp.CountChars() > 0) {
|
if (tmp.CountChars() > 0) {
|
||||||
BString *newtrack = new BString(tmp);
|
BString *newTrack = new BString(tmp);
|
||||||
cdaudio_time *time = new cdaudio_time;
|
CDAudioTime *time = new CDAudioTime;
|
||||||
time->minutes = 0;
|
time->SetMinutes(0);
|
||||||
time->seconds = 0;
|
time->SetSeconds(0);
|
||||||
|
|
||||||
STRACE(("CDDBData::Load: Adding Track %s (%ld:%ld)\n",newtrack->String(),
|
STRACE(("CDDBData::Load: Adding Track %s (%ld:%ld)\n", newTrack->String(),
|
||||||
time->minutes,time->seconds));
|
time->minutes, time->seconds));
|
||||||
|
|
||||||
fTrackList.AddItem(newtrack);
|
fTrackList.AddItem(newTrack);
|
||||||
fTimeList.AddItem(time);
|
fTimeList.AddItem(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,8 +263,9 @@ CDDBData::Load(const entry_ref &ref)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
CDDBData::Load(void)
|
CDDBData::Load()
|
||||||
{
|
{
|
||||||
// This uses the default R5 path
|
// This uses the default R5 path
|
||||||
|
|
||||||
@@ -236,7 +279,7 @@ CDDBData::Load(void)
|
|||||||
BString filename(path.Path());
|
BString filename(path.Path());
|
||||||
filename << "/" << Artist() << " - " << Album();
|
filename << "/" << Artist() << " - " << Album();
|
||||||
|
|
||||||
if (filename.Compare("Artist")==0)
|
if (filename.Compare("Artist") == 0)
|
||||||
filename << "." << DiscID();
|
filename << "." << DiscID();
|
||||||
|
|
||||||
BEntry entry(filename.String());
|
BEntry entry(filename.String());
|
||||||
@@ -249,8 +292,9 @@ CDDBData::Load(void)
|
|||||||
return Load(ref);
|
return Load(ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
CDDBData::Save(void)
|
CDDBData::Save()
|
||||||
{
|
{
|
||||||
// This uses the default R5 path
|
// This uses the default R5 path
|
||||||
|
|
||||||
@@ -270,6 +314,7 @@ CDDBData::Save(void)
|
|||||||
return Save(filename.String());
|
return Save(filename.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
CDDBData::Save(const char *filename)
|
CDDBData::Save(const char *filename)
|
||||||
{
|
{
|
||||||
@@ -280,72 +325,74 @@ CDDBData::Save(const char *filename)
|
|||||||
|
|
||||||
BFile file(filename, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
BFile file(filename, B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
if (file.InitCheck() != B_OK) {
|
if (file.InitCheck() != B_OK) {
|
||||||
STRACE(("CDDBData::Save failed - couldn't create file %s\n",filename));
|
STRACE(("CDDBData::Save failed - couldn't create file %s\n", filename));
|
||||||
return file.InitCheck();
|
return file.InitCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
BString entry;
|
BString entry;
|
||||||
char timestring[10];
|
char timestring[10];
|
||||||
|
|
||||||
sprintf(timestring,"%.2ld:%.2ld",fDiscTime.minutes, fDiscTime.seconds);
|
sprintf(timestring,"%.2ld:%.2ld", fDiscTime.GetMinutes(), fDiscTime.GetSeconds());
|
||||||
|
|
||||||
entry << fArtist << " - " << fAlbum << "\t" << timestring << "\n";
|
entry << fArtist << " - " << fAlbum << "\t" << timestring << "\n";
|
||||||
file.Write(entry.String(),entry.Length());
|
file.Write(entry.String(), entry.Length());
|
||||||
|
|
||||||
STRACE(("CDDBData::Save: wrote first line: %s",entry.String()));
|
STRACE(("CDDBData::Save: wrote first line: %s", entry.String()));
|
||||||
|
|
||||||
BString tracksattr(fArtist);
|
BString tracksattr(fArtist);
|
||||||
tracksattr << " - " << fAlbum << "\n";
|
tracksattr << " - " << fAlbum << "\n";
|
||||||
|
|
||||||
for (int32 i = 0; i < fTrackList.CountItems(); i++) {
|
for (int32 i = 0; i < fTrackList.CountItems(); i++) {
|
||||||
BString *trackstr = (BString *)fTrackList.ItemAt(i);
|
BString *trackstr = (BString *)fTrackList.ItemAt(i);
|
||||||
cdaudio_time *time= (cdaudio_time*)fTimeList.ItemAt(i);
|
CDAudioTime *time= (CDAudioTime*)fTimeList.ItemAt(i);
|
||||||
|
|
||||||
if (!trackstr || !time)
|
if (!trackstr || !time)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
entry = *trackstr;
|
entry = *trackstr;
|
||||||
|
|
||||||
sprintf(timestring,"%.2ld:%.2ld",time->minutes, time->seconds);
|
sprintf(timestring,"%.2ld:%.2ld", time->GetMinutes(), time->GetSeconds());
|
||||||
|
|
||||||
entry << "\t" << timestring << "\n";
|
entry << "\t" << timestring << "\n";
|
||||||
file.Write(entry.String(),entry.Length());
|
file.Write(entry.String(), entry.Length());
|
||||||
STRACE(("CDDBData::Save: Wrote line: %s",entry.String()));
|
STRACE(("CDDBData::Save: Wrote line: %s", entry.String()));
|
||||||
|
|
||||||
tracksattr << *trackstr << "\n";
|
tracksattr << *trackstr << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
file.WriteAttr("CD:key", B_INT32_TYPE, 0, &fDiscID, sizeof(int32));
|
file.WriteAttr("CD:key", B_INT32_TYPE, 0, &fDiscID, sizeof(int32));
|
||||||
STRACE(("CDDBData::Save: Wrote CD identifier: %ld(%lx)\n",fDiscID,fDiscID));
|
STRACE(("CDDBData::Save: Wrote CD identifier: %ld(%lx)\n", fDiscID, fDiscID));
|
||||||
file.WriteAttr("CD:tracks", B_STRING_TYPE, 0, tracksattr.String(), tracksattr.Length() + 1);
|
file.WriteAttr("CD:tracks", B_STRING_TYPE, 0, tracksattr.String(), tracksattr.Length() + 1);
|
||||||
|
|
||||||
if (fGenre.CountChars() > 0)
|
if (fGenre.CountChars() > 0)
|
||||||
file.WriteAttr("Audio:Genre",B_STRING_TYPE,0, fGenre.String(), fGenre.Length() + 1);
|
file.WriteAttr("Audio:Genre",B_STRING_TYPE, 0, fGenre.String(), fGenre.Length() + 1);
|
||||||
|
|
||||||
if (fYear > 0)
|
if (fYear > 0)
|
||||||
file.WriteAttr("Audio:Year",B_INT32_TYPE,0,&fYear,sizeof(int32));
|
file.WriteAttr("Audio:Year", B_INT32_TYPE, 0, &fYear, sizeof(int32));
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16
|
uint16
|
||||||
CDDBData::CountTracks(void) const
|
CDDBData::CountTracks() const
|
||||||
{
|
{
|
||||||
return fTrackList.CountItems();
|
return fTrackList.CountItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDDBData::RenameTrack(const int32 &index, const char *newname)
|
CDDBData::RenameTrack(const int32 &index, const char *newName)
|
||||||
{
|
{
|
||||||
if (!newname) {
|
if (!newName) {
|
||||||
STRACE(("CDDBData::RenameTrack failed - NULL newname\n"));
|
STRACE(("CDDBData::RenameTrack failed - NULL newName\n"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BString *name = (BString*)fTrackList.ItemAt(index);
|
BString *name = (BString*)fTrackList.ItemAt(index);
|
||||||
if (name) {
|
if (name) {
|
||||||
STRACE(("CDDBData::RenameTrack(%ld,%s)\n",index,newname));
|
STRACE(("CDDBData::RenameTrack(%ld,%s)\n", index, newName));
|
||||||
name->SetTo(newname);
|
name->SetTo(newName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,20 +400,22 @@ CDDBData::RenameTrack(const int32 &index, const char *newname)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBData::AddTrack(const char *track, const cdaudio_time &time,
|
CDDBData::AddTrack(const char *track, const CDAudioTime &time,
|
||||||
const int16 &index)
|
const int16 &index)
|
||||||
{
|
{
|
||||||
if (!track) {
|
if (!track) {
|
||||||
STRACE(("CDDBData::AddTrack failed - NULL name\n"));
|
STRACE(("CDDBData::AddTrack failed - NULL name\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
STRACE(("CDDBData::AddTrack(%s, %ld:%.2ld,%d)\n",track,time.minutes,time.seconds,index));
|
STRACE(("CDDBData::AddTrack(%s, %ld:%.2ld,%d)\n", track, time.minutes, time.seconds, index));
|
||||||
|
|
||||||
fTrackList.AddItem(new BString(track));
|
fTrackList.AddItem(new BString(track));
|
||||||
fTimeList.AddItem(new cdaudio_time(time));
|
fTimeList.AddItem(new CDAudioTime(time));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBData::RemoveTrack(const int16 &index)
|
CDDBData::RemoveTrack(const int16 &index)
|
||||||
{
|
{
|
||||||
@@ -376,9 +425,10 @@ CDDBData::RemoveTrack(const int16 &index)
|
|||||||
fTrackList.RemoveItem(index);
|
fTrackList.RemoveItem(index);
|
||||||
fTimeList.RemoveItem(index);
|
fTimeList.RemoveItem(index);
|
||||||
|
|
||||||
STRACE(("CDDBData::RemoveTrack(%d)\n",index));
|
STRACE(("CDDBData::RemoveTrack(%d)\n", index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
CDDBData::TrackAt(const int16 &index) const
|
CDDBData::TrackAt(const int16 &index) const
|
||||||
{
|
{
|
||||||
@@ -389,34 +439,43 @@ CDDBData::TrackAt(const int16 &index) const
|
|||||||
return track->String();
|
return track->String();
|
||||||
}
|
}
|
||||||
|
|
||||||
cdaudio_time *
|
|
||||||
|
CDAudioTime *
|
||||||
CDDBData::TrackTimeAt(const int16 &index)
|
CDDBData::TrackTimeAt(const int16 &index)
|
||||||
{
|
{
|
||||||
return (cdaudio_time *)fTimeList.ItemAt(index);
|
return (CDAudioTime *)fTimeList.ItemAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
CDDBQuery::CDDBQuery(const char *server, int32 port)
|
CDDBQuery::CDDBQuery(const char *server, int32 port)
|
||||||
: fServerName(server),
|
:
|
||||||
|
fServerName(server),
|
||||||
fPort(port),
|
fPort(port),
|
||||||
fConnected(false),
|
fConnected(false),
|
||||||
fState(kInitial)
|
fState(kInitial)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
CDDBQuery::~CDDBQuery(void)
|
|
||||||
|
CDDBQuery::~CDDBQuery()
|
||||||
{
|
{
|
||||||
kill_thread(fThread);
|
kill_thread(fThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBQuery::SetToSite(const char *server, int32 port)
|
CDDBQuery::SetToSite(const char *server, int32 port)
|
||||||
{
|
{
|
||||||
Disconnect();
|
_Disconnect();
|
||||||
fServerName = server;
|
fServerName = server;
|
||||||
fPort = port;
|
fPort = port;
|
||||||
fState = kInitial;
|
fState = kInitial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBQuery::SetToCD(const char *path)
|
CDDBQuery::SetToCD(const char *path)
|
||||||
{
|
{
|
||||||
@@ -452,7 +511,7 @@ CDDBQuery::SetToCD(const char *path)
|
|||||||
|
|
||||||
result = B_OK;
|
result = B_OK;
|
||||||
fState = kReading;
|
fState = kReading;
|
||||||
fThread = spawn_thread(&CDDBQuery::QueryThread, "CDDBLookup", B_NORMAL_PRIORITY, this);
|
fThread = spawn_thread(&CDDBQuery::_QueryThread, "CDDBLookup", B_NORMAL_PRIORITY, this);
|
||||||
|
|
||||||
if (fThread >= 0)
|
if (fThread >= 0)
|
||||||
resume_thread(fThread);
|
resume_thread(fThread);
|
||||||
@@ -462,13 +521,9 @@ CDDBQuery::SetToCD(const char *path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
DoNothing(int)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
CDDBQuery::GetToken(const char *stream, BString &result)
|
CDDBQuery::_GetToken(const char *stream, BString &result)
|
||||||
{
|
{
|
||||||
result = "";
|
result = "";
|
||||||
while (*stream && *stream <= ' ')
|
while (*stream && *stream <= ' ')
|
||||||
@@ -484,21 +539,21 @@ status_t
|
|||||||
CDDBQuery::GetSites(bool (*eachFunc)(const char *site, int port, const char *latitude,
|
CDDBQuery::GetSites(bool (*eachFunc)(const char *site, int port, const char *latitude,
|
||||||
const char *longitude, const char *description, void *state), void *passThru)
|
const char *longitude, const char *description, void *state), void *passThru)
|
||||||
{
|
{
|
||||||
if (!IsConnected())
|
if (!_IsConnected())
|
||||||
Connect();
|
_Connect();
|
||||||
|
|
||||||
BString tmp;
|
BString tmp;
|
||||||
|
|
||||||
tmp = "sites\n";
|
tmp = "sites\n";
|
||||||
STRACE((">%s", tmp.String()));
|
STRACE((">%s", tmp.String()));
|
||||||
|
|
||||||
if (fSocket.Send(tmp.String(), tmp.Length())==-1)
|
if (fSocket.Send(tmp.String(), tmp.Length()) == -1)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
ReadLine(tmp);
|
_ReadLine(tmp);
|
||||||
|
|
||||||
if (tmp.FindFirst("210") == -1) {
|
if (tmp.FindFirst("210") == -1) {
|
||||||
Disconnect();
|
_Disconnect();
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,27 +564,28 @@ CDDBQuery::GetSites(bool (*eachFunc)(const char *site, int port, const char *lat
|
|||||||
BString longitude;
|
BString longitude;
|
||||||
BString description;
|
BString description;
|
||||||
|
|
||||||
ReadLine(tmp);
|
_ReadLine(tmp);
|
||||||
if (tmp == ".")
|
if (tmp == ".")
|
||||||
break;
|
break;
|
||||||
const char *scanner = tmp.String();
|
const char *scanner = tmp.String();
|
||||||
|
|
||||||
scanner = GetToken(scanner, site);
|
scanner = _GetToken(scanner, site);
|
||||||
BString portString;
|
BString portString;
|
||||||
scanner = GetToken(scanner, portString);
|
scanner = _GetToken(scanner, portString);
|
||||||
sitePort = atoi(portString.String());
|
sitePort = atoi(portString.String());
|
||||||
scanner = GetToken(scanner, latitude);
|
scanner = _GetToken(scanner, latitude);
|
||||||
scanner = GetToken(scanner, longitude);
|
scanner = _GetToken(scanner, longitude);
|
||||||
description = scanner;
|
description = scanner;
|
||||||
|
|
||||||
if (eachFunc(site.String(), sitePort, latitude.String(), longitude.String(),
|
if (eachFunc(site.String(), sitePort, latitude.String(), longitude.String(),
|
||||||
description.String(), passThru))
|
description.String(), passThru))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Disconnect();
|
_Disconnect();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDDBQuery::GetData(CDDBData *data, bigtime_t timeout)
|
CDDBQuery::GetData(CDDBData *data, bigtime_t timeout)
|
||||||
{
|
{
|
||||||
@@ -550,17 +606,6 @@ CDDBQuery::GetData(CDDBData *data, bigtime_t timeout)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32
|
|
||||||
cddb_sum(int n)
|
|
||||||
{
|
|
||||||
char buf[12];
|
|
||||||
int32 ret = 0;
|
|
||||||
|
|
||||||
sprintf(buf, "%u", n);
|
|
||||||
for (const char *p = buf; *p != '\0'; p++)
|
|
||||||
ret += (*p - '0');
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
CDDBQuery::GetDiscID(const scsi_toc *toc)
|
CDDBQuery::GetDiscID(const scsi_toc *toc)
|
||||||
@@ -584,6 +629,7 @@ CDDBQuery::GetDiscID(const scsi_toc *toc)
|
|||||||
return discID;
|
return discID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
CDDBQuery::OffsetsToString(const scsi_toc *toc)
|
CDDBQuery::OffsetsToString(const scsi_toc *toc)
|
||||||
{
|
{
|
||||||
@@ -607,35 +653,38 @@ CDDBQuery::GetTrackCount(const scsi_toc *toc)
|
|||||||
return toc->toc_data[3] - toc->toc_data[2] + 1;
|
return toc->toc_data[3] - toc->toc_data[2] + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cdaudio_time
|
|
||||||
|
CDAudioTime
|
||||||
CDDBQuery::GetDiscTime(const scsi_toc *toc)
|
CDDBQuery::GetDiscTime(const scsi_toc *toc)
|
||||||
{
|
{
|
||||||
int16 trackcount = toc->toc_data[3] - toc->toc_data[2] + 1;
|
int16 trackcount = toc->toc_data[3] - toc->toc_data[2] + 1;
|
||||||
TrackRecord *desc = (TrackRecord*)&(toc->toc_data[4]);
|
TrackRecord *desc = (TrackRecord*)&(toc->toc_data[4]);
|
||||||
|
|
||||||
cdaudio_time disc;
|
CDAudioTime disc;
|
||||||
disc.minutes = desc[trackcount].min;
|
disc.SetMinutes(desc[trackcount].min);
|
||||||
disc.seconds = desc[trackcount].sec;
|
disc.SetSeconds(desc[trackcount].sec);
|
||||||
|
|
||||||
return disc;
|
return disc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBQuery::GetTrackTimes(const scsi_toc *toc, vector<cdaudio_time> ×)
|
CDDBQuery::GetTrackTimes(const scsi_toc *toc, vector<CDAudioTime> ×)
|
||||||
{
|
{
|
||||||
TrackRecord *tocData = (TrackRecord*)&(toc->toc_data[4]);
|
TrackRecord *tocData = (TrackRecord*)&(toc->toc_data[4]);
|
||||||
int16 trackCount = toc->toc_data[3] - toc->toc_data[2] + 1;
|
int16 trackCount = toc->toc_data[3] - toc->toc_data[2] + 1;
|
||||||
|
|
||||||
for (int index = 0; index < trackCount + 1; index++) {
|
for (int index = 0; index < trackCount + 1; index++) {
|
||||||
cdaudio_time cdtime;
|
CDAudioTime cdtime;
|
||||||
cdtime.minutes = tocData[index].min;
|
cdtime.SetMinutes(tocData[index].min);
|
||||||
cdtime.seconds = tocData[index].sec;
|
cdtime.SetSeconds(tocData[index].sec);
|
||||||
times.push_back(cdtime);
|
times.push_back(cdtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
CDDBQuery::ReadFromServer(BString &data)
|
CDDBQuery::_ReadFromServer(BString &data)
|
||||||
{
|
{
|
||||||
// This function queries the given CDDB server for the existence of the disc's data and
|
// This function queries the given CDDB server for the existence of the disc's data and
|
||||||
// saves the data to file once obtained.
|
// saves the data to file once obtained.
|
||||||
@@ -647,20 +696,20 @@ CDDBQuery::ReadFromServer(BString &data)
|
|||||||
|
|
||||||
int32 trackCount = GetTrackCount(&fSCSIData);
|
int32 trackCount = GetTrackCount(&fSCSIData);
|
||||||
BString offsetString = OffsetsToString(&fSCSIData);
|
BString offsetString = OffsetsToString(&fSCSIData);
|
||||||
int32 discLength = (fCDData.DiscTime()->minutes * 60) + fCDData.DiscTime()->seconds;
|
int32 discLength = (fCDData.DiscTime()->GetMinutes() * 60) + fCDData.DiscTime()->GetSeconds();
|
||||||
|
|
||||||
query << "cddb query " << idString << ' ' << trackCount << ' '
|
query << "cddb query " << idString << ' ' << trackCount << ' '
|
||||||
<< offsetString << ' ' << discLength << '\n';
|
<< offsetString << ' ' << discLength << '\n';
|
||||||
|
|
||||||
STRACE((">%s", query.String()));
|
STRACE((">%s", query.String()));
|
||||||
|
|
||||||
if (fSocket.Send(query.String(), query.Length())==-1) {
|
if (fSocket.Send(query.String(), query.Length()) == -1) {
|
||||||
Disconnect();
|
_Disconnect();
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
BString tmp;
|
BString tmp;
|
||||||
ReadLine(tmp);
|
_ReadLine(tmp);
|
||||||
STRACE(("<%s", tmp.String()));
|
STRACE(("<%s", tmp.String()));
|
||||||
|
|
||||||
BString category;
|
BString category;
|
||||||
@@ -673,32 +722,32 @@ CDDBQuery::ReadFromServer(BString &data)
|
|||||||
// the server returns. This may or may not be wise, but in my experience, the first
|
// the server returns. This may or may not be wise, but in my experience, the first
|
||||||
// one has been the right one.
|
// one has been the right one.
|
||||||
|
|
||||||
ReadLine(tmp);
|
_ReadLine(tmp);
|
||||||
|
|
||||||
// Get the category from the what the server returned
|
// Get the category from the what the server returned
|
||||||
GetToken(tmp.String(), category);
|
_GetToken(tmp.String(), category);
|
||||||
|
|
||||||
// Now we will get the disc ID for the CD. We will need this when we query for
|
// Now we will get the disc ID for the CD. We will need this when we query for
|
||||||
// the track name list. If we send the track name query with the real discID, nothing
|
// the track name list. If we send the track name query with the real discID, nothing
|
||||||
// will be returned. However, if we send the one from the entry, we'll get the names
|
// will be returned. However, if we send the one from the entry, we'll get the names
|
||||||
// and we can take these names attach them to the disc that we have.
|
// and we can take these names attach them to the disc that we have.
|
||||||
GetToken(tmp.String() + category.CountChars(),queryDiscID);
|
_GetToken(tmp.String() + category.CountChars(), queryDiscID);
|
||||||
|
|
||||||
// This is to suck up any more search results that the server sends us.
|
// This is to suck up any more search results that the server sends us.
|
||||||
BString throwaway;
|
BString throwaway;
|
||||||
ReadLine(throwaway);
|
_ReadLine(throwaway);
|
||||||
while (throwaway.ByteAt(0) != '.')
|
while (throwaway.ByteAt(0) != '.')
|
||||||
ReadLine(throwaway);
|
_ReadLine(throwaway);
|
||||||
} else {
|
} else {
|
||||||
// We get here for any time the CDDB server does not recognize the CD, amongst other things
|
// We get here for any time the CDDB server does not recognize the CD, amongst other things
|
||||||
STRACE(("CDDB lookup error: %s\n",tmp.String()));
|
STRACE(("CDDB lookup error: %s\n", tmp.String()));
|
||||||
fCDData.SetGenre("misc");
|
fCDData.SetGenre("misc");
|
||||||
return B_NAME_NOT_FOUND;
|
return B_NAME_NOT_FOUND;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
GetToken(tmp.String() + 3, category);
|
_GetToken(tmp.String() + 3, category);
|
||||||
}
|
}
|
||||||
STRACE(("CDDBQuery::ReadFromServer: Genre: %s\n",category.String()));
|
STRACE(("CDDBQuery::_ReadFromServer: Genre: %s\n", category.String()));
|
||||||
if (!category.Length()) {
|
if (!category.Length()) {
|
||||||
STRACE(("Set genre to 'misc'\n"));
|
STRACE(("Set genre to 'misc'\n"));
|
||||||
category = "misc";
|
category = "misc";
|
||||||
@@ -707,13 +756,13 @@ CDDBQuery::ReadFromServer(BString &data)
|
|||||||
// Query for the disc's data - artist, album, tracks, etc.
|
// Query for the disc's data - artist, album, tracks, etc.
|
||||||
query = "";
|
query = "";
|
||||||
query << "cddb read " << category << ' ' << queryDiscID << '\n' ;
|
query << "cddb read " << category << ' ' << queryDiscID << '\n' ;
|
||||||
if (fSocket.Send(query.String(), query.Length())==-1) {
|
if (fSocket.Send(query.String(), query.Length()) == -1) {
|
||||||
Disconnect();
|
_Disconnect();
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
ReadLine(tmp);
|
_ReadLine(tmp);
|
||||||
|
|
||||||
if (tmp == "." || tmp == ".\n")
|
if (tmp == "." || tmp == ".\n")
|
||||||
break;
|
break;
|
||||||
@@ -724,11 +773,12 @@ CDDBQuery::ReadFromServer(BString &data)
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
CDDBQuery::Connect()
|
CDDBQuery::_Connect()
|
||||||
{
|
{
|
||||||
if (fConnected)
|
if (fConnected)
|
||||||
Disconnect();
|
_Disconnect();
|
||||||
|
|
||||||
BNetAddress address;
|
BNetAddress address;
|
||||||
|
|
||||||
@@ -743,20 +793,22 @@ CDDBQuery::Connect()
|
|||||||
fConnected = true;
|
fConnected = true;
|
||||||
|
|
||||||
BString tmp;
|
BString tmp;
|
||||||
ReadLine(tmp);
|
_ReadLine(tmp);
|
||||||
IdentifySelf();
|
_IdentifySelf();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDDBQuery::IsConnected() const
|
CDDBQuery::_IsConnected() const
|
||||||
{
|
{
|
||||||
return fConnected;
|
return fConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBQuery::Disconnect()
|
CDDBQuery::_Disconnect()
|
||||||
{
|
{
|
||||||
if (fConnected) {
|
if (fConnected) {
|
||||||
fSocket.Close();
|
fSocket.Close();
|
||||||
@@ -764,8 +816,9 @@ CDDBQuery::Disconnect()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBQuery::ReadLine(BString &buffer)
|
CDDBQuery::_ReadLine(BString &buffer)
|
||||||
{
|
{
|
||||||
buffer = "";
|
buffer = "";
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
@@ -814,9 +867,9 @@ CDDBQuery::ReadLine(BString &buffer)
|
|||||||
srcstr[1] = '\0';
|
srcstr[1] = '\0';
|
||||||
srclen = 1;
|
srclen = 1;
|
||||||
destlen = 5;
|
destlen = 5;
|
||||||
memset(deststr,0,5);
|
memset(deststr, 0, 5);
|
||||||
|
|
||||||
if (convert_to_utf8(B_ISO1_CONVERSION,srcstr,&srclen,deststr,&destlen,&state)==B_OK) {
|
if (convert_to_utf8(B_ISO1_CONVERSION, srcstr, &srclen, deststr, &destlen, &state) == B_OK) {
|
||||||
// We succeeded. Amazing. Now we hack the string into having the character
|
// We succeeded. Amazing. Now we hack the string into having the character
|
||||||
length = buffer.Length();
|
length = buffer.Length();
|
||||||
|
|
||||||
@@ -845,10 +898,11 @@ CDDBQuery::ReadLine(BString &buffer)
|
|||||||
STRACE(("<%s", buffer.String()));
|
STRACE(("<%s", buffer.String()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
CDDBQuery::IdentifySelf()
|
CDDBQuery::_IdentifySelf()
|
||||||
{
|
{
|
||||||
BString username,hostname;
|
BString username, hostname;
|
||||||
|
|
||||||
username = getenv("USER");
|
username = getenv("USER");
|
||||||
hostname = getenv("HOSTNAME");
|
hostname = getenv("HOSTNAME");
|
||||||
@@ -864,17 +918,18 @@ CDDBQuery::IdentifySelf()
|
|||||||
|
|
||||||
STRACE((">%s", tmp.String()));
|
STRACE((">%s", tmp.String()));
|
||||||
if (fSocket.Send(tmp.String(), tmp.Length())==-1) {
|
if (fSocket.Send(tmp.String(), tmp.Length())==-1) {
|
||||||
Disconnect();
|
_Disconnect();
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadLine(tmp);
|
_ReadLine(tmp);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
CDDBQuery::OpenContentFile(const int32 &discID)
|
CDDBQuery::_OpenContentFile(const int32 &discID)
|
||||||
{
|
{
|
||||||
// Makes sure that the lookup has a valid file to work with for the CD content.
|
// Makes sure that the lookup has a valid file to work with for the CD content.
|
||||||
// Returns true if there is an existing file, false if a lookup is required.
|
// Returns true if there is an existing file, false if a lookup is required.
|
||||||
@@ -909,11 +964,11 @@ CDDBQuery::OpenContentFile(const int32 &discID)
|
|||||||
if (status == B_NO_INIT) {
|
if (status == B_NO_INIT) {
|
||||||
// We receive this error when the Load() function couldn't load the track times
|
// We receive this error when the Load() function couldn't load the track times
|
||||||
// This just means that we get it from the SCSI data given to us in SetToCD
|
// This just means that we get it from the SCSI data given to us in SetToCD
|
||||||
vector<cdaudio_time> times;
|
vector<CDAudioTime> times;
|
||||||
GetTrackTimes(&fSCSIData,times);
|
GetTrackTimes(&fSCSIData,times);
|
||||||
|
|
||||||
for (int32 i = 0; i < fCDData.CountTracks(); i++) {
|
for (int32 i = 0; i < fCDData.CountTracks(); i++) {
|
||||||
cdaudio_time *item = fCDData.TrackTimeAt(i);
|
CDAudioTime *item = fCDData.TrackTimeAt(i);
|
||||||
*item = times[i + 1] - times[i];
|
*item = times[i + 1] - times[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -923,26 +978,27 @@ CDDBQuery::OpenContentFile(const int32 &discID)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
CDDBQuery::QueryThread(void *owner)
|
CDDBQuery::_QueryThread(void *owner)
|
||||||
{
|
{
|
||||||
CDDBQuery *query = (CDDBQuery *)owner;
|
CDDBQuery *query = (CDDBQuery *)owner;
|
||||||
|
|
||||||
signal(kTerminatingSignal, DoNothing);
|
signal(kTerminatingSignal, DoNothing);
|
||||||
|
|
||||||
if (query->OpenContentFile(query->fCDData.DiscID()) != B_OK) {
|
if (query->_OpenContentFile(query->fCDData.DiscID()) != B_OK) {
|
||||||
// new content file, read it in from the server
|
// new content file, read it in from the server
|
||||||
if (query->Connect()==B_OK) {
|
if (query->_Connect() == B_OK) {
|
||||||
BString data;
|
BString data;
|
||||||
|
|
||||||
query->ReadFromServer(data);
|
query->_ReadFromServer(data);
|
||||||
query->ParseData(data);
|
query->_ParseData(data);
|
||||||
query->WriteFile();
|
query->_WriteFile();
|
||||||
} else {
|
} else {
|
||||||
// We apparently couldn't connect to the server, so we'll need to handle
|
// We apparently couldn't connect to the server, so we'll need to handle
|
||||||
// creating tracknames. Note that we do not save to disk. This is because it should
|
// creating tracknames. Note that we do not save to disk. This is because it should
|
||||||
// be up to the user what to do.
|
// be up to the user what to do.
|
||||||
query->SetDefaultInfo();
|
query->_SetDefaultInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -953,8 +1009,9 @@ CDDBQuery::QueryThread(void *owner)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBQuery::WriteFile(void)
|
CDDBQuery::_WriteFile()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_USER_DIRECTORY, &path, true) != B_OK)
|
if (find_directory(B_USER_DIRECTORY, &path, true) != B_OK)
|
||||||
@@ -966,20 +1023,21 @@ CDDBQuery::WriteFile(void)
|
|||||||
BString filename(path.Path());
|
BString filename(path.Path());
|
||||||
filename << "/" << fCDData.Artist() << " - " << fCDData.Album();
|
filename << "/" << fCDData.Artist() << " - " << fCDData.Album();
|
||||||
|
|
||||||
if (filename.Compare("Artist")==0)
|
if (filename.Compare("Artist") == 0)
|
||||||
filename << "." << fCDData.DiscID();
|
filename << "." << fCDData.DiscID();
|
||||||
|
|
||||||
fCDData.Save(filename.String());
|
fCDData.Save(filename.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBQuery::SetDefaultInfo(void)
|
CDDBQuery::_SetDefaultInfo()
|
||||||
{
|
{
|
||||||
for (int16 i = fCDData.CountTracks(); i >= 0; i--)
|
for (int16 i = fCDData.CountTracks(); i >= 0; i--)
|
||||||
fCDData.RemoveTrack(i);
|
fCDData.RemoveTrack(i);
|
||||||
|
|
||||||
vector<cdaudio_time> trackTimes;
|
vector<CDAudioTime> trackTimes;
|
||||||
GetTrackTimes(&fSCSIData,trackTimes);
|
GetTrackTimes(&fSCSIData, trackTimes);
|
||||||
int32 trackCount = GetTrackCount(&fSCSIData);
|
int32 trackCount = GetTrackCount(&fSCSIData);
|
||||||
|
|
||||||
fCDData.SetArtist("Artist");
|
fCDData.SetArtist("Artist");
|
||||||
@@ -994,13 +1052,14 @@ CDDBQuery::SetDefaultInfo(void)
|
|||||||
|
|
||||||
trackname << i + 1;
|
trackname << i + 1;
|
||||||
|
|
||||||
cdaudio_time time = trackTimes[i + 1] - trackTimes[i];
|
CDAudioTime time = trackTimes[i + 1] - trackTimes[i];
|
||||||
fCDData.AddTrack(trackname.String(),time);
|
fCDData.AddTrack(trackname.String(), time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDDBQuery::ParseData(const BString &data)
|
CDDBQuery::_ParseData(const BString &data)
|
||||||
{
|
{
|
||||||
// Can't simply call MakeEmpty() because the thread is spawned when the discID kept in fCDData
|
// Can't simply call MakeEmpty() because the thread is spawned when the discID kept in fCDData
|
||||||
// is not the same as what's in the drive and MakeEmpty invalidates *everything* in the object.
|
// is not the same as what's in the drive and MakeEmpty invalidates *everything* in the object.
|
||||||
@@ -1008,7 +1067,7 @@ CDDBQuery::ParseData(const BString &data)
|
|||||||
for (int16 i = fCDData.CountTracks(); i >= 0; i--)
|
for (int16 i = fCDData.CountTracks(); i >= 0; i--)
|
||||||
fCDData.RemoveTrack(i);
|
fCDData.RemoveTrack(i);
|
||||||
|
|
||||||
vector<cdaudio_time> trackTimes;
|
vector<CDAudioTime> trackTimes;
|
||||||
GetTrackTimes(&fSCSIData,trackTimes);
|
GetTrackTimes(&fSCSIData,trackTimes);
|
||||||
int32 trackCount = GetTrackCount(&fSCSIData);
|
int32 trackCount = GetTrackCount(&fSCSIData);
|
||||||
|
|
||||||
@@ -1027,8 +1086,8 @@ CDDBQuery::ParseData(const BString &data)
|
|||||||
|
|
||||||
trackname << i + 1;
|
trackname << i + 1;
|
||||||
|
|
||||||
cdaudio_time time = trackTimes[i + 1] - trackTimes[i];
|
CDAudioTime time = trackTimes[i + 1] - trackTimes[i];
|
||||||
fCDData.AddTrack(trackname.String(),time);
|
fCDData.AddTrack(trackname.String(), time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1045,7 +1104,7 @@ CDDBQuery::ParseData(const BString &data)
|
|||||||
artist = album = GetLineFromString(data.String() + sizeof("DYEAR") + pos);
|
artist = album = GetLineFromString(data.String() + sizeof("DYEAR") + pos);
|
||||||
|
|
||||||
// TODO: finish, once I find an entry which actually has a year in it
|
// TODO: finish, once I find an entry which actually has a year in it
|
||||||
BAlert *alert = new BAlert("SimplyVorbis","DYEAR entry found\n","OK");
|
BAlert *alert = new BAlert("SimplyVorbis", "DYEAR entry found\n", "OK");
|
||||||
alert->Go();
|
alert->Go();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1079,7 +1138,7 @@ CDDBQuery::ParseData(const BString &data)
|
|||||||
BString trackName = data.String() + pos + searchString.Length();
|
BString trackName = data.String() + pos + searchString.Length();
|
||||||
trackName.Truncate(trackName.FindFirst("\n"));
|
trackName.Truncate(trackName.FindFirst("\n"));
|
||||||
|
|
||||||
cdaudio_time tracktime = trackTimes[trackCount + 1] - trackTimes[trackCount];
|
CDAudioTime tracktime = trackTimes[trackCount + 1] - trackTimes[trackCount];
|
||||||
fCDData.AddTrack(trackName.String(),tracktime);
|
fCDData.AddTrack(trackName.String(),tracktime);
|
||||||
|
|
||||||
trackCount++;
|
trackCount++;
|
||||||
@@ -1090,23 +1149,8 @@ CDDBQuery::ParseData(const BString &data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CDDBQuery::SetData(const CDDBData &data)
|
void CDDBQuery::SetData(const CDDBData &data)
|
||||||
{
|
{
|
||||||
fCDData = data;
|
fCDData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
BString
|
|
||||||
GetLineFromString(const char *string)
|
|
||||||
{
|
|
||||||
if (!string)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
BString out(string);
|
|
||||||
|
|
||||||
int32 linefeed = out.FindFirst("\n");
|
|
||||||
|
|
||||||
if (linefeed > 0)
|
|
||||||
out.Truncate(linefeed);
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|||||||
+123
-60
@@ -1,61 +1,105 @@
|
|||||||
#ifndef CDDBSUPPORT_H
|
#ifndef CDDBSUPPORT_H
|
||||||
#define CDDBSUPPORT_H
|
#define CDDBSUPPORT_H
|
||||||
|
|
||||||
#include <NetEndpoint.h>
|
#include "CDAudioDevice.h"
|
||||||
#include <String.h>
|
|
||||||
#include <scsi.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include "CDAudioDevice.h"
|
#include <NetEndpoint.h>
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <scsi.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
class CDDBData
|
|
||||||
{
|
class CDDBData {
|
||||||
public:
|
public:
|
||||||
CDDBData(int32 discid=-1);
|
CDDBData(int32 discid = -1);
|
||||||
CDDBData(const CDDBData &from);
|
CDDBData(const CDDBData &from);
|
||||||
~CDDBData(void);
|
~CDDBData();
|
||||||
CDDBData & operator=(const CDDBData &from);
|
CDDBData& operator=(const CDDBData &from);
|
||||||
|
|
||||||
status_t Load(const entry_ref &ref);
|
status_t Load(const entry_ref &ref);
|
||||||
status_t Save(const char *filename);
|
status_t Save(const char *filename);
|
||||||
|
|
||||||
status_t Load(void);
|
status_t Load();
|
||||||
status_t Save(void);
|
status_t Save();
|
||||||
|
|
||||||
void MakeEmpty(void);
|
void MakeEmpty();
|
||||||
void SetDiscID(const int32 &id) { fDiscID=id; }
|
|
||||||
int32 DiscID(void) const { return fDiscID; }
|
|
||||||
|
|
||||||
uint16 CountTracks(void) const;
|
void SetDiscID(const int32 &id)
|
||||||
const char * TrackAt(const int16 &index) const;
|
{
|
||||||
|
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);
|
bool RenameTrack(const int32 &index, const char *newname);
|
||||||
void AddTrack(const char *track, const cdaudio_time &time,
|
void AddTrack(const char *track, const CDAudioTime &time,
|
||||||
const int16 &index=-1);
|
const int16 &index=-1);
|
||||||
void RemoveTrack(const int16 &index);
|
void RemoveTrack(const int16 &index);
|
||||||
|
|
||||||
cdaudio_time * TrackTimeAt(const int16 &index);
|
CDAudioTime* TrackTimeAt(const int16 &index);
|
||||||
|
|
||||||
void SetDiscTime(const cdaudio_time time) { fDiscTime = time; }
|
void SetDiscTime(const CDAudioTime time)
|
||||||
cdaudio_time * DiscTime(void) { return &fDiscTime; }
|
{
|
||||||
|
fDiscTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
void SetGenre(const char *genre) { fGenre=genre; }
|
CDAudioTime* DiscTime()
|
||||||
const char * Genre(void) { return fGenre.String(); }
|
{
|
||||||
|
return &fDiscTime;
|
||||||
|
}
|
||||||
|
|
||||||
void SetArtist(const char *artist) { fArtist=artist; }
|
void SetGenre(const char *genre)
|
||||||
const char * Artist(void) const { return fArtist.String(); }
|
{
|
||||||
|
fGenre=genre;
|
||||||
|
}
|
||||||
|
|
||||||
void SetAlbum(const char *album) { fAlbum=album; }
|
const char* Genre()
|
||||||
const char * Album(void) const { return fAlbum.String(); }
|
{
|
||||||
|
return fGenre.String();
|
||||||
|
}
|
||||||
|
|
||||||
void SetYear(const int16 &year) { fYear=year; }
|
void SetArtist(const char *artist)
|
||||||
int16 Year(void) const { return fYear; }
|
{
|
||||||
|
fArtist = artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* Artist() const
|
||||||
|
{
|
||||||
|
return fArtist.String();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
void SetAlbum(const char *album)
|
||||||
void EmptyLists(void);
|
{
|
||||||
|
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;
|
int32 fDiscID;
|
||||||
|
|
||||||
@@ -66,17 +110,18 @@ private:
|
|||||||
BList fTrackList;
|
BList fTrackList;
|
||||||
BList fTimeList;
|
BList fTimeList;
|
||||||
|
|
||||||
cdaudio_time fDiscTime;
|
CDAudioTime fDiscTime;
|
||||||
int32 fYear;
|
int32 fYear;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// based on Jukebox by Chip Paul
|
// based on Jukebox by Chip Paul
|
||||||
|
|
||||||
class CDDBQuery
|
|
||||||
{
|
class CDDBQuery {
|
||||||
public:
|
public:
|
||||||
CDDBQuery(const char *server, int32 port = 888);
|
CDDBQuery(const char *server, int32 port = 888);
|
||||||
~CDDBQuery(void);
|
~CDDBQuery();
|
||||||
void SetToSite(const char *server, int32 port);
|
void SetToSite(const char *server, int32 port);
|
||||||
status_t GetSites(bool (*)(const char *site, int port,
|
status_t GetSites(bool (*)(const char *site, int port,
|
||||||
const char *latitude, const char *longitude,
|
const char *latitude, const char *longitude,
|
||||||
@@ -84,49 +129,67 @@ public:
|
|||||||
|
|
||||||
void SetToCD(const char *devicepath);
|
void SetToCD(const char *devicepath);
|
||||||
|
|
||||||
const char * GetArtist(void) { return fCDData.Artist(); }
|
const char* GetArtist()
|
||||||
const char * GetAlbum(void) { return fCDData.Album(); }
|
{
|
||||||
const char * GetGenre(void) { return fCDData.Genre(); }
|
return fCDData.Artist();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* GetAlbum()
|
||||||
|
{
|
||||||
|
return fCDData.Album();
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* GetGenre()
|
||||||
|
{
|
||||||
|
return fCDData.Genre();
|
||||||
|
}
|
||||||
|
|
||||||
bool GetData(CDDBData *data, bigtime_t timeout);
|
bool GetData(CDDBData *data, bigtime_t timeout);
|
||||||
void SetData(const CDDBData &data);
|
void SetData(const CDDBData &data);
|
||||||
|
|
||||||
bool Ready() const { return fState == kDone; }
|
bool Ready() const
|
||||||
int32 CurrentDiscID() const { return fCDData.DiscID(); }
|
{
|
||||||
|
return fState == kDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 CurrentDiscID() const
|
||||||
|
{
|
||||||
|
return fCDData.DiscID();
|
||||||
|
}
|
||||||
|
|
||||||
static int32 GetDiscID(const scsi_toc *);
|
static int32 GetDiscID(const scsi_toc *);
|
||||||
static int32 GetTrackCount(const scsi_toc *);
|
static int32 GetTrackCount(const scsi_toc *);
|
||||||
static cdaudio_time GetDiscTime(const scsi_toc *);
|
static CDAudioTime GetDiscTime(const scsi_toc *);
|
||||||
static void GetTrackTimes(const scsi_toc *, vector<cdaudio_time> ×);
|
static void GetTrackTimes(const scsi_toc *, vector<CDAudioTime> ×);
|
||||||
static BString OffsetsToString(const scsi_toc *);
|
static BString OffsetsToString(const scsi_toc *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
status_t Connect();
|
status_t _Connect();
|
||||||
void Disconnect();
|
void _Disconnect();
|
||||||
bool IsConnected() const;
|
bool _IsConnected() const;
|
||||||
|
|
||||||
static int32 QueryThread(void *);
|
static int32 _QueryThread(void *);
|
||||||
|
|
||||||
// cached retrieved data
|
// cached retrieved data
|
||||||
enum State
|
enum State {
|
||||||
{
|
|
||||||
kInitial,
|
kInitial,
|
||||||
kReading,
|
kReading,
|
||||||
kDone,
|
kDone,
|
||||||
kInterrupting,
|
kInterrupting,
|
||||||
kError
|
kError
|
||||||
};
|
};
|
||||||
void SetDefaultInfo(void);
|
|
||||||
status_t OpenContentFile(const int32 &discID);
|
|
||||||
|
|
||||||
status_t ReadFromServer(BString &data);
|
void _SetDefaultInfo();
|
||||||
void ParseData(const BString &data);
|
status_t _OpenContentFile(const int32 &discID);
|
||||||
void WriteFile(void);
|
|
||||||
|
|
||||||
void ReadLine(BString &);
|
status_t _ReadFromServer(BString &data);
|
||||||
status_t IdentifySelf();
|
void _ParseData(const BString &data);
|
||||||
|
void _WriteFile();
|
||||||
|
|
||||||
const char * GetToken(const char *, BString &);
|
void _ReadLine(BString &);
|
||||||
|
status_t _IdentifySelf();
|
||||||
|
|
||||||
|
const char* _GetToken(const char*, BString &);
|
||||||
|
|
||||||
// state data
|
// state data
|
||||||
BString fServerName;
|
BString fServerName;
|
||||||
@@ -146,4 +209,4 @@ private:
|
|||||||
|
|
||||||
BString GetLineFromString(const char *string);
|
BString GetLineFromString(const char *string);
|
||||||
|
|
||||||
#endif
|
#endif // CDDBSUPPORT_H
|
||||||
|
|||||||
+187
-177
@@ -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.
|
* Distributed under the terms of the MIT license.
|
||||||
*
|
*
|
||||||
* Author:
|
* 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 <Alert.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
|
#include <BitmapStream.h>
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
@@ -17,20 +26,14 @@
|
|||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
|
#include <TranslatorFormats.h>
|
||||||
|
#include <TranslatorRoster.h>
|
||||||
|
#include <TranslationUtils.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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 {
|
enum {
|
||||||
M_STOP = 'mstp',
|
M_STOP = 'mstp',
|
||||||
@@ -47,21 +50,25 @@ enum {
|
|||||||
M_SET_CD_TITLE
|
M_SET_CD_TITLE
|
||||||
};
|
};
|
||||||
|
|
||||||
class CDPlayerWindow : public BWindow
|
|
||||||
{
|
class CDPlayerWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
CDPlayerWindow(void);
|
CDPlayerWindow();
|
||||||
bool QuitRequested(void);
|
bool QuitRequested();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
SetLabel(BStringView *label, const char *text)
|
SetLabel(BStringView *label, const char *text)
|
||||||
{
|
{
|
||||||
if (strcmp(label->Text(),text) != 0)
|
if (strcmp(label->Text(), text) != 0)
|
||||||
label->SetText(text);
|
label->SetText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
CDPlayer::CDPlayer(BRect frame, const char *name, uint32 resizeMask, uint32 flags)
|
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")
|
fCDQuery("freedb.freedb.org")
|
||||||
@@ -73,9 +80,9 @@ CDPlayer::CDPlayer(BRect frame, const char *name, uint32 resizeMask, uint32 flag
|
|||||||
BuildGUI();
|
BuildGUI();
|
||||||
|
|
||||||
if (fCDDrive.CountDrives() < 1) {
|
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"
|
" on your computer or there is no system software"
|
||||||
" to support one. Sorry.","OK");
|
" to support one. Sorry.", "OK");
|
||||||
alert->Go();
|
alert->Go();
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
}
|
}
|
||||||
@@ -86,7 +93,7 @@ CDPlayer::CDPlayer(BRect frame, const char *name, uint32 resizeMask, uint32 flag
|
|||||||
fCDDrive.SetVolume(255);
|
fCDDrive.SetVolume(255);
|
||||||
fVolumeSlider->SetValue(255);
|
fVolumeSlider->SetValue(255);
|
||||||
}
|
}
|
||||||
WatchCDState();
|
_WatchCDState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +104,7 @@ CDPlayer::~CDPlayer()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDPlayer::BuildGUI(void)
|
CDPlayer::BuildGUI()
|
||||||
{
|
{
|
||||||
fStopColor.red = 80;
|
fStopColor.red = 80;
|
||||||
fStopColor.green = 164;
|
fStopColor.green = 164;
|
||||||
@@ -109,15 +116,15 @@ CDPlayer::BuildGUI(void)
|
|||||||
fPlayColor.blue = 40;
|
fPlayColor.blue = 40;
|
||||||
fPlayColor.alpha = 255;
|
fPlayColor.alpha = 255;
|
||||||
|
|
||||||
BRect r(Bounds().InsetByCopy(10,10));
|
BRect r(Bounds().InsetByCopy(10, 10));
|
||||||
BBox *box = new BBox(r,"",B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
BBox *box = new BBox(r, "", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
||||||
AddChild(box);
|
AddChild(box);
|
||||||
|
|
||||||
r = box->Bounds().InsetByCopy(10,10);
|
r = box->Bounds().InsetByCopy(10, 10);
|
||||||
r.bottom = 25;
|
r.bottom = 25;
|
||||||
|
|
||||||
float labelWidth, labelHeight;
|
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->GetPreferredSize(&labelWidth, &labelHeight);
|
||||||
fCDTitle->ResizeTo(r.Width(), labelHeight);
|
fCDTitle->ResizeTo(r.Width(), labelHeight);
|
||||||
box->AddChild(fCDTitle);
|
box->AddChild(fCDTitle);
|
||||||
@@ -125,73 +132,71 @@ CDPlayer::BuildGUI(void)
|
|||||||
r.bottom = r.top + labelHeight;
|
r.bottom = r.top + labelHeight;
|
||||||
r.OffsetBy(0, r.Height() + 5);
|
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);
|
box->AddChild(fCurrentTrack);
|
||||||
|
|
||||||
r.OffsetBy(0, r.Height() + 5);
|
r.OffsetBy(0, r.Height() + 5);
|
||||||
r.right = r.left + (r.Width() / 2);
|
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);
|
box->AddChild(fTrackTime);
|
||||||
|
|
||||||
r.OffsetTo(box->Bounds().right / 2, r.top);
|
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->ResizeToPreferred();
|
||||||
fDiscTime->ResizeBy(10,0);
|
fDiscTime->ResizeBy(10, 0);
|
||||||
box->AddChild(fDiscTime);
|
box->AddChild(fDiscTime);
|
||||||
|
|
||||||
box->ResizeTo(fCDTitle->Frame().right + 5, fDiscTime->Frame().bottom + 10);
|
box->ResizeTo(fCDTitle->Frame().right + 5, fDiscTime->Frame().bottom + 10);
|
||||||
|
|
||||||
fStop = new DrawButton(BRect(0,0,1,1), "Stop",
|
fStop = new DrawButton(BRect(0, 0, 1, 1), "Stop",
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_up"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "stop_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"stop_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "stop_down"),
|
||||||
new BMessage(M_STOP), B_FOLLOW_BOTTOM, B_WILL_DRAW);
|
new BMessage(M_STOP), B_FOLLOW_BOTTOM, B_WILL_DRAW);
|
||||||
fStop->ResizeToPreferred();
|
fStop->ResizeToPreferred();
|
||||||
fStop->MoveTo(10, box->Frame().bottom + 15);
|
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);
|
AddChild(fStop);
|
||||||
float stopTop = fStop->Frame().top;
|
float stopTop = fStop->Frame().top;
|
||||||
|
|
||||||
|
|
||||||
fPlay = new TwoStateDrawButton(BRect(0,0,1,1), "Play",
|
fPlay = new TwoStateDrawButton(BRect(0, 0, 1, 1), "Play",
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up_on"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_up_on"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"),
|
||||||
new BMessage(M_PLAY), B_FOLLOW_NONE, B_WILL_DRAW);
|
new BMessage(M_PLAY), B_FOLLOW_NONE, B_WILL_DRAW);
|
||||||
|
|
||||||
fPlay->ResizeToPreferred();
|
fPlay->ResizeToPreferred();
|
||||||
fPlay->MoveTo(fStop->Frame().right + 2, stopTop);
|
fPlay->MoveTo(fStop->Frame().right + 2, stopTop);
|
||||||
AddChild(fPlay);
|
AddChild(fPlay);
|
||||||
|
|
||||||
fPrevTrack = new DrawButton(BRect(0,0,1,1), "PrevTrack",
|
fPrevTrack = new DrawButton(BRect(0, 0, 1, 1), "PrevTrack",
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"prev_up"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "prev_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"prev_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "prev_down"),
|
||||||
new BMessage(M_PREV_TRACK), 0,
|
new BMessage(M_PREV_TRACK), 0, B_WILL_DRAW);
|
||||||
B_WILL_DRAW);
|
|
||||||
fPrevTrack->ResizeToPreferred();
|
fPrevTrack->ResizeToPreferred();
|
||||||
fPrevTrack->MoveTo(fPlay->Frame().right + 20, stopTop);
|
fPrevTrack->MoveTo(fPlay->Frame().right + 20, stopTop);
|
||||||
AddChild(fPrevTrack);
|
AddChild(fPrevTrack);
|
||||||
|
|
||||||
fNextTrack = new DrawButton(BRect(0,0,1,1), "NextTrack",
|
fNextTrack = new DrawButton(BRect(0, 0, 1, 1), "NextTrack",
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"next_up"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "next_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"next_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "next_down"),
|
||||||
new BMessage(M_NEXT_TRACK), 0,
|
new BMessage(M_NEXT_TRACK), 0, B_WILL_DRAW);
|
||||||
B_WILL_DRAW);
|
|
||||||
fNextTrack->ResizeToPreferred();
|
fNextTrack->ResizeToPreferred();
|
||||||
fNextTrack->MoveTo(fPrevTrack->Frame().right + 1, stopTop);
|
fNextTrack->MoveTo(fPrevTrack->Frame().right + 1, stopTop);
|
||||||
AddChild(fNextTrack);
|
AddChild(fNextTrack);
|
||||||
|
|
||||||
fRewind = new DoubleShotDrawButton(BRect(0,0,1,1), "Rewind",
|
fRewind = new DoubleShotDrawButton(BRect(0, 0, 1, 1), "Rewind",
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_up"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "rew_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"rew_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "rew_down"),
|
||||||
new BMessage(M_REWIND), 0, B_WILL_DRAW);
|
new BMessage(M_REWIND), 0, B_WILL_DRAW);
|
||||||
fRewind->ResizeToPreferred();
|
fRewind->ResizeToPreferred();
|
||||||
fRewind->MoveTo(fNextTrack->Frame().right + 20, stopTop);
|
fRewind->MoveTo(fNextTrack->Frame().right + 20, stopTop);
|
||||||
AddChild(fRewind);
|
AddChild(fRewind);
|
||||||
|
|
||||||
fFastFwd = new DoubleShotDrawButton(BRect(0,0,1,1), "FastFwd",
|
fFastFwd = new DoubleShotDrawButton(BRect(0, 0, 1, 1), "FastFwd",
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_up"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "ffwd_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"ffwd_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "ffwd_down"),
|
||||||
new BMessage(M_FFWD), 0, B_WILL_DRAW);
|
new BMessage(M_FFWD), 0, B_WILL_DRAW);
|
||||||
fFastFwd->ResizeToPreferred();
|
fFastFwd->ResizeToPreferred();
|
||||||
fFastFwd->MoveTo(fRewind->Frame().right + 1, stopTop);
|
fFastFwd->MoveTo(fRewind->Frame().right + 1, stopTop);
|
||||||
@@ -201,43 +206,41 @@ CDPlayer::BuildGUI(void)
|
|||||||
r.right = fPlay->Frame().right;
|
r.right = fPlay->Frame().right;
|
||||||
r.top = fStop->Frame().bottom + 14;
|
r.top = fStop->Frame().bottom + 14;
|
||||||
r.bottom = r.top + kVolumeSliderBitmapHeight - 1.0;
|
r.bottom = r.top + kVolumeSliderBitmapHeight - 1.0;
|
||||||
fVolumeSlider = new VolumeSlider(r,"VolumeSlider",0,255, new BMessage(M_SET_VOLUME),
|
fVolumeSlider = new VolumeSlider(r, "VolumeSlider",
|
||||||
this);
|
0, 255, new BMessage(M_SET_VOLUME), this);
|
||||||
fVolumeSlider->ResizeToPreferred();
|
fVolumeSlider->ResizeToPreferred();
|
||||||
AddChild(fVolumeSlider);
|
AddChild(fVolumeSlider);
|
||||||
|
|
||||||
fRepeat = new TwoStateDrawButton( BRect(0,0,1,1), "Repeat",
|
fRepeat = new TwoStateDrawButton(BRect(0, 0, 1, 1), "Repeat",
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_up_off"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "repeat_up_off"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "repeat_down"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_up_on"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "repeat_up_on"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"repeat_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "repeat_down"),
|
||||||
new BMessage(M_REPEAT), B_FOLLOW_NONE, B_WILL_DRAW);
|
new BMessage(M_REPEAT), B_FOLLOW_NONE, B_WILL_DRAW);
|
||||||
fRepeat->ResizeToPreferred();
|
fRepeat->ResizeToPreferred();
|
||||||
fRepeat->MoveTo(fPrevTrack->Frame().left,
|
fRepeat->MoveTo(fPrevTrack->Frame().left, fVolumeSlider->Frame().top -
|
||||||
fVolumeSlider->Frame().top -
|
|
||||||
((fRepeat->Frame().Height() - fVolumeSlider->Frame().Height()) / 2));
|
((fRepeat->Frame().Height() - fVolumeSlider->Frame().Height()) / 2));
|
||||||
AddChild(fRepeat);
|
AddChild(fRepeat);
|
||||||
|
|
||||||
fShuffle = new TwoStateDrawButton(BRect(0,0,1,1), "Shuffle",
|
fShuffle = new TwoStateDrawButton(BRect(0, 0, 1, 1), "Shuffle",
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_up_off"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "shuffle_up_off"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "shuffle_down"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_up_on"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "shuffle_up_on"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"shuffle_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "shuffle_down"),
|
||||||
new BMessage(M_SHUFFLE), B_FOLLOW_NONE, B_WILL_DRAW);
|
new BMessage(M_SHUFFLE), B_FOLLOW_NONE, B_WILL_DRAW);
|
||||||
fShuffle->ResizeToPreferred();
|
fShuffle->ResizeToPreferred();
|
||||||
fShuffle->MoveTo(fRepeat->Frame().right + 2,fRepeat->Frame().top);
|
fShuffle->MoveTo(fRepeat->Frame().right + 2, fRepeat->Frame().top);
|
||||||
AddChild(fShuffle);
|
AddChild(fShuffle);
|
||||||
|
|
||||||
fEject = new DrawButton(BRect(0,0,1,1), "Eject",
|
fEject = new DrawButton(BRect(0, 0, 1, 1), "Eject",
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"eject_up"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "eject_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"eject_down"),
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "eject_down"),
|
||||||
new BMessage(M_EJECT), 0, B_WILL_DRAW);
|
new BMessage(M_EJECT), 0, B_WILL_DRAW);
|
||||||
fEject->ResizeToPreferred();
|
fEject->ResizeToPreferred();
|
||||||
fEject->MoveTo(fFastFwd->Frame().left, fShuffle->Frame().top);
|
fEject->MoveTo(fFastFwd->Frame().left, fShuffle->Frame().top);
|
||||||
AddChild(fEject);
|
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)
|
CDPlayer::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case M_SET_VOLUME: {
|
case M_SET_VOLUME:
|
||||||
fCDDrive.SetVolume(fVolumeSlider->Value());
|
fCDDrive.SetVolume(fVolumeSlider->Value());
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case M_STOP: {
|
case M_STOP:
|
||||||
if (fWindowState == kPaused) {
|
if (fWindowState == kPaused) {
|
||||||
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"),
|
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"));
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"));
|
||||||
fPlay->SetState(1);
|
fPlay->SetState(1);
|
||||||
}
|
}
|
||||||
fWindowState = kStopped;
|
fWindowState = kStopped;
|
||||||
fCDDrive.Stop();
|
fCDDrive.Stop();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case M_PLAY: {
|
case M_PLAY:
|
||||||
// If we are currently playing, then we will be showing
|
// If we are currently playing, then we will be showing
|
||||||
// the pause images and will want to switch back to the play images
|
// the pause images and will want to switch back to the play images
|
||||||
if (fWindowState == kPlaying) {
|
if (fWindowState == kPlaying) {
|
||||||
fWindowState = kPaused;
|
fWindowState = kPaused;
|
||||||
fCDDrive.Pause();
|
fCDDrive.Pause();
|
||||||
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT,"paused_up"),
|
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT, "paused_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"));
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"));
|
||||||
} else if (fWindowState == kPaused) {
|
} else if (fWindowState == kPaused) {
|
||||||
fWindowState = kPlaying;
|
fWindowState = kPlaying;
|
||||||
fCDDrive.Resume();
|
fCDDrive.Resume();
|
||||||
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_up"),
|
fPlay->SetBitmaps(0, BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_up"),
|
||||||
BTranslationUtils::GetBitmap(B_PNG_FORMAT,"play_down"));
|
BTranslationUtils::GetBitmap(B_PNG_FORMAT, "play_down"));
|
||||||
} else {
|
} else {
|
||||||
fWindowState = kPlaying;
|
fWindowState = kPlaying;
|
||||||
fCDDrive.Play(fPlayList.GetCurrentTrack());
|
fCDDrive.Play(fPlayList.GetCurrentTrack());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case M_EJECT: {
|
case M_EJECT:
|
||||||
fCDDrive.Eject();
|
fCDDrive.Eject();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case M_NEXT_TRACK: {
|
case M_NEXT_TRACK:
|
||||||
|
{
|
||||||
int16 next = fPlayList.GetNextTrack();
|
int16 next = fPlayList.GetNextTrack();
|
||||||
if (next <= 0) {
|
if (next <= 0) {
|
||||||
// force a "wrap around" when possible. This makes it
|
// force a "wrap around" when possible. This makes it
|
||||||
@@ -294,7 +298,7 @@ CDPlayer::MessageReceived(BMessage *msg)
|
|||||||
if (next > 0) {
|
if (next > 0) {
|
||||||
CDState state = fCDDrive.GetState();
|
CDState state = fCDDrive.GetState();
|
||||||
if (state == kPlaying) {
|
if (state == kPlaying) {
|
||||||
while(!fCDDrive.Play(next)) {
|
while (!fCDDrive.Play(next)) {
|
||||||
next = fPlayList.GetNextTrack();
|
next = fPlayList.GetNextTrack();
|
||||||
if (next < 1) {
|
if (next < 1) {
|
||||||
fWindowState = kStopped;
|
fWindowState = kStopped;
|
||||||
@@ -312,11 +316,13 @@ CDPlayer::MessageReceived(BMessage *msg)
|
|||||||
fPlayList.SetCurrentTrack(next);
|
fPlayList.SetCurrentTrack(next);
|
||||||
|
|
||||||
// Force an update for better responsiveness
|
// Force an update for better responsiveness
|
||||||
WatchCDState();
|
_WatchCDState();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case M_PREV_TRACK: {
|
|
||||||
|
case M_PREV_TRACK:
|
||||||
|
{
|
||||||
int16 prev = fPlayList.GetPreviousTrack();
|
int16 prev = fPlayList.GetPreviousTrack();
|
||||||
if (prev <= 0) {
|
if (prev <= 0) {
|
||||||
// force a "wrap around" when possible. This makes it
|
// force a "wrap around" when possible. This makes it
|
||||||
@@ -328,7 +334,7 @@ CDPlayer::MessageReceived(BMessage *msg)
|
|||||||
if (prev > 0) {
|
if (prev > 0) {
|
||||||
CDState state = fCDDrive.GetState();
|
CDState state = fCDDrive.GetState();
|
||||||
if (state == kPlaying) {
|
if (state == kPlaying) {
|
||||||
while(!fCDDrive.Play(prev)) {
|
while (!fCDDrive.Play(prev)) {
|
||||||
prev = fPlayList.GetPreviousTrack();
|
prev = fPlayList.GetPreviousTrack();
|
||||||
if (prev < 1) {
|
if (prev < 1) {
|
||||||
fWindowState = kStopped;
|
fWindowState = kStopped;
|
||||||
@@ -344,25 +350,26 @@ CDPlayer::MessageReceived(BMessage *msg)
|
|||||||
fPlayList.SetCurrentTrack(prev);
|
fPlayList.SetCurrentTrack(prev);
|
||||||
|
|
||||||
// Force an update for better responsiveness
|
// Force an update for better responsiveness
|
||||||
WatchCDState();
|
_WatchCDState();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case M_FFWD: {
|
|
||||||
|
case M_FFWD:
|
||||||
if (fFastFwd->Value() == B_CONTROL_ON)
|
if (fFastFwd->Value() == B_CONTROL_ON)
|
||||||
fCDDrive.StartFastFwd();
|
fCDDrive.StartFastFwd();
|
||||||
else
|
else
|
||||||
fCDDrive.StopFastFwd();
|
fCDDrive.StopFastFwd();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case M_REWIND: {
|
case M_REWIND:
|
||||||
if (fRewind->Value() == B_CONTROL_ON)
|
if (fRewind->Value() == B_CONTROL_ON)
|
||||||
fCDDrive.StartRewind();
|
fCDDrive.StartRewind();
|
||||||
else
|
else
|
||||||
fCDDrive.StopRewind();
|
fCDDrive.StopRewind();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case M_SHUFFLE: {
|
case M_SHUFFLE:
|
||||||
if (fPlayList.IsShuffled()) {
|
if (fPlayList.IsShuffled()) {
|
||||||
int16 track = fPlayList.GetCurrentTrack();
|
int16 track = fPlayList.GetCurrentTrack();
|
||||||
fPlayList.SetShuffle(false);
|
fPlayList.SetShuffle(false);
|
||||||
@@ -375,8 +382,8 @@ CDPlayer::MessageReceived(BMessage *msg)
|
|||||||
fShuffle->SetState(1);
|
fShuffle->SetState(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case M_REPEAT: {
|
case M_REPEAT:
|
||||||
if (fPlayList.IsLoop()) {
|
if (fPlayList.IsLoop()) {
|
||||||
fPlayList.SetLoop(false);
|
fPlayList.SetLoop(false);
|
||||||
fRepeat->SetState(0);
|
fRepeat->SetState(0);
|
||||||
@@ -385,11 +392,11 @@ CDPlayer::MessageReceived(BMessage *msg)
|
|||||||
fRepeat->SetState(1);
|
fRepeat->SetState(1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default: {
|
default:
|
||||||
BView::MessageReceived(msg);
|
BView::MessageReceived(msg);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,27 +419,27 @@ CDPlayer::AttachedToWindow()
|
|||||||
void
|
void
|
||||||
CDPlayer::Pulse()
|
CDPlayer::Pulse()
|
||||||
{
|
{
|
||||||
WatchCDState();
|
_WatchCDState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CDPlayer::WatchCDState(void)
|
CDPlayer::_WatchCDState()
|
||||||
{
|
{
|
||||||
// One watcher function to rule them all
|
// One watcher function to rule them all
|
||||||
|
|
||||||
// first, watch the one setting independent of having a CD: volume
|
// first, watch the one setting independent of having a CD: volume
|
||||||
uint8 drivevolume = fCDDrive.GetVolume();
|
uint8 driveVolume = fCDDrive.GetVolume();
|
||||||
if (fVolume == drivevolume) {
|
if (fVolume == driveVolume) {
|
||||||
fVolume = drivevolume;
|
fVolume = driveVolume;
|
||||||
fVolumeSlider->SetValue(fVolume);
|
fVolumeSlider->SetValue(fVolume);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second, establish whether or not we have a CD in the drive
|
// Second, establish whether or not we have a CD in the drive
|
||||||
CDState playstate = fCDDrive.GetState();
|
CDState playState = fCDDrive.GetState();
|
||||||
bool internal_track_change = false;
|
bool internalTrackChange = false;
|
||||||
|
|
||||||
if (playstate == kNoCD) {
|
if (playState == kNoCD) {
|
||||||
// Yes, we have no bananas!
|
// Yes, we have no bananas!
|
||||||
|
|
||||||
// Do something only if there is a change in the app's play state
|
// Do something only if there is a change in the app's play state
|
||||||
@@ -442,11 +449,11 @@ CDPlayer::WatchCDState(void)
|
|||||||
|
|
||||||
// Because we are changing play states, we will need to update the GUI
|
// Because we are changing play states, we will need to update the GUI
|
||||||
fCDData.SetDiscID(-1);
|
fCDData.SetDiscID(-1);
|
||||||
SetLabel(fCDTitle,"CD drive is empty");
|
SetLabel(fCDTitle, "CD drive is empty");
|
||||||
|
|
||||||
SetLabel(fCurrentTrack,"");
|
SetLabel(fCurrentTrack, "");
|
||||||
SetLabel(fTrackTime,"Track: --:-- / --:--");
|
SetLabel(fTrackTime, "Track: --:-- / --:--");
|
||||||
SetLabel(fDiscTime,"Disc: --:-- / --:--");
|
SetLabel(fDiscTime, "Disc: --:-- / --:--");
|
||||||
fPlayList.SetTrackCount(0);
|
fPlayList.SetTrackCount(0);
|
||||||
fPlayList.SetStartingTrack(1);
|
fPlayList.SetStartingTrack(1);
|
||||||
fPlayList.SetCurrentTrack(1);
|
fPlayList.SetCurrentTrack(1);
|
||||||
@@ -459,9 +466,9 @@ CDPlayer::WatchCDState(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now otherwise handle the play state
|
// Now otherwise handle the play state
|
||||||
if (playstate == kStopped) {
|
if (playState == kStopped) {
|
||||||
if (fWindowState == kPlaying) {
|
if (fWindowState == kPlaying) {
|
||||||
internal_track_change = true;
|
internalTrackChange = true;
|
||||||
|
|
||||||
// This means that the drive finished playing the song, so get the next one
|
// This means that the drive finished playing the song, so get the next one
|
||||||
// from the list and play it
|
// from the list and play it
|
||||||
@@ -472,23 +479,22 @@ CDPlayer::WatchCDState(void)
|
|||||||
|
|
||||||
if (fPlay->GetState() == 1)
|
if (fPlay->GetState() == 1)
|
||||||
fPlay->SetState(0);
|
fPlay->SetState(0);
|
||||||
} else if (playstate == kPlaying) {
|
} else if (playState == kPlaying) {
|
||||||
if (fPlay->GetState() == 0)
|
if (fPlay->GetState() == 0)
|
||||||
fPlay->SetState(1);
|
fPlay->SetState(1);
|
||||||
} else if (playstate == kPaused) {
|
} else if (playState == kPaused)
|
||||||
fPlay->SetState(0);
|
fPlay->SetState(0);
|
||||||
}
|
|
||||||
|
|
||||||
// If we got this far, then there must be a CD in the drive. The next order on the agenda
|
// 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
|
// is to find out which CD it is
|
||||||
int32 discid = fCDDrive.GetDiscID();
|
int32 discId = fCDDrive.GetDiscID();
|
||||||
bool update_track_gui = false;
|
bool updateTrackGui = false;
|
||||||
|
|
||||||
if (discid != fCDData.DiscID()) {
|
if (discId != fCDData.DiscID()) {
|
||||||
update_track_gui = true;
|
updateTrackGui = true;
|
||||||
|
|
||||||
// Apparently the disc has changed since we last looked.
|
// Apparently the disc has changed since we last looked.
|
||||||
if (fCDQuery.CurrentDiscID() != discid)
|
if (fCDQuery.CurrentDiscID() != discId)
|
||||||
fCDQuery.SetToCD(fCDDrive.GetDrivePath());
|
fCDQuery.SetToCD(fCDDrive.GetDrivePath());
|
||||||
|
|
||||||
if (fCDQuery.Ready()) {
|
if (fCDQuery.Ready()) {
|
||||||
@@ -497,102 +503,103 @@ CDPlayer::WatchCDState(void)
|
|||||||
if (fCDQuery.GetData(&fCDData, 1000000)) {
|
if (fCDQuery.GetData(&fCDData, 1000000)) {
|
||||||
BString display(fCDData.Artist());
|
BString display(fCDData.Artist());
|
||||||
display << " - " << fCDData.Album();
|
display << " - " << fCDData.Album();
|
||||||
SetLabel(fCDTitle,display.String());
|
SetLabel(fCDTitle, display.String());
|
||||||
} else {
|
} else
|
||||||
SetLabel(fCDTitle,"Audio CD");
|
SetLabel(fCDTitle, "Audio CD");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now that we know which CD it is, update the track info
|
// Now that we know which CD it is, update the track info
|
||||||
int16 drivecount = fCDDrive.CountTracks();
|
int16 driveCount = fCDDrive.CountTracks();
|
||||||
int16 drivetrack = fCDDrive.GetTrack();
|
int16 driveTrack = fCDDrive.GetTrack();
|
||||||
|
|
||||||
int16 playlisttrack = fPlayList.GetCurrentTrack();
|
int16 playlistTrack = fPlayList.GetCurrentTrack();
|
||||||
int16 playlistcount = fPlayList.TrackCount();
|
int16 playlistCount = fPlayList.TrackCount();
|
||||||
|
|
||||||
if (playstate == kPlaying) {
|
if (playState == kPlaying) {
|
||||||
if (playlisttrack != drivetrack) {
|
if (playlistTrack != driveTrack) {
|
||||||
playlisttrack = drivetrack;
|
playlistTrack = driveTrack;
|
||||||
|
|
||||||
if (!internal_track_change) {
|
if (!internalTrackChange) {
|
||||||
// The main thing is that we need to make sure that the playlist and the drive's track
|
// 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
|
// 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.
|
// the drive is playing, check for playlist sync.
|
||||||
fPlayList.SetTrackCount(drivecount);
|
fPlayList.SetTrackCount(driveCount);
|
||||||
fPlayList.SetCurrentTrack(drivetrack);
|
fPlayList.SetCurrentTrack(driveTrack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
update_track_gui = true;
|
updateTrackGui = true;
|
||||||
} else {
|
} else {
|
||||||
if (playlistcount != drivecount) {
|
if (playlistCount != driveCount) {
|
||||||
// This happens only when CDs are changed
|
// 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
|
// 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.
|
// count set to 0 and it also needs to be rewound.
|
||||||
fPlayList.SetStartingTrack(1);
|
fPlayList.SetStartingTrack(1);
|
||||||
fPlayList.SetTrackCount(0);
|
fPlayList.SetTrackCount(0);
|
||||||
playlisttrack = 1;
|
playlistTrack = 1;
|
||||||
playlistcount = 0;
|
playlistCount = 0;
|
||||||
} else {
|
} else {
|
||||||
// Two possible cases here: playlist is empty or playlist has a different
|
// Two possible cases here: playlist is empty or playlist has a different
|
||||||
// number of tracks. In either case, the playlist needs to be reinitialized
|
// number of tracks. In either case, the playlist needs to be reinitialized
|
||||||
// to the current track data
|
// to the current track data
|
||||||
fPlayList.SetStartingTrack(1);
|
fPlayList.SetStartingTrack(1);
|
||||||
fPlayList.SetTrackCount(drivecount);
|
fPlayList.SetTrackCount(driveCount);
|
||||||
playlisttrack = fPlayList.GetCurrentTrack();
|
playlistTrack = fPlayList.GetCurrentTrack();
|
||||||
playlistcount = drivecount;
|
playlistCount = driveCount;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// update only with a track change
|
// update only with a track change
|
||||||
if (playlisttrack != drivetrack)
|
if (playlistTrack != driveTrack)
|
||||||
update_track_gui = true;
|
updateTrackGui = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update_track_gui) {
|
if (updateTrackGui) {
|
||||||
BString currentTrackName;
|
BString currentTrackName;
|
||||||
|
|
||||||
if (playlisttrack >= 0) {
|
if (playlistTrack >= 0) {
|
||||||
int16 whichtrack = playlisttrack;
|
int16 whichTrack = playlistTrack;
|
||||||
|
|
||||||
if (whichtrack == 0)
|
if (whichTrack == 0)
|
||||||
whichtrack++;
|
whichTrack++;
|
||||||
|
|
||||||
currentTrackName << "Track " << whichtrack << ": " << fCDData.TrackAt(whichtrack-1);
|
currentTrackName << "Track " << whichTrack << ": " << fCDData.TrackAt(whichTrack - 1);
|
||||||
|
|
||||||
SetLabel(fCurrentTrack,currentTrackName.String());
|
SetLabel(fCurrentTrack, currentTrackName.String());
|
||||||
|
|
||||||
} else {
|
} else
|
||||||
SetLabel(fCurrentTrack,"");
|
SetLabel(fCurrentTrack, "");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now update the time info
|
// Now update the time info
|
||||||
cdaudio_time tracktime;
|
CDAudioTime trackTime;
|
||||||
cdaudio_time disctime;
|
CDAudioTime discTime;
|
||||||
cdaudio_time tracktotal;
|
CDAudioTime trackTotal;
|
||||||
cdaudio_time disctotal;
|
CDAudioTime discTotal;
|
||||||
char timestring[1024];
|
char timeString[1024];
|
||||||
|
|
||||||
if (fCDDrive.GetTime(tracktime, disctime)) {
|
if (fCDDrive.GetTime(trackTime, discTime)) {
|
||||||
fCDDrive.GetTimeForDisc(disctotal);
|
fCDDrive.GetTimeForDisc(discTotal);
|
||||||
sprintf(timestring,"Disc: %ld:%.2ld / %ld:%.2ld",disctime.minutes,disctime.seconds,
|
sprintf(timeString, "Disc: %ld:%.2ld / %ld:%.2ld", discTime.GetMinutes(),
|
||||||
disctotal.minutes,disctotal.seconds);
|
discTime.GetSeconds(), discTotal.GetMinutes(), discTotal.GetSeconds());
|
||||||
SetLabel(fDiscTime,timestring);
|
SetLabel(fDiscTime, timeString);
|
||||||
|
|
||||||
fCDDrive.GetTimeForTrack(playlisttrack,tracktotal);
|
fCDDrive.GetTimeForTrack(playlistTrack, trackTotal);
|
||||||
sprintf(timestring,"Track: %ld:%.2ld / %ld:%.2ld",tracktime.minutes,tracktime.seconds,
|
sprintf(timeString, "Track: %ld:%.2ld / %ld:%.2ld", trackTime.GetMinutes(),
|
||||||
tracktotal.minutes,tracktotal.seconds);
|
trackTime.GetSeconds(), trackTotal.GetMinutes(), trackTotal.GetSeconds());
|
||||||
SetLabel(fTrackTime,timestring);
|
SetLabel(fTrackTime, timeString);
|
||||||
} else {
|
} else {
|
||||||
SetLabel(fTrackTime,"Track: --:-- / --:--");
|
SetLabel(fTrackTime, "Track: --:-- / --:--");
|
||||||
SetLabel(fDiscTime,"Disc: --:-- / --:--");
|
SetLabel(fDiscTime, "Disc: --:-- / --:--");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CDPlayerWindow::CDPlayerWindow(void)
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
CDPlayerWindow::CDPlayerWindow()
|
||||||
: BWindow(BRect (100, 100, 405, 280), "CD Player", B_TITLED_WINDOW, B_NOT_RESIZABLE |
|
: BWindow(BRect (100, 100, 405, 280), "CD Player", B_TITLED_WINDOW, B_NOT_RESIZABLE |
|
||||||
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
|
B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS)
|
||||||
{
|
{
|
||||||
@@ -600,13 +607,16 @@ CDPlayerWindow::CDPlayerWindow(void)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
CDPlayerWindow::QuitRequested(void)
|
CDPlayerWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
CDPlayerApplication::CDPlayerApplication()
|
CDPlayerApplication::CDPlayerApplication()
|
||||||
: BApplication("application/x-vnd.Haiku-CDPlayer")
|
: BApplication("application/x-vnd.Haiku-CDPlayer")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,40 +7,38 @@
|
|||||||
#ifndef CDPLAYER_H
|
#ifndef CDPLAYER_H
|
||||||
#define 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 "CDAudioDevice.h"
|
||||||
#include "CDDBSupport.h"
|
#include "CDDBSupport.h"
|
||||||
#include "PlayList.h"
|
#include "PlayList.h"
|
||||||
#include "VolumeSlider.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 DrawButton;
|
||||||
class DoubleShotDrawButton;
|
class DoubleShotDrawButton;
|
||||||
class TwoStateDrawButton;
|
class TwoStateDrawButton;
|
||||||
|
|
||||||
class CDPlayer : public BView
|
|
||||||
{
|
class CDPlayer : public BView {
|
||||||
public:
|
public:
|
||||||
CDPlayer(BRect frame, const char *name,
|
CDPlayer(BRect frame, const char *name, uint32 resizeMask = B_FOLLOW_ALL,
|
||||||
uint32 resizeMask = B_FOLLOW_ALL,
|
uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_PULSE_NEEDED);
|
||||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE |
|
|
||||||
B_PULSE_NEEDED);
|
|
||||||
virtual ~CDPlayer();
|
virtual ~CDPlayer();
|
||||||
|
|
||||||
void BuildGUI(void);
|
void BuildGUI();
|
||||||
|
|
||||||
virtual void AttachedToWindow();
|
virtual void AttachedToWindow();
|
||||||
virtual void Pulse();
|
virtual void Pulse();
|
||||||
virtual void MessageReceived(BMessage *);
|
virtual void MessageReceived(BMessage *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WatchCDState(void);
|
void _WatchCDState();
|
||||||
|
|
||||||
DrawButton *fStop,
|
DrawButton *fStop,
|
||||||
*fNextTrack,
|
*fNextTrack,
|
||||||
@@ -80,11 +78,10 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class CDPlayerApplication : public BApplication
|
class CDPlayerApplication : public BApplication {
|
||||||
{
|
public:
|
||||||
public:
|
|
||||||
CDPlayerApplication();
|
CDPlayerApplication();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif // CDPLAYER_H
|
||||||
|
|||||||
Reference in New Issue
Block a user