* some style and whitespace cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39541 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -148,12 +148,9 @@ RecorderWindow::~RecorderWindow()
|
|||||||
{
|
{
|
||||||
// The sound consumer and producer are Nodes; it has to be released and the Roster
|
// The sound consumer and producer are Nodes; it has to be released and the Roster
|
||||||
// will reap it when it's done.
|
// will reap it when it's done.
|
||||||
if (fRecordNode) {
|
if (fRecordNode)
|
||||||
fRecordNode->Release();
|
fRecordNode->Release();
|
||||||
}
|
|
||||||
if (fPlayer) {
|
|
||||||
delete fPlayer;
|
delete fPlayer;
|
||||||
}
|
|
||||||
|
|
||||||
if (fPlayTrack && fPlayFile)
|
if (fPlayTrack && fPlayFile)
|
||||||
fPlayFile->ReleaseTrack(fPlayTrack);
|
fPlayFile->ReleaseTrack(fPlayTrack);
|
||||||
@@ -169,9 +166,8 @@ RecorderWindow::~RecorderWindow()
|
|||||||
WINDOW((stderr, "clean up item %d\n", i+1));
|
WINDOW((stderr, "clean up item %d\n", i+1));
|
||||||
SoundListItem* item = dynamic_cast<SoundListItem *>(fSoundList->ItemAt(i));
|
SoundListItem* item = dynamic_cast<SoundListItem *>(fSoundList->ItemAt(i));
|
||||||
if (item) {
|
if (item) {
|
||||||
if (item->IsTemp()) {
|
if (item->IsTemp())
|
||||||
item->Entry().Remove(); // delete temp file
|
item->Entry().Remove(); // delete temp file
|
||||||
}
|
|
||||||
delete item;
|
delete item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,20 +189,19 @@ RecorderWindow::InitCheck()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
RecorderWindow::CalcSizes(float min_wid, float min_hei)
|
RecorderWindow::CalcSizes(float min_width, float min_height)
|
||||||
{
|
{
|
||||||
// Set up size limits based on new screen size
|
// Set up size limits based on new screen size
|
||||||
BScreen screen(this);
|
BScreen screen(this);
|
||||||
BRect r = screen.Frame();
|
BRect rect = screen.Frame();
|
||||||
float wid = r.Width()-12;
|
float width = rect.Width() - 12;
|
||||||
SetSizeLimits(min_wid, wid, min_hei, r.Height()-24);
|
SetSizeLimits(min_width, width, min_height, rect.Height() - 24);
|
||||||
|
|
||||||
// Don't zoom to cover all of screen; user can resize last bit if necessary.
|
// Don't zoom to cover all of screen; user can resize last bit if necessary.
|
||||||
// This leaves other windows visible.
|
// This leaves other windows visible.
|
||||||
if (wid > 640) {
|
if (width > 640)
|
||||||
wid = 640 + (wid-640)/2;
|
width = 640 + (width - 640) / 2;
|
||||||
}
|
SetZoomLimits(width, rect.Height() - 24);
|
||||||
SetZoomLimits(wid, r.Height()-24);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -219,35 +214,29 @@ RecorderWindow::InitWindow()
|
|||||||
try {
|
try {
|
||||||
// Find temp directory for recorded sounds.
|
// Find temp directory for recorded sounds.
|
||||||
BPath path;
|
BPath path;
|
||||||
if (!(error = find_directory(B_COMMON_TEMP_DIRECTORY, &path))) {
|
if (!(error = find_directory(B_COMMON_TEMP_DIRECTORY, &path)))
|
||||||
error = fTempDir.SetTo(path.Path());
|
error = fTempDir.SetTo(path.Path());
|
||||||
}
|
if (error < 0)
|
||||||
if (error < 0) {
|
|
||||||
goto bad_mojo;
|
goto bad_mojo;
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the media roster is there (which means the server is there).
|
// Make sure the media roster is there (which means the server is there).
|
||||||
fRoster = BMediaRoster::Roster(&error);
|
fRoster = BMediaRoster::Roster(&error);
|
||||||
if (!fRoster) {
|
if (!fRoster)
|
||||||
goto bad_mojo;
|
goto bad_mojo;
|
||||||
}
|
|
||||||
|
|
||||||
error = fRoster->GetAudioInput(&fAudioInputNode);
|
error = fRoster->GetAudioInput(&fAudioInputNode);
|
||||||
if (error < B_OK) { // there's no input?
|
if (error < B_OK) // there's no input?
|
||||||
goto bad_mojo;
|
goto bad_mojo;
|
||||||
}
|
|
||||||
|
|
||||||
error = fRoster->GetAudioMixer(&fAudioMixerNode);
|
error = fRoster->GetAudioMixer(&fAudioMixerNode);
|
||||||
if (error < B_OK) { // there's no mixer?
|
if (error < B_OK) // there's no mixer?
|
||||||
goto bad_mojo;
|
goto bad_mojo;
|
||||||
}
|
|
||||||
|
|
||||||
// Create our internal Node which records sound, and register it.
|
// Create our internal Node which records sound, and register it.
|
||||||
fRecordNode = new SoundConsumer("Sound Recorder");
|
fRecordNode = new SoundConsumer("Sound Recorder");
|
||||||
error = fRoster->RegisterNode(fRecordNode);
|
error = fRoster->RegisterNode(fRecordNode);
|
||||||
if (error < B_OK) {
|
if (error < B_OK)
|
||||||
goto bad_mojo;
|
goto bad_mojo;
|
||||||
}
|
|
||||||
|
|
||||||
// Create the window header with controls
|
// Create the window header with controls
|
||||||
BRect r(Bounds());
|
BRect r(Bounds());
|
||||||
@@ -256,8 +245,6 @@ RecorderWindow::InitWindow()
|
|||||||
| B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_NO_BORDER);
|
| B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_NO_BORDER);
|
||||||
AddChild(background);
|
AddChild(background);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
r = background->Bounds();
|
r = background->Bounds();
|
||||||
r.left = 0;
|
r.left = 0;
|
||||||
r.right = r.left + 38;
|
r.right = r.left + 38;
|
||||||
@@ -453,13 +440,15 @@ RecorderWindow::InitWindow()
|
|||||||
int32 ni_count = 12;
|
int32 ni_count = 12;
|
||||||
error = fRoster->GetInstancesFor(dni[i].addon, dni[i].flavor_id,
|
error = fRoster->GetInstancesFor(dni[i].addon, dni[i].flavor_id,
|
||||||
ni, &ni_count);
|
ni, &ni_count);
|
||||||
if (error == B_OK)
|
if (error == B_OK) {
|
||||||
for (int j = 0; j < ni_count; j++)
|
for (int j = 0; j < ni_count; j++) {
|
||||||
if (ni[j] == fAudioInputNode.node) {
|
if (ni[j] == fAudioInputNode.node) {
|
||||||
strcpy(selected_name, dni[i].name);
|
strcpy(selected_name, dni[i].name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create the actual widget
|
// Create the actual widget
|
||||||
BRect frame(fBottomBox->Bounds());
|
BRect frame(fBottomBox->Bounds());
|
||||||
@@ -469,7 +458,8 @@ RecorderWindow::InitWindow()
|
|||||||
r.InsetBy(10,10);
|
r.InsetBy(10,10);
|
||||||
r.top = r.bottom - 18;
|
r.top = r.bottom - 18;
|
||||||
fInputField = new BMenuField(r, "Input", B_TRANSLATE("Input:"), popup);
|
fInputField = new BMenuField(r, "Input", B_TRANSLATE("Input:"), popup);
|
||||||
fInputField->SetDivider(fInputField->StringWidth(B_TRANSLATE("Input:")) + 4.0f);
|
fInputField->SetDivider(fInputField->StringWidth(B_TRANSLATE("Input:"))
|
||||||
|
+ 4.0f);
|
||||||
fBottomBox->AddChild(fInputField);
|
fBottomBox->AddChild(fInputField);
|
||||||
|
|
||||||
fBottomBox->AddChild(fFileInfoBox);
|
fBottomBox->AddChild(fFileInfoBox);
|
||||||
@@ -493,17 +483,14 @@ RecorderWindow::InitWindow()
|
|||||||
|
|
||||||
// Error handling.
|
// Error handling.
|
||||||
bad_mojo:
|
bad_mojo:
|
||||||
if (error >= 0) {
|
if (error >= 0)
|
||||||
error = B_ERROR;
|
error = B_ERROR;
|
||||||
}
|
if (fRecordNode)
|
||||||
if (fRecordNode) {
|
|
||||||
fRecordNode->Release();
|
fRecordNode->Release();
|
||||||
}
|
|
||||||
|
|
||||||
delete fPlayer;
|
delete fPlayer;
|
||||||
if (!fInputField) {
|
if (!fInputField)
|
||||||
delete popup;
|
delete popup;
|
||||||
}
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,16 +578,17 @@ RecorderWindow::MessageReceived(BMessage * message)
|
|||||||
fScopeView->SetMainTime(main);
|
fScopeView->SetMainTime(main);
|
||||||
}
|
}
|
||||||
if (message->FindInt64("right", &right) == B_OK) {
|
if (message->FindInt64("right", &right) == B_OK) {
|
||||||
if (fPlayTrack)
|
if (fPlayTrack) {
|
||||||
fPlayLimit = MIN(fPlayFrames,
|
fPlayLimit = MIN(fPlayFrames,
|
||||||
(off_t)(right * fPlayFormat.u.raw_audio.frame_rate/1000000LL));
|
(off_t)(right * fPlayFormat.u.raw_audio.frame_rate
|
||||||
|
/ 1000000LL));
|
||||||
|
}
|
||||||
fScopeView->SetRightTime(right);
|
fScopeView->SetRightTime(right);
|
||||||
}
|
}
|
||||||
if (message->FindInt64("left", &left) == B_OK) {
|
if (message->FindInt64("left", &left) == B_OK)
|
||||||
fScopeView->SetLeftTime(left);
|
fScopeView->SetLeftTime(left);
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case LOOP:
|
case LOOP:
|
||||||
fLooping = fLoopButton->ButtonState();
|
fLooping = fLoopButton->ButtonState();
|
||||||
break;
|
break;
|
||||||
@@ -685,11 +673,9 @@ RecorderWindow::Record(BMessage * message)
|
|||||||
if (fAudioInputNode.kind & B_TIME_SOURCE) {
|
if (fAudioInputNode.kind & B_TIME_SOURCE) {
|
||||||
fRoster->StartNode(fAudioInputNode,
|
fRoster->StartNode(fAudioInputNode,
|
||||||
fRecordNode->TimeSource()->RealTimeFor(then, 0));
|
fRecordNode->TimeSource()->RealTimeFor(then, 0));
|
||||||
}
|
} else
|
||||||
else {
|
|
||||||
fRoster->StartNode(fAudioInputNode, then);
|
fRoster->StartNode(fAudioInputNode, then);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -722,9 +708,8 @@ RecorderWindow::Play(BMessage * message)
|
|||||||
fPlayer = new BSoundPlayer(fAudioMixerNode, &fPlayFormat.u.raw_audio,
|
fPlayer = new BSoundPlayer(fAudioMixerNode, &fPlayFormat.u.raw_audio,
|
||||||
"Sound Player");
|
"Sound Player");
|
||||||
status_t err = fPlayer->InitCheck();
|
status_t err = fPlayer->InitCheck();
|
||||||
if (err < B_OK) {
|
if (err < B_OK)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
fVolumeSlider->SetSoundPlayer(fPlayer);
|
fVolumeSlider->SetSoundPlayer(fPlayer);
|
||||||
fPlayer->SetCallbacks(PlayFile, NotifyPlayFile, this);
|
fPlayer->SetCallbacks(PlayFile, NotifyPlayFile, this);
|
||||||
@@ -753,9 +738,8 @@ RecorderWindow::Save(BMessage * message)
|
|||||||
// Find the item to save.
|
// Find the item to save.
|
||||||
int32 index = fSoundList->CurrentSelection();
|
int32 index = fSoundList->CurrentSelection();
|
||||||
SoundListItem* pItem = dynamic_cast<SoundListItem*>(fSoundList->ItemAt(index));
|
SoundListItem* pItem = dynamic_cast<SoundListItem*>(fSoundList->ItemAt(index));
|
||||||
if ((! pItem) || (pItem->Entry().InitCheck() != B_OK)) {
|
if ((! pItem) || (pItem->Entry().InitCheck() != B_OK))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Update the save panel and show it.
|
// Update the save panel and show it.
|
||||||
char filename[B_FILE_NAME_LENGTH];
|
char filename[B_FILE_NAME_LENGTH];
|
||||||
@@ -785,8 +769,7 @@ RecorderWindow::DoSave(BMessage * message)
|
|||||||
|
|
||||||
if ((message->FindPointer("sound list item", (void**) &pItem) == B_OK)
|
if ((message->FindPointer("sound list item", (void**) &pItem) == B_OK)
|
||||||
&& (message->FindRef("directory", &new_dir_ref) == B_OK)
|
&& (message->FindRef("directory", &new_dir_ref) == B_OK)
|
||||||
&& (message->FindString("name", &new_name) == B_OK))
|
&& (message->FindString("name", &new_name) == B_OK)) {
|
||||||
{
|
|
||||||
BEntry& oldEntry = pItem->Entry();
|
BEntry& oldEntry = pItem->Entry();
|
||||||
BFile oldFile(&oldEntry, B_READ_WRITE);
|
BFile oldFile(&oldEntry, B_READ_WRITE);
|
||||||
if (oldFile.InitCheck() != B_OK)
|
if (oldFile.InitCheck() != B_OK)
|
||||||
@@ -824,18 +807,16 @@ RecorderWindow::Input(BMessage * message)
|
|||||||
// User selected input from pop-up
|
// User selected input from pop-up
|
||||||
const dormant_node_info * dni = 0;
|
const dormant_node_info * dni = 0;
|
||||||
ssize_t size = 0;
|
ssize_t size = 0;
|
||||||
if (message->FindData("node", B_RAW_TYPE, (const void **)&dni, &size)) {
|
if (message->FindData("node", B_RAW_TYPE, (const void **)&dni, &size))
|
||||||
return; // bad input selection message
|
return; // bad input selection message
|
||||||
}
|
|
||||||
|
|
||||||
media_node_id node_id;
|
media_node_id node_id;
|
||||||
status_t error = fRoster->GetInstancesFor(dni->addon, dni->flavor_id, &node_id);
|
status_t error = fRoster->GetInstancesFor(dni->addon, dni->flavor_id, &node_id);
|
||||||
if (error != B_OK) {
|
if (error != B_OK)
|
||||||
fRoster->InstantiateDormantNode(*dni, &fAudioInputNode);
|
fRoster->InstantiateDormantNode(*dni, &fAudioInputNode);
|
||||||
} else {
|
else
|
||||||
fRoster->GetNodeFor(node_id, &fAudioInputNode);
|
fRoster->GetNodeFor(node_id, &fAudioInputNode);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -944,9 +925,9 @@ RecorderWindow::MakeRecordConnection(const media_node & input)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the time source if it's not running.
|
// Start the time source if it's not running.
|
||||||
if ((tsobj->Node() != input) && !tsobj->IsRunning()) {
|
if ((tsobj->Node() != input) && !tsobj->IsRunning())
|
||||||
fRoster->StartNode(tsobj->Node(), BTimeSource::RealTime());
|
fRoster->StartNode(tsobj->Node(), BTimeSource::RealTime());
|
||||||
}
|
|
||||||
tsobj->Release(); // we're done with this time source instance!
|
tsobj->Release(); // we're done with this time source instance!
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -1001,10 +982,9 @@ RecorderWindow::StopRecording()
|
|||||||
fRecFile.SetSize(fRecSize + sizeof(header));
|
fRecFile.SetSize(fRecSize + sizeof(header));
|
||||||
// We reserve space; make sure we cut off any excess at the end.
|
// We reserve space; make sure we cut off any excess at the end.
|
||||||
AddSoundItem(fRecEntry, true);
|
AddSoundItem(fRecEntry, true);
|
||||||
}
|
} else
|
||||||
else {
|
|
||||||
fRecEntry.Remove();
|
fRecEntry.Remove();
|
||||||
}
|
|
||||||
// We're done for this time.
|
// We're done for this time.
|
||||||
fRecEntry.Unset();
|
fRecEntry.Unset();
|
||||||
// Close the file.
|
// Close the file.
|
||||||
@@ -1324,11 +1304,11 @@ RecorderWindow::RefsReceived(BMessage *msg)
|
|||||||
countBad++;
|
countBad++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (countBad > 0 && countGood == 0)
|
if (countBad > 0 && countGood == 0) {
|
||||||
(new BAlert(B_TRANSLATE("Nothing to play"), B_TRANSLATE("None of the "
|
(new BAlert(B_TRANSLATE("Nothing to play"), B_TRANSLATE("None of the "
|
||||||
"files appear to be audio files"), B_TRANSLATE("OK"), NULL, NULL,
|
"files appear to be audio files"), B_TRANSLATE("OK"), NULL, NULL,
|
||||||
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
|
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
|
||||||
else if (countGood > 0) {
|
} else if (countGood > 0) {
|
||||||
if (countBad > 0)
|
if (countBad > 0)
|
||||||
(new BAlert(B_TRANSLATE("Invalid audio files"), B_TRANSLATE("Some "
|
(new BAlert(B_TRANSLATE("Invalid audio files"), B_TRANSLATE("Some "
|
||||||
"of the files don't appear to be audio files"),
|
"of the files don't appear to be audio files"),
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
*
|
*
|
||||||
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers and Producers)
|
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers and Producers)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RECORDERWINDOW_H
|
#ifndef RECORDERWINDOW_H
|
||||||
#define RECORDERWINDOW_H
|
#define RECORDERWINDOW_H
|
||||||
|
|
||||||
|
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
@@ -172,4 +172,3 @@ static void NotifyPlayFile(void * cookie, BSoundPlayer::sound_player_notificatio
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif /* RECORDERWINDOW_H */
|
#endif /* RECORDERWINDOW_H */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user