home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
MMSTEREO
/
MLTCD.CPP
< prev
next >
Wrap
Text File
|
1995-05-01
|
14KB
|
330 lines
#include "mltcd.hpp"
/*------------------------------------------------------------------------------
| CD::CD |
| |
| |
------------------------------------------------------------------------------*/
CD::CD( IMMAudioCD* cd,
unsigned long windowid,
IWindow* parent,
IWindow* owner)
: IMMPlayerPanel(windowid,parent,owner,IMMDevice::audioCD),
readout (READOUTID, this,this),
discReadout (DISCREADOUTID, this,this),
name (CDNAMEID, this, this),
pCDPlayer(cd),
observer(0),
handler(0)
{
setPlayableDevice(pCDPlayer);
eject = new IAnimatedButton(EJECTID,this,this,IRectangle(),
ICustomButton::autoLatch |
IWindow::visible | IAnimatedButton::animateWhenLatched);
trackF= new IAnimatedButton(TRACKFID,this,this,IRectangle(),
IWindow::visible | IAnimatedButton::animateWhenLatched);
trackB= new IAnimatedButton(TRACKBID,this,this,IRectangle(),
IWindow::visible | IAnimatedButton::animateWhenLatched);
scanF = new IAnimatedButton(SCANFID,this,this,IRectangle(),
ICustomButton::autoLatch |
ICustomButton::latchable |
IWindow::visible | IAnimatedButton::animateWhenLatched);
scanB = new IAnimatedButton(SCANBID,this,this,IRectangle(),
ICustomButton::autoLatch |
ICustomButton::latchable |
IWindow::visible | IAnimatedButton::animateWhenLatched);
//Add the additional buttons to the player panel.
addToCell(trackB , 7, 1, 1, 1);
addToCell(trackF , 8, 1, 1, 1);
addToCell(scanB , 10, 1, 1, 1);
addToCell(scanF , 11, 1, 1, 1);
addToCell(&readout , 13, 1, 1, 2);
addToCell(&discReadout ,13, 3, 1, 1);
addToCell(eject , 15, 1, 1, 1);
addToCell(&name , 2, 3, 5, 1);
setRowHeight(4,4);
//Put the bitmaps on the buttons.
trackB->setBitmaps(IAnimatedButton::trackReverse);
trackF->setBitmaps(IAnimatedButton::trackAdvance);
scanB->setBitmaps(IAnimatedButton::scanBackward);
scanF->setBitmaps(IAnimatedButton::scanForward);
eject->setBitmaps(IAnimatedButton::eject);
//Put text on the buttons. The \n cause the
//following text to be on a new line.
//trackB->setText("Track\nReverse");
//trackF->setText("Track\nAdvance");
//scanB->setText("Scan\nBackward");
//scanF->setText("Scan\nForward");
//eject->setText("Eject&Load");
//Set up the title
name.setText("Class Library CD Player");
name.setForegroundColor(IColor(IColor::red));
//Set up the display
IFont("LED",10).setWindowFont(&readout);
readout.setForegroundColor(IColor(0,160,0));
readout.setBackgroundColor(IColor(IColor::black));
readout.setText("TRACK 00 MIN:SEC 00:00");
readout.setLimit(24);
//Set up the disc and track display
discReadout.setForegroundColor(IColor(0,160,0));
discReadout.setBackgroundColor(IColor(IColor::black));
discReadout.setLimit(24);
discReadout.setText("No CD Title: No Track Title");
if (pCDPlayer)
{
handler = new CDHandler();
handler->handleEventsFor(this);
observer = new CDObserver(*this);
observer->handleNotificationsFor(*pCDPlayer);
if (!pCDPlayer->isMediaPresent())
{
disable();
eject->latch();
discReadout.setText("Insert an Audio CD");
}
}
else
discReadout.setText("Could Not Open CD Device");
}
/*------------------------------------------------------------------------------
| CD::~CD |
| |
| |
------------------------------------------------------------------------------*/
CD::~CD()
{
if (observer)
observer->stopHandlingNotificationsFor(*pCDPlayer);
if (handler)
handler->stopHandlingEventsFor(this);
}
/*------------------------------------------------------------------------------
| CD::scanForwardButton |
| |
| |
------------------------------------------------------------------------------*/
IAnimatedButton* CD::scanForwardButton () const
{
return scanF;
}
/*------------------------------------------------------------------------------
| CD::scanBackwardButton |
| |
| |
------------------------------------------------------------------------------*/
IAnimatedButton* CD::scanBackwardButton () const
{
return scanB;
}
/*------------------------------------------------------------------------------
| CD::ejectButton |
| |
| |
------------------------------------------------------------------------------*/
IAnimatedButton* CD::ejectButton () const
{
return eject;
}
/*------------------------------------------------------------------------------
| CD::CDPlayer |
| |
| |
------------------------------------------------------------------------------*/
IMMAudioCD* CD::cdPlayer () const
{
return pCDPlayer;
}
/*------------------------------------------------------------------------------
| CDHandler::CDHandler |
| |
| |
------------------------------------------------------------------------------*/
CDHandler::CDHandler()
: CDHandler::Inherited()
{}
/*------------------------------------------------------------------------------
| CDHandler::command |
| |
------------------------------------------------------------------------------*/
Boolean CDHandler::command(ICommandEvent& event)
{
Boolean handled = false;
CD* panel = 0;
switch (event.commandId())
{
case EJECTID:
panel = (CD*) (event.window());
if (panel->cdPlayer())
if (panel->cdPlayer()->isMediaPresent())
panel->cdPlayer()->openDoor();
handled=true;
break;
case TRACKBID:
panel = (CD*) (event.window());
panel->cdPlayer()->trackBackward();
handled=true;
break;
case TRACKFID:
panel = (CD*) (event.window());
panel->cdPlayer()->trackForward();
handled=true;
break;
case SCANFID:
panel = (CD*) (event.window());
if (panel->scanForwardButton()->isLatched())
panel->cdPlayer()->startScanningForward();
else
panel->cdPlayer()->stop();
handled=true;
break;
case SCANBID:
panel = (CD*) (event.window());
if (panel->scanBackwardButton()->isLatched())
panel->cdPlayer()->startScanningBackward();
else
panel->cdPlayer()->stop();
handled=true;
break;
default:
handled = Inherited::command(event);
break;
} /* endswitch */
return handled;
}
/*------------------------------------------------------------------------------
| CDHandler::rewind |
| |
------------------------------------------------------------------------------*/
Boolean CDHandler::rewind(const IMMPlayerPanel& panel)
{
IMMAudioCD* device = (IMMAudioCD*)(panel.playableDevice());
CD* cdpanel = (CD*)(&panel);
Boolean ret = Inherited::rewind(panel);
IMMAudioCDContents contents = device->contents();
IMMTrackMinSecFrameTime time(contents,device->position());
cdpanel->readout.setText(IString("TRACK ") +
IString(time.track()).rightJustify(2,'0') +
IString(" MIN:SEC ") +
IString(time.minutes()).rightJustify(2,'0') +
IString(":") +
IString(time.seconds()).rightJustify(2,'0'));
return ret;
}
/*------------------------------------------------------------------------------
| CDHandler::fastForward |
| |
------------------------------------------------------------------------------*/
Boolean CDHandler::fastForward(const IMMPlayerPanel& panel)
{
IMMAudioCD* device = (IMMAudioCD*)(panel.playableDevice());
CD* cdpanel = (CD*)(&panel);
Boolean ret = Inherited::fastForward(panel);
IMMAudioCDContents contents = device->contents();
IMMTrackMinSecFrameTime time(contents,device->position());
cdpanel->readout.setText(IString("TRACK ") +
IString(time.track()).rightJustify(2,'0') +
IString(" MIN:SEC ") +
IString(time.minutes()).rightJustify(2,'0') +
IString(":") +
IString(time.seconds()).rightJustify(2,'0'));
return ret;
}
/*------------------------------------------------------------------------------
| CDObserver::CDObserver |
| |
| |
------------------------------------------------------------------------------*/
CDObserver::CDObserver(CD& cdPanel)
: CDObserver::Inherited(),
panel(cdPanel)
{}
/*-------------------------------------------------------------------------------
| CDObserver::dispatchNotificationEvent |
| |
| |
------------------------------------------------------------------------------*/
CDObserver& CDObserver::dispatchNotificationEvent(const INotificationEvent& event)
{
if (event.notificationId() == IMMDevice::positionChangeId)
{
IMMPositionChangeEvent* positionEvent = (IMMPositionChangeEvent*)(event.eventData().asUnsignedLong());
IMMAudioCDContents temp = panel.cdPlayer()->contents();
IMMTrackMinSecFrameTime time(temp,positionEvent->position());
panel.readout.setText(IString("TRACK ") +
IString(time.track()).rightJustify(2,'0') +
IString(" MIN:SEC ") +
IString(time.minutes()).rightJustify(2,'0') +
IString(":") +
IString(time.seconds()).rightJustify(2,'0'));
if (!panel.playButton()->isLatched())
panel.playButton()->latch();
} /* endif */
if (event.notificationId() == IMMAudioCD::positionTimerId)
{
IMMTrackMinSecFrameTime* time = (IMMTrackMinSecFrameTime*)(event.eventData().asUnsignedLong());
panel.readout.setText(IString("TRACK ") +
IString(time->track()).rightJustify(2,'0') +
IString(" MIN:SEC ") +
IString(time->minutes()).rightJustify(2,'0') +
IString(":") +
IString(time->seconds()).rightJustify(2,'0'));
if (!panel.playButton()->isLatched())
panel.playButton()->latch();
} /* endif */
else if (event.notificationId() == IMMAudioCD::trackStartedId)
{
IMMTrackMinSecFrameTime* time = (IMMTrackMinSecFrameTime*)(event.eventData().asUnsignedLong());
panel.readout.setText(IString("TRACK ") +
IString(time->track()).rightJustify(2,'0') +
IString(" MIN:SEC ") +
IString(time->minutes()).rightJustify(2,'0') +
IString(":") +
IString(time->seconds()).rightJustify(2,'0'));
panel.discReadout.setText(panel.cdPlayer()->discTitle() + ":" +
panel.cdPlayer()->trackTitle(time->track()));
if (!panel.playButton()->isLatched())
if (panel.cdPlayer()->mode()==IMMDevice::playing)
panel.playButton()->latch();
} /* endif */
else if (event.notificationId() == IMMDevice::commandNotifyId)
{
IMMNotifyEvent* notifyEvent = (IMMNotifyEvent*)(event.eventData().asUnsignedLong());
if (notifyEvent->command() == IMMNotifyEvent::play)
panel.playButton()->unlatch();
} /* endif */
else if (event.notificationId() == IMMRemovableMedia::mediaLoadedId)
{
if (event.eventData().asUnsignedLong())
{
panel.enable();
panel.ejectButton()->unlatch();
} else {
panel.disable();
panel.ejectButton()->latch();
panel.discReadout.setText("Insert an Audio CD");
}
} /* endif */
return *this;
}