home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
MMSTEREO
/
MLTWAVE.CPP
< prev
next >
Wrap
Text File
|
1995-05-01
|
10KB
|
239 lines
#include "mltwave.hpp"
/*------------------------------------------------------------------------------
| WAVE::WAVE |
| |
| |
------------------------------------------------------------------------------*/
WAVE::WAVE( IMMWaveAudio* aWavePlayer,
unsigned long windowid,
IWindow* parent,
IWindow* owner)
: IMMPlayerPanel(windowid,parent,owner,IMMDevice::waveAudio),
readout (WAVEREADOUTID, this,this),
name (WAVENAMEID, this, this),
loadit (LOADID,this,this,IRectangle(),
IWindow::visible | IAnimatedButton::animateWhenLatched),
saveButton (SAVEID,this,this),
lineIn (WAVELINEINID,this,this),
microphone (WAVEMICROPHONEID,this,this),
pWavePlayer(aWavePlayer),
observer(0),
handler(0)
{
setPlayableDevice(pWavePlayer);
rec = new IAnimatedButton(RECID,this,this,IRectangle(),
ICustomButton::autoLatch |
ICustomButton::latchable |
IWindow::visible | IAnimatedButton::animateWhenLatched);
saveButton.setText("Save");
lineIn.enableAutoSelect();
lineIn.setText("LineIn");
microphone.enableAutoSelect();
microphone.setText("Microphone");
microphone.select();
//Add the additional buttons to the player panel.
addToCell(rec , 7, 1, 1, 2);
addToCell(&lineIn , 8, 1, 1, 1);
addToCell(µphone, 8, 2, 1, 1);
addToCell(&saveButton, 9, 1, 1, 1);
addToCell(&readout , 11, 1, 1, 2);
addToCell(&loadit , 13, 1, 1, 2);
addToCell(&name , 2, 3, 5, 1);
rec->disable();
playButton()->disable();
saveButton.disable();
rewindButton()->disable();
fastForwardButton()->disable();
//Put the bitmaps on the buttons.
rec->setBitmaps(IAnimatedButton::record);
loadit.setBitmaps(IAnimatedButton::eject);
//Put text on the buttons.
rec->setText("Record");
loadit.setText("Load");
//Set up the title
name.setText("Class Library Wave 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("HR:MIN:SEC 00:00:00");
readout.setLimit(22);
if (pWavePlayer)
{
handler = new WaveHandler();
handler->handleEventsFor(this);
observer = new WaveObserver(*this);
observer->handleNotificationsFor(*pWavePlayer);
}
}
/*------------------------------------------------------------------------------
| WAVE::~WAVE |
| |
| |
------------------------------------------------------------------------------*/
WAVE::~WAVE()
{
if (observer)
observer->stopHandlingNotificationsFor(*pWavePlayer);
if (handler)
handler->stopHandlingEventsFor(this);
}
/*------------------------------------------------------------------------------
| WAVE::recordButton |
| |
| |
------------------------------------------------------------------------------*/
IAnimatedButton* WAVE::recordButton () const
{
return rec;
}
/*------------------------------------------------------------------------------
| WAVE::wavePlayer |
| |
| |
------------------------------------------------------------------------------*/
IMMWaveAudio* WAVE::wavePlayer () const
{
return pWavePlayer;
}
/*------------------------------------------------------------------------------
| WaveHandler::WaveHandler |
| |
| |
------------------------------------------------------------------------------*/
WaveHandler::WaveHandler()
: WaveHandler::Inherited()
{}
/*------------------------------------------------------------------------------
| WaveHandler::command |
| |
------------------------------------------------------------------------------*/
Boolean WaveHandler::command(ICommandEvent& event)
{
Boolean handled = false;
WAVE* panel = 0;
switch (event.commandId())
{
case LOADID:
{
panel = (WAVE*) (event.window());
IFileDialog::Settings fdSettings;
fdSettings.setTitle("Load a new audio file");
fdSettings.setFileName("*.wav");
IFileDialog fd(panel->desktopWindow(),panel,fdSettings);
if (fd.pressedOK())
{
panel->wavePlayer()->loadOnThread(fd.fileName());
stop(*panel);
panel->wavePlayer()->startPositionTracking(IMMTime(3000));
panel->recordButton()->enable();
panel->playButton()->enable();
panel->rewindButton()->enable();
panel->fastForwardButton()->enable();
panel->saveButton.enable();
}
}
handled=true;
break;
case SAVEID:
panel = (WAVE*) (event.window());
stop(*panel);
panel->wavePlayer()->save();
handled=true;
break;
case RECID:
panel = (WAVE*) (event.window());
panel->stopButton()->enable();
panel->pauseButton()->disable();
panel->playButton()->disable();
panel->rewindButton()->disable();
panel->fastForwardButton()->disable();
if (panel->lineIn.isSelected())
panel->wavePlayer()->enableConnector(IMMDevice::lineIn);
else
panel->wavePlayer()->enableConnector(IMMDevice::microphones);
panel->wavePlayer()->acquire(IMMDevice::isolatedExclusive);
panel->wavePlayer()->record();
handled = true;
break;
default:
handled = Inherited::command(event);
break;
} /* endswitch */
return handled;
}
/*------------------------------------------------------------------------------
| WaveHandler::stop |
| |
------------------------------------------------------------------------------*/
Boolean WaveHandler::stop(const IMMPlayerPanel& panel)
{
panel.playButton()->enable();
panel.rewindButton()->enable();
panel.fastForwardButton()->enable();
Boolean retval = Inherited::stop(panel);
panel.playableDevice()->release();
return retval;
}
/*------------------------------------------------------------------------------
| WaveObserver::WaveObserver |
| |
| |
------------------------------------------------------------------------------*/
WaveObserver::WaveObserver(WAVE& wavePanel)
: WaveObserver::Inherited(),
panel(wavePanel)
{}
/*------------------------------------------------------------------------------
| WaveObserver::dispatchNotificationEvent |
| |
| |
------------------------------------------------------------------------------*/
WaveObserver& WaveObserver::dispatchNotificationEvent(const INotificationEvent& event)
{
if (event.notificationId() == IMMDevice::positionChangeId)
{
IMMPositionChangeEvent* positionEvent = (IMMPositionChangeEvent*)(event.eventData().asUnsignedLong());
IMMTime time(positionEvent->position());
panel.readout.setText(IString("HR:MIN:SEC ") +
IString(time.hours()).rightJustify(2,'0') +
":" +
IString(time.minutes()).rightJustify(2,'0') +
":" +
IString(time.seconds()).rightJustify(2,'0'));
if (!panel.playButton()->isLatched())
if (panel.wavePlayer()->mode()==IMMDevice::playing)
panel.playButton()->latch();
} /* endif */
if (event.notificationId() == IMMDevice::commandNotifyId)
{
IMMNotifyEvent* notifyEvent = (IMMNotifyEvent*)(event.eventData().asUnsignedLong());
if (notifyEvent->command() == IMMNotifyEvent::play)
panel.playButton()->unlatch();
if (notifyEvent->command() == IMMNotifyEvent::record)
panel.recordButton()->unlatch();
} /* endif */
return *this;
}