Patch from Karvjorm (ticket #6107): Localization for SoundRecorder.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37009 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2010-06-04 20:21:15 +00:00
parent e7d3e55ad6
commit 3ee964070b
15 changed files with 412 additions and 239 deletions

View File

@ -8,8 +8,8 @@
#include "DrawButton.h"
#include "DrawingTidbits.h"
DrawButton::DrawButton(BRect frame, const char *name, const unsigned char *on, const unsigned char *off,
BMessage *msg, int32 resize, int32 flags)
DrawButton::DrawButton(BRect frame, const char *name, const unsigned char *on,
const unsigned char *off, BMessage *msg, int32 resize, int32 flags)
: BControl(frame, name, "", msg, resize, flags | B_WILL_DRAW),
fOn(frame, B_CMAP8),
fOff(frame, B_CMAP8),

View File

@ -2,7 +2,8 @@
* Copyright 2005, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers and Producers)
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers
* and Producers)
*/
#include <Bitmap.h>
@ -48,7 +49,8 @@ operator!=(const rgb_color &a, const rgb_color &b)
void
ReplaceColor(BBitmap *bitmap, rgb_color from, rgb_color to)
{
ASSERT(bitmap->ColorSpace() == B_CMAP8); // other color spaces not implemented yet
ASSERT(bitmap->ColorSpace() == B_CMAP8);
// other color spaces not implemented yet
BScreen screen(B_MAIN_SCREEN_ID);
uint32 fromIndex = screen.IndexForColor(from);
@ -64,7 +66,8 @@ ReplaceColor(BBitmap *bitmap, rgb_color from, rgb_color to)
void
ReplaceTransparentColor(BBitmap *bitmap, rgb_color with)
{
ASSERT(bitmap->ColorSpace() == B_CMAP8); // other color spaces not implemented yet
ASSERT(bitmap->ColorSpace() == B_CMAP8);
// other color spaces not implemented yet
BScreen screen(B_MAIN_SCREEN_ID);
uint8 withIndex = screen.IndexForColor(with);

View File

@ -1,4 +1,4 @@
/*******************************************************************************
/******************************************************************************
/
/ File: FileUtils.cpp
/
@ -6,7 +6,7 @@
/
/ Copyright 1998-1999, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
******************************************************************************/
#include "FileUtils.h"
#include <new>
@ -102,8 +102,8 @@ CopyAttributes(BNode& dst, BNode& src)
}
// NOTE: Attributes of size 0 are perfectly valid!
while (read >= 0) {
ssize_t written = dst.WriteAttr(attrName, info.type, offset, buffer,
read);
ssize_t written = dst.WriteAttr(attrName, info.type, offset,
buffer, read);
if (written != read) {
fprintf(stderr, "Error writing attribute '%s'\n", attrName);
if (written < 0)

View File

@ -20,7 +20,15 @@ Application SoundRecorder :
UpDownButton.cpp
VUView.cpp
VolumeSlider.cpp
: be media tracker $(TARGET_LIBSTDC++)
: be locale media tracker $(TARGET_LIBSTDC++)
: SoundRecorder.rdef
;
DoCatalogs SoundRecorder :
x-vnd.Haiku-SoundRecorder
:
RecorderWindow.cpp
SoundListView.cpp
;

View File

@ -56,6 +56,10 @@
#define CONNECT FPRINTF
#define WINDOW FPRINTF
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "RecorderWindow"
// default window positioning
static const float MIN_WIDTH = 400.0f;
static const float MIN_HEIGHT = 336.0f;
@ -108,7 +112,8 @@ RecorderWindow::RecorderWindow() :
fPlayFrames(0),
fLooping(false),
fSavePanel(NULL),
fInitCheck(B_OK)
fInitCheck(B_OK),
fAppCatalog(NULL)
{
fRoster = NULL;
fRecordButton = NULL;
@ -124,12 +129,18 @@ RecorderWindow::RecorderWindow() :
CalcSizes(MIN_WIDTH, MIN_HEIGHT);
be_locale->GetAppCatalog(&fAppCatalog);
SetTitle(B_TRANSLATE("SoundRecorder"));
fInitCheck = InitWindow();
if (fInitCheck != B_OK) {
if (fInitCheck == B_NAME_NOT_FOUND)
ErrorAlert("find default audio hardware", fInitCheck);
ErrorAlert(B_TRANSLATE("Cannot find default audio hardware"),
fInitCheck);
else
ErrorAlert("connect to media server", fInitCheck);
ErrorAlert(B_TRANSLATE("Cannot connect to media server"),
fInitCheck);
PostMessage(B_QUIT_REQUESTED);
} else
Show();
@ -277,7 +288,7 @@ RecorderWindow::InitWindow()
// Button for rewinding
buttonRect = BRect(BPoint(0,0), kSkipButtonSize);
buttonRect.OffsetTo(background->Bounds().LeftBottom() - BPoint(-7, 25));
fRewindButton = new TransportButton(buttonRect, "Rewind",
fRewindButton = new TransportButton(buttonRect, B_TRANSLATE("Rewind"),
kSkipBackBitmapBits, kPressedSkipBackBitmapBits,
kDisabledSkipBackBitmapBits, new BMessage(REWIND));
background->AddChild(fRewindButton);
@ -285,7 +296,7 @@ RecorderWindow::InitWindow()
// Button for stopping recording or playback
buttonRect = BRect(BPoint(0,0), kStopButtonSize);
buttonRect.OffsetTo(background->Bounds().LeftBottom() - BPoint(-48, 25));
fStopButton = new TransportButton(buttonRect, "Stop",
fStopButton = new TransportButton(buttonRect, B_TRANSLATE("Stop"),
kStopButtonBitmapBits, kPressedStopButtonBitmapBits,
kDisabledStopButtonBitmapBits, new BMessage(STOP));
background->AddChild(fStopButton);
@ -293,14 +304,14 @@ RecorderWindow::InitWindow()
// Button for starting playback of selected sound
BRect playRect(BPoint(0,0), kPlayButtonSize);
playRect.OffsetTo(background->Bounds().LeftBottom() - BPoint(-82, 25));
fPlayButton = new PlayPauseButton(playRect, "Play",
fPlayButton = new PlayPauseButton(playRect, B_TRANSLATE("Play"),
new BMessage(PLAY), new BMessage(PLAY_PERIOD), ' ', 0);
background->AddChild(fPlayButton);
// Button for forwarding
buttonRect = BRect(BPoint(0,0), kSkipButtonSize);
buttonRect.OffsetTo(background->Bounds().LeftBottom() - BPoint(-133, 25));
fForwardButton = new TransportButton(buttonRect, "Forward",
fForwardButton = new TransportButton(buttonRect, B_TRANSLATE("Forward"),
kSkipForwardBitmapBits, kPressedSkipForwardBitmapBits,
kDisabledSkipForwardBitmapBits, new BMessage(FORWARD));
background->AddChild(fForwardButton);
@ -308,14 +319,14 @@ RecorderWindow::InitWindow()
// Button to start recording (or waiting for sound)
buttonRect = BRect(BPoint(0,0), kRecordButtonSize);
buttonRect.OffsetTo(background->Bounds().LeftBottom() - BPoint(-174, 25));
fRecordButton = new RecordButton(buttonRect, "Record",
fRecordButton = new RecordButton(buttonRect, B_TRANSLATE("Record"),
new BMessage(RECORD), new BMessage(RECORD_PERIOD));
background->AddChild(fRecordButton);
// Button for saving selected sound
buttonRect = BRect(BPoint(0,0), kDiskButtonSize);
buttonRect.OffsetTo(background->Bounds().LeftBottom() - BPoint(-250, 21));
fSaveButton = new TransportButton(buttonRect, "Save",
fSaveButton = new TransportButton(buttonRect, B_TRANSLATE("Save"),
kDiskButtonBitmapsBits, kPressedDiskButtonBitmapsBits,
kDisabledDiskButtonBitmapsBits, new BMessage(SAVE));
fSaveButton->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_TOP);
@ -324,7 +335,7 @@ RecorderWindow::InitWindow()
// Button Loop
buttonRect = BRect(BPoint(0,0), kArrowSize);
buttonRect.OffsetTo(background->Bounds().RightBottom() - BPoint(23, 48));
fLoopButton = new DrawButton(buttonRect, "Loop",
fLoopButton = new DrawButton(buttonRect, B_TRANSLATE("Loop"),
kLoopArrowBits, kArrowBits, new BMessage(LOOP));
fLoopButton->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_TOP);
fLoopButton->SetTarget(this);
@ -366,7 +377,8 @@ RecorderWindow::InitWindow()
r.top += 4;
r.right -= B_V_SCROLL_BAR_WIDTH;
r.bottom -= 25;
fSoundList = new SoundListView(r, "Sound List", B_FOLLOW_ALL);
fSoundList = new SoundListView(r, B_TRANSLATE("Sound List"),
B_FOLLOW_ALL);
fSoundList->SetSelectionMessage(new BMessage(SOUND_SELECTED));
fSoundList->SetViewColor(216, 216, 216);
BScrollView *scroller = new BScrollView("scroller", fSoundList,
@ -379,43 +391,46 @@ RecorderWindow::InitWindow()
r.InsetBy(10, 8);
r.top -= 1;
fFileInfoBox = new BBox(r, "fileinfo", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
fFileInfoBox->SetLabel("File info");
fFileInfoBox->SetLabel(B_TRANSLATE("File info"));
r = fFileInfoBox->Bounds();
r.left = 8;
r.top = 13;
r.bottom = r.top + 15;
r.right -= 10;
fFilename = new BStringView(r, "filename", "File name:");
fFilename = new BStringView(r, "filename", B_TRANSLATE("File name:"));
fFileInfoBox->AddChild(fFilename);
r.top += 13;
r.bottom = r.top + 15;
fFormat = new BStringView(r, "format", "Format:");
fFormat = new BStringView(r, "format", B_TRANSLATE("Format:"));
fFileInfoBox->AddChild(fFormat);
r.top += 13;
r.bottom = r.top + 15;
fCompression = new BStringView(r, "compression", "Compression:");
fCompression = new BStringView(r, "compression",
B_TRANSLATE("Compression:"));
fFileInfoBox->AddChild(fCompression);
r.top += 13;
r.bottom = r.top + 15;
fChannels = new BStringView(r, "channels", "Channels:");
fChannels = new BStringView(r, "channels", B_TRANSLATE("Channels:"));
fFileInfoBox->AddChild(fChannels);
r.top += 13;
r.bottom = r.top + 15;
fSampleSize = new BStringView(r, "samplesize", "Sample size:");
fSampleSize = new BStringView(r, "samplesize",
B_TRANSLATE("Sample size:"));
fFileInfoBox->AddChild(fSampleSize);
r.top += 13;
r.bottom = r.top + 15;
fSampleRate = new BStringView(r, "samplerate", "Sample rate:");
fSampleRate = new BStringView(r, "samplerate",
B_TRANSLATE("Sample rate:"));
fFileInfoBox->AddChild(fSampleRate);
r.top += 13;
r.bottom = r.top + 15;
fDuration = new BStringView(r, "duration", "Duration:");
fDuration = new BStringView(r, "duration", B_TRANSLATE("Duration:"));
fFileInfoBox->AddChild(fDuration);
// Input selection lists all available physical inputs that produce
// buffers with B_MEDIA_RAW_AUDIO format data.
popup = new BPopUpMenu("Input");
popup = new BPopUpMenu(B_TRANSLATE("Input"));
const int maxInputCount = 64;
dormant_node_info dni[maxInputCount];
@ -456,8 +471,8 @@ RecorderWindow::InitWindow()
r.right = (r.left + r.right) / 2;
r.InsetBy(10,10);
r.top = r.bottom - 18;
fInputField = new BMenuField(r, "Input", "Input:", popup);
fInputField->SetDivider(fInputField->StringWidth("Input:") + 4.0f);
fInputField = new BMenuField(r, "Input", B_TRANSLATE("Input:"), popup);
fInputField->SetDivider(fInputField->StringWidth(B_TRANSLATE("Input:")) + 4.0f);
fBottomBox->AddChild(fInputField);
fBottomBox->AddChild(fFileInfoBox);
@ -624,27 +639,31 @@ RecorderWindow::Record(BMessage * message)
// Create a file with a temporary name
status_t err = NewTempName(name);
if (err < B_OK) {
ErrorAlert("find an unused name to use for the new recording", err);
ErrorAlert(B_TRANSLATE("Cannot find an unused name to use for the "
"new recording"), err);
return;
}
// Find the file so we can refer to it later
err = fTempDir.FindEntry(name, &fRecEntry);
if (err < B_OK) {
ErrorAlert("find the temporary file created to hold the new recording", err);
ErrorAlert(B_TRANSLATE("Cannot find the temporary file created to "
"hold the new recording"), err);
return;
}
err = fRecFile.SetTo(&fTempDir, name, O_RDWR);
if (err < B_OK) {
ErrorAlert("open the temporary file created to hold the new recording", err);
ErrorAlert(B_TRANSLATE("Cannot open the temporary file created to "
"hold the new recording"), err);
fRecEntry.Unset();
return;
}
// Reserve space on disk (creates fewer fragments)
err = fRecFile.SetSize(4 * fRecordFormat.u.raw_audio.channel_count
* fRecordFormat.u.raw_audio.frame_rate * (fRecordFormat.u.raw_audio.format
& media_raw_audio_format::B_AUDIO_SIZE_MASK));
* fRecordFormat.u.raw_audio.frame_rate
* (fRecordFormat.u.raw_audio.format
& media_raw_audio_format::B_AUDIO_SIZE_MASK));
if (err < B_OK) {
ErrorAlert("record a sound that long", err);
ErrorAlert(B_TRANSLATE("Cannot record a sound that long"), err);
fRecEntry.Remove();
fRecEntry.Unset();
return;
@ -656,7 +675,8 @@ RecorderWindow::Record(BMessage * message)
// Hook up input
err = MakeRecordConnection(fAudioInputNode);
if (err < B_OK) {
ErrorAlert("connect to the selected sound input", err);
ErrorAlert(B_TRANSLATE("Cannot connect to the selected sound input"),
err);
fRecEntry.Remove();
fRecEntry.Unset();
return;
@ -692,7 +712,7 @@ RecorderWindow::Play(BMessage * message)
fPlayButton->SetPlaying();
if (!fPlayTrack) {
ErrorAlert("get the file to play", B_ERROR);
ErrorAlert(B_TRANSLATE("Cannot get the file to play"), B_ERROR);
return;
}
@ -702,7 +722,8 @@ RecorderWindow::Play(BMessage * message)
fPlayFrame = fPlayTrack->CurrentFrame();
// Create our internal Node which plays sound, and register it.
fPlayer = new BSoundPlayer(fAudioMixerNode, &fPlayFormat.u.raw_audio, "Sound Player");
fPlayer = new BSoundPlayer(fAudioMixerNode, &fPlayFormat.u.raw_audio,
"Sound Player");
status_t err = fPlayer->InitCheck();
if (err < B_OK) {
return;
@ -830,7 +851,7 @@ RecorderWindow::Selected(BMessage * message)
return;
status_t err = UpdatePlayFile(pItem, true);
if (err != B_OK) {
ErrorAlert("recognize this file as a media file",
ErrorAlert(B_TRANSLATE("Cannot recognize this file as a media file"),
err == B_MEDIA_NO_HANDLER ? B_OK : err);
RemoveCurrentSoundItem();
}
@ -913,8 +934,10 @@ RecorderWindow::MakeRecordConnection(const media_node & input)
return err;
}
// Using the same structs for input and output is OK in BMediaRoster::Connect().
err = fRoster->Connect(fAudioOutput.source, fRecInput.destination, &fRecordFormat, &fAudioOutput, &fRecInput);
// Using the same structs for input and output is OK in
// BMediaRoster::Connect().
err = fRoster->Connect(fAudioOutput.source, fRecInput.destination,
&fRecordFormat, &fAudioOutput, &fRecInput);
if (err < B_OK) {
CONNECT((stderr, "RecorderWindow::MakeRecordConnection():"
" failed to connect sound recorder to audio input node.\n"));
@ -978,7 +1001,8 @@ RecorderWindow::StopRecording()
fRecFile.Seek(0, SEEK_SET);
fRecFile.Write(&header, sizeof(header));
fRecFile.SetSize(fRecSize + sizeof(header)); // We reserve space; make sure we cut off any excess at the end.
fRecFile.SetSize(fRecSize + sizeof(header));
// We reserve space; make sure we cut off any excess at the end.
AddSoundItem(fRecEntry, true);
}
else {
@ -1037,7 +1061,8 @@ RecorderWindow::UpdateButtons()
}
#ifndef __HAIKU__
extern "C" status_t DecodedFormat__11BMediaTrackP12media_format(BMediaTrack *self, media_format *inout_format);
extern "C" status_t DecodedFormat__11BMediaTrackP12media_format(
BMediaTrack *self, media_format *inout_format);
#endif
@ -1093,31 +1118,32 @@ RecorderWindow::UpdatePlayFile(SoundListItem* item, bool updateDisplay)
if (!updateDisplay)
return B_OK;
BString filename = "File name: ";
BString filename = B_TRANSLATE("File name: ");
filename << ref.name;
fFilename->SetText(filename.String());
BString format = "Format: ";
BString format = B_TRANSLATE("Format: ");
media_file_format file_format;
if (fPlayFile->GetFileFormatInfo(&file_format) == B_OK)
format << file_format.short_name;
BString compression = "Compression: ";
BString compression = B_TRANSLATE("Compression: ");
media_codec_info codec_info;
if (fPlayTrack->GetCodecInfo(&codec_info) == B_OK) {
if (strcmp(codec_info.short_name, "raw")==0)
compression << "None";
compression << B_TRANSLATE("None");
else
compression << codec_info.short_name;
}
BString channels = "Channels: ";
BString channels = B_TRANSLATE("Channels: ");
channels << fPlayFormat.u.raw_audio.channel_count;
BString samplesize = "Sample size: ";
samplesize << 8 * (fPlayFormat.u.raw_audio.format & 0xf) << " bits";
BString samplerate = "Sample rate: ";
BString samplesize = B_TRANSLATE("Sample size: ");
samplesize << 8 * (fPlayFormat.u.raw_audio.format & 0xf)
<< B_TRANSLATE(" bits");
BString samplerate = B_TRANSLATE("Sample rate: ");
samplerate << (int)fPlayFormat.u.raw_audio.frame_rate;
BString durationString = "Duration: ";
BString durationString = B_TRANSLATE("Duration: ");
bigtime_t duration = fPlayTrack->Duration();
durationString << (float)(duration / 1000000.0) << " seconds";
durationString << (float)(duration / 1000000.0) << B_TRANSLATE(" seconds");
fFormat->SetText(format.String());
fCompression->SetText(compression.String());
@ -1140,10 +1166,10 @@ RecorderWindow::ErrorAlert(const char * action, status_t err)
{
char msg[300];
if (err != B_OK)
sprintf(msg, "Cannot %s: %s. [%lx]", action, strerror(err), (int32) err);
sprintf(msg, "%s: %s. [%lx]", action, strerror(err), (int32) err);
else
sprintf(msg, "Cannot %s.", action);
(new BAlert("", msg, "Stop"))->Go();
sprintf(msg, "%s.", action);
(new BAlert("", msg, B_TRANSLATE("Stop")))->Go();
}
@ -1302,13 +1328,15 @@ RecorderWindow::RefsReceived(BMessage *msg)
}
if (countBad > 0 && countGood == 0)
(new BAlert("Nothing to play", "None of the files appear to be "
"audio files", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
(new BAlert(B_TRANSLATE("Nothing to play"), B_TRANSLATE("None of the "
"files appear to be audio files"), B_TRANSLATE("OK"), NULL, NULL,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
else if (countGood > 0) {
if (countBad > 0)
(new BAlert("Invalid audio files", "Some of the files "
"don't appear to be audio files", "OK", NULL, NULL,
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
(new BAlert(B_TRANSLATE("Invalid audio files"), B_TRANSLATE("Some "
"of the files don't appear to be audio files"),
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL,
B_WARNING_ALERT))->Go();
fSoundList->Select(fSoundList->CountItems() - 1);
}
}
@ -1332,7 +1360,8 @@ RecorderWindow::CopyTarget(BMessage *msg)
bigtime_t start = fTrackSlider->LeftTime();
// write data
bigtime_t diffTime = fTrackSlider->RightTime() - fTrackSlider->LeftTime();
bigtime_t diffTime = fTrackSlider->RightTime()
- fTrackSlider->LeftTime();
int64 framesToWrite = (int64) (diffTime
* fPlayFormat.u.raw_audio.frame_rate / 1000000LL);
int32 frameSize = (fPlayFormat.u.raw_audio.format & 0xf)
@ -1340,17 +1369,21 @@ RecorderWindow::CopyTarget(BMessage *msg)
wave_struct header;
header.riff.riff_id = FOURCC('R','I','F','F');
header.riff.len = (frameSize * framesToWrite) + sizeof(header) - 8;
header.riff.len
= (frameSize * framesToWrite) + sizeof(header) - 8;
header.riff.wave_id = FOURCC('W','A','V','E');
header.format_chunk.fourcc = FOURCC('f','m','t',' ');
header.format_chunk.len = sizeof(header.format);
header.format.format_tag = 1;
header.format.channels = fPlayFormat.u.raw_audio.channel_count;
header.format.samples_per_sec = (uint32)fPlayFormat.u.raw_audio.frame_rate;
header.format.avg_bytes_per_sec = (uint32)(fPlayFormat.u.raw_audio.frame_rate
header.format.samples_per_sec
= (uint32)fPlayFormat.u.raw_audio.frame_rate;
header.format.avg_bytes_per_sec
= (uint32)(fPlayFormat.u.raw_audio.frame_rate
* fPlayFormat.u.raw_audio.channel_count
* (fPlayFormat.u.raw_audio.format & 0xf));
header.format.bits_per_sample = (fPlayFormat.u.raw_audio.format & 0xf) * 8;
header.format.bits_per_sample
= (fPlayFormat.u.raw_audio.format & 0xf) * 8;
header.format.block_align = frameSize;
header.data_chunk.fourcc = FOURCC('d','a','t','a');
header.data_chunk.len = frameSize * framesToWrite;

View File

@ -8,10 +8,12 @@
#ifndef RECORDERWINDOW_H
#define RECORDERWINDOW_H
#include <Catalog.h>
#include <Directory.h>
#include <Entry.h>
#include <File.h>
#include <FilePanel.h>
#include <Locale.h>
#include <MediaFile.h>
#include <MediaNode.h>
#include <MediaTrack.h>
@ -167,6 +169,7 @@ static void NotifyPlayFile(void * cookie, BSoundPlayer::sound_player_notificatio
void RefsReceived(BMessage *msg);
void CopyTarget(BMessage *msg);
BCatalog fAppCatalog;
};
#endif /* RECORDERWINDOW_H */

View File

@ -121,7 +121,8 @@ ScopeView::ComputeRendering()
int64 framesCount = fMediaTrack->CountFrames() / SAMPLES_COUNT;
if (framesCount <= 0)
return;
T samples[fPlayFormat.u.raw_audio.buffer_size / (fPlayFormat.u.raw_audio.format
T samples[fPlayFormat.u.raw_audio.buffer_size
/ (fPlayFormat.u.raw_audio.format
& media_raw_audio_format::B_AUDIO_SIZE_MASK)];
int64 frames = 0;
U sum = 0;
@ -149,7 +150,8 @@ ScopeView::ComputeRendering()
break;
if (sumCount >= framesCount) {
//TRACE("computing block %ld, sumCount %ld\n", previewIndex, sumCount);
// TRACE("computing block %ld, sumCount %ld\n", previewIndex,
// sumCount);
fPreview[previewIndex] = (int32)(sum
/ fPlayFormat.u.raw_audio.channel_count / framesCount);
if (previewMax < fPreview[previewIndex])
@ -164,7 +166,8 @@ ScopeView::ComputeRendering()
if (previewMax <= 0)
return;
for (int i = 0; i < SAMPLES_COUNT; i++)
fPreview[i] = (int32)(fPreview[i] * 1.0 / previewMax * middle + middle);
fPreview[i] = (int32)(fPreview[i] * 1.0 / previewMax
* middle + middle);
}

View File

@ -1,4 +1,4 @@
/*******************************************************************************
/******************************************************************************
/
/ File: SoundConsumer.cpp
/
@ -6,7 +6,7 @@
/
/ Copyright 1998-1999, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
******************************************************************************/
#include "SoundConsumer.h"
#include <new>

View File

@ -2,13 +2,20 @@
* Copyright 2005, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers and Producers)
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers
* and Producers)
*/
#include <Catalog.h>
#include <Entry.h>
#include <Locale.h>
#include "SoundListView.h"
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "SoundListView"
SoundListView::SoundListView(
const BRect & area,
const char * name,
@ -36,12 +43,12 @@ SoundListView::Draw(BRect updateRect)
SetFont(&font);
font_height height;
font.GetHeight(&height);
float width = font.StringWidth("Drop files here");
float width = font.StringWidth(B_TRANSLATE("Drop files here"));
BPoint pt;
pt.x = (Bounds().Width() - width) / 2;
pt.y = (Bounds().Height() + height.ascent + height.descent)/ 2;
DrawString("Drop files here", pt);
DrawString(B_TRANSLATE("Drop files here"), pt);
}
BListView::Draw(updateRect);
}

View File

@ -1,4 +1,4 @@
/*******************************************************************************
/******************************************************************************
/
/ File: SoundUtils.cpp
/
@ -6,7 +6,7 @@
/
/ Copyright 1998-1999, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
******************************************************************************/
#include <math.h>
#include "SoundUtils.h"
@ -58,13 +58,15 @@ buffer_duration(
// Figuring out duration is easy. We take extra precaution to
// not divide by zero or return irrelevant results.
bigtime_t duration = 0;
if (format.buffer_size > 0 && format.frame_rate > 0 && bytes_per_frame(format) > 0) {
if (format.buffer_size > 0 && format.frame_rate > 0
&& bytes_per_frame(format) > 0) {
// In these kinds of calculations, it's always useful to double-check
// the unit conversions. (Anyone remember high school physics?)
// bytes/(bytes/frame) / frames/sec
// = frames * sec/frames
// = secs which is what we want.
duration = s_to_us((format.buffer_size / bytes_per_frame(format)) / format.frame_rate);
duration = s_to_us((format.buffer_size / bytes_per_frame(format))
/ format.frame_rate);
}
return duration;
}
@ -87,10 +89,12 @@ buffers_for_duration(
const media_raw_audio_format & format, bigtime_t duration)
{
// Double-checking those unit conversions again:
// secs * ( (frames/sec) / (frames/buffer) ) = secs * (buffers/sec) = buffers
// secs * ( (frames/sec) / (frames/buffer) ) = secs * (buffers/sec)
// = buffers
int buffers = 0;
if (frames_per_buffer(format) > 0) {
buffers = (int) ceil(us_to_s(duration)*(format.frame_rate/frames_per_buffer(format)));
buffers = (int) ceil(us_to_s(duration)
*(format.frame_rate/frames_per_buffer(format)));
}
return buffers;
}

View File

@ -2,7 +2,8 @@
* Copyright 2005, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers and Producers)
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers
* and Producers)
*/
#include <stdio.h>
@ -12,11 +13,20 @@
#include "TrackSlider.h"
#include "icon_button.h"
TrackSlider::TrackSlider(BRect rect, const char *title, BMessage *msg, uint32 resizeFlags)
: BControl(rect, "slider", NULL, msg, resizeFlags, B_WILL_DRAW | B_FRAME_EVENTS),
fLeftTime(0), fRightTime(1000000), fMainTime(0), fTotalTime(1000000),
fLeftTracking(false), fRightTracking(false), fMainTracking(false),
fBitmap(NULL), fBitmapView(NULL)
TrackSlider::TrackSlider(BRect rect, const char *title, BMessage *msg,
uint32 resizeFlags)
:
BControl(rect, "slider", NULL, msg, resizeFlags, B_WILL_DRAW
| B_FRAME_EVENTS),
fLeftTime(0),
fRightTime(1000000),
fMainTime(0),
fTotalTime(1000000),
fLeftTracking(false),
fRightTracking(false),
fMainTracking(false),
fBitmap(NULL),
fBitmapView(NULL)
{
fFont.SetSize(8.0);
fFont.SetFlags(B_DISABLE_ANTIALIASING);
@ -74,9 +84,12 @@ TrackSlider::_InitBitmap()
fBitmapView->fRightX = fBitmapView->fRight;
fBitmapView->fPositionX = 15;
} else {
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14) * ((double)fMainTime / fTotalTime);
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15)
* ((double)fLeftTime / fTotalTime);
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16)
* ((double)fRightTime / fTotalTime);
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
* ((double)fMainTime / fTotalTime);
}
}
@ -132,20 +145,29 @@ TrackSlider::_DrawCounter(bigtime_t timestamp, float position, bool isTracking)
BeginLineArray(4);
if (!isTracking) {
AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE+1), BPoint(counterX+halfwidth+3,SLIDER_BASE+1), gray);
AddLine(BPoint(counterX+halfwidth+4,SLIDER_BASE+1), BPoint(counterX+halfwidth+4,SLIDER_BASE-8), gray);
AddLine(BPoint(counterX-halfwidth-4,SLIDER_BASE+1), BPoint(counterX-halfwidth-4,SLIDER_BASE-9), white);
AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE-9), BPoint(counterX+halfwidth+4,SLIDER_BASE-9), white);
AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE+1),
BPoint(counterX+halfwidth+3,SLIDER_BASE+1), gray);
AddLine(BPoint(counterX+halfwidth+4,SLIDER_BASE+1),
BPoint(counterX+halfwidth+4,SLIDER_BASE-8), gray);
AddLine(BPoint(counterX-halfwidth-4,SLIDER_BASE+1),
BPoint(counterX-halfwidth-4,SLIDER_BASE-9), white);
AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE-9),
BPoint(counterX+halfwidth+4,SLIDER_BASE-9), white);
SetHighColor(216,216,216);
} else {
AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE+1), BPoint(counterX+halfwidth+3,SLIDER_BASE+1), blue);
AddLine(BPoint(counterX+halfwidth+4,SLIDER_BASE+1), BPoint(counterX+halfwidth+4,SLIDER_BASE-9), blue2);
AddLine(BPoint(counterX-halfwidth-4,SLIDER_BASE+1), BPoint(counterX-halfwidth-4,SLIDER_BASE-9), blue2);
AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE-9), BPoint(counterX+halfwidth+3,SLIDER_BASE-9), blue2);
AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE+1),
BPoint(counterX+halfwidth+3,SLIDER_BASE+1), blue);
AddLine(BPoint(counterX+halfwidth+4,SLIDER_BASE+1),
BPoint(counterX+halfwidth+4,SLIDER_BASE-9), blue2);
AddLine(BPoint(counterX-halfwidth-4,SLIDER_BASE+1),
BPoint(counterX-halfwidth-4,SLIDER_BASE-9), blue2);
AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE-9),
BPoint(counterX+halfwidth+3,SLIDER_BASE-9), blue2);
SetHighColor(48,48,241);
}
EndLineArray();
FillRect(BRect(counterX-halfwidth-3,SLIDER_BASE-8,counterX+halfwidth+3,SLIDER_BASE));
FillRect(BRect(counterX-halfwidth-3,SLIDER_BASE-8,counterX+halfwidth+3,
SLIDER_BASE));
#ifdef __HAIKU__
SetDrawingMode(B_OP_OVER);
@ -174,36 +196,58 @@ TrackSlider::_DrawMarker(float position)
rgb_color white = {255,255,255};
BeginLineArray(30);
AddLine(BPoint(position,SLIDER_BASE+7), BPoint(position-4,SLIDER_BASE+3), black);
AddLine(BPoint(position-4,SLIDER_BASE+3), BPoint(position-4,SLIDER_BASE+1), black);
AddLine(BPoint(position-4,SLIDER_BASE+1), BPoint(position+4,SLIDER_BASE+1), black);
AddLine(BPoint(position+4,SLIDER_BASE+1), BPoint(position+4,SLIDER_BASE+3), black);
AddLine(BPoint(position+4,SLIDER_BASE+3), BPoint(position,SLIDER_BASE+7), black);
AddLine(BPoint(position,SLIDER_BASE+7), BPoint(position-4,SLIDER_BASE+3),
black);
AddLine(BPoint(position-4,SLIDER_BASE+3), BPoint(position-4,SLIDER_BASE+1),
black);
AddLine(BPoint(position-4,SLIDER_BASE+1), BPoint(position+4,SLIDER_BASE+1),
black);
AddLine(BPoint(position+4,SLIDER_BASE+1), BPoint(position+4,SLIDER_BASE+3),
black);
AddLine(BPoint(position+4,SLIDER_BASE+3), BPoint(position,SLIDER_BASE+7),
black);
AddLine(BPoint(position-3,SLIDER_BASE+2), BPoint(position+3,SLIDER_BASE+2), rose);
AddLine(BPoint(position-3,SLIDER_BASE+3), BPoint(position-1,SLIDER_BASE+5), rose);
AddLine(BPoint(position-3,SLIDER_BASE+2), BPoint(position+3,SLIDER_BASE+2),
rose);
AddLine(BPoint(position-3,SLIDER_BASE+3), BPoint(position-1,SLIDER_BASE+5),
rose);
AddLine(BPoint(position-2,SLIDER_BASE+3), BPoint(position+2,SLIDER_BASE+3), red);
AddLine(BPoint(position-1,SLIDER_BASE+4), BPoint(position+1,SLIDER_BASE+4), red);
AddLine(BPoint(position,SLIDER_BASE+5), BPoint(position,SLIDER_BASE+5), red);
AddLine(BPoint(position-2,SLIDER_BASE+3), BPoint(position+2,SLIDER_BASE+3),
red);
AddLine(BPoint(position-1,SLIDER_BASE+4), BPoint(position+1,SLIDER_BASE+4),
red);
AddLine(BPoint(position,SLIDER_BASE+5), BPoint(position,SLIDER_BASE+5),
red);
AddLine(BPoint(position,SLIDER_BASE+6), BPoint(position+3,SLIDER_BASE+3), bordeau);
AddLine(BPoint(position,SLIDER_BASE+6), BPoint(position+3,SLIDER_BASE+3),
bordeau);
AddLine(BPoint(position,SLIDER_BASE+12), BPoint(position-4,SLIDER_BASE+16), black);
AddLine(BPoint(position-4,SLIDER_BASE+16), BPoint(position-4,SLIDER_BASE+17), black);
AddLine(BPoint(position-4,SLIDER_BASE+17), BPoint(position+4,SLIDER_BASE+17), black);
AddLine(BPoint(position+4,SLIDER_BASE+17), BPoint(position+4,SLIDER_BASE+16), black);
AddLine(BPoint(position+4,SLIDER_BASE+16), BPoint(position,SLIDER_BASE+12), black);
AddLine(BPoint(position-4,SLIDER_BASE+18), BPoint(position+4,SLIDER_BASE+18), white);
AddLine(BPoint(position,SLIDER_BASE+12), BPoint(position-4,SLIDER_BASE+16),
black);
AddLine(BPoint(position-4,SLIDER_BASE+16), BPoint(position-4,
SLIDER_BASE+17), black);
AddLine(BPoint(position-4,SLIDER_BASE+17), BPoint(position+4,
SLIDER_BASE+17), black);
AddLine(BPoint(position+4,SLIDER_BASE+17), BPoint(position+4,
SLIDER_BASE+16), black);
AddLine(BPoint(position+4,SLIDER_BASE+16), BPoint(position,SLIDER_BASE+12),
black);
AddLine(BPoint(position-4,SLIDER_BASE+18), BPoint(position+4,
SLIDER_BASE+18), white);
AddLine(BPoint(position-3,SLIDER_BASE+16), BPoint(position,SLIDER_BASE+13), rose);
AddLine(BPoint(position-3,SLIDER_BASE+16), BPoint(position,SLIDER_BASE+13),
rose);
AddLine(BPoint(position-2,SLIDER_BASE+16), BPoint(position+2,SLIDER_BASE+16), red);
AddLine(BPoint(position-1,SLIDER_BASE+15), BPoint(position+1,SLIDER_BASE+15), red);
AddLine(BPoint(position,SLIDER_BASE+14), BPoint(position,SLIDER_BASE+14), red);
AddLine(BPoint(position-2,SLIDER_BASE+16), BPoint(position+2,
SLIDER_BASE+16), red);
AddLine(BPoint(position-1,SLIDER_BASE+15), BPoint(position+1,
SLIDER_BASE+15), red);
AddLine(BPoint(position,SLIDER_BASE+14), BPoint(position,
SLIDER_BASE+14), red);
AddLine(BPoint(position+1,SLIDER_BASE+14), BPoint(position+3,SLIDER_BASE+16), bordeau);
AddLine(BPoint(position+1,SLIDER_BASE+14), BPoint(position+3,
SLIDER_BASE+16), bordeau);
EndLineArray();
}
@ -237,7 +281,8 @@ TrackSlider::MouseDown(BPoint point)
_UpdatePosition(point);
SetTracking(true);
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY | B_LOCK_WINDOW_FOCUS);
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY
| B_LOCK_WINDOW_FOCUS);
}
@ -262,14 +307,19 @@ TrackSlider::MouseUp(BPoint point)
void
TrackSlider::_UpdatePosition(BPoint point)
{
BRect leftRect(fBitmapView->fLeftX-9, SLIDER_BASE+3, fBitmapView->fLeftX, SLIDER_BASE+16);
BRect rightRect(fBitmapView->fRightX, SLIDER_BASE+3, fBitmapView->fRightX+9, SLIDER_BASE+16);
BRect leftRect(fBitmapView->fLeftX-9, SLIDER_BASE+3, fBitmapView->fLeftX,
SLIDER_BASE+16);
BRect rightRect(fBitmapView->fRightX, SLIDER_BASE+3,
fBitmapView->fRightX+9, SLIDER_BASE+16);
if (!(fRightTracking || fMainTracking) && (fLeftTracking || ((point.x < fBitmapView->fPositionX-4) && leftRect.Contains(point)))) {
if (!(fRightTracking || fMainTracking) && (fLeftTracking
|| ((point.x < fBitmapView->fPositionX-4) && leftRect.Contains(point)))) {
if (!IsTracking())
fBitmapView->fLastX = point.x - fBitmapView->fLeftX;
fBitmapView->fLeftX = MIN(MAX(point.x - fBitmapView->fLastX, 15), fBitmapView->fRight);
fLeftTime = (bigtime_t)(MAX(MIN((fBitmapView->fLeftX - 15) / (fBitmapView->fRight - 14),1), 0) * fTotalTime);
fBitmapView->fLeftX = MIN(MAX(point.x - fBitmapView->fLastX, 15),
fBitmapView->fRight);
fLeftTime = (bigtime_t)(MAX(MIN((fBitmapView->fLeftX - 15)
/ (fBitmapView->fRight - 14),1), 0) * fTotalTime);
fLeftTracking = true;
BMessage msg = *Message();
@ -290,11 +340,15 @@ TrackSlider::_UpdatePosition(BPoint point)
_RenderBitmap();
//printf("fLeftPos : %Ld\n", fLeftTime);
} else if (!fMainTracking && (fRightTracking || ((point.x > fBitmapView->fPositionX+4) && rightRect.Contains(point)))) {
} else if (!fMainTracking && (fRightTracking
|| ((point.x > fBitmapView->fPositionX+4)
&& rightRect.Contains(point)))) {
if (!IsTracking())
fBitmapView->fLastX = point.x - fBitmapView->fRightX;
fBitmapView->fRightX = MIN(MAX(point.x - fBitmapView->fLastX, 15), fBitmapView->fRight);
fRightTime = (bigtime_t)(MAX(MIN((fBitmapView->fRightX - 15) / (fBitmapView->fRight - 14),1), 0) * fTotalTime);
fBitmapView->fRightX = MIN(MAX(point.x - fBitmapView->fLastX, 15),
fBitmapView->fRight);
fRightTime = (bigtime_t)(MAX(MIN((fBitmapView->fRightX - 15)
/ (fBitmapView->fRight - 14),1), 0) * fTotalTime);
fRightTracking = true;
BMessage msg = *Message();
@ -317,7 +371,8 @@ TrackSlider::_UpdatePosition(BPoint point)
//printf("fRightPos : %Ld\n", fRightTime);
} else {
fBitmapView->fPositionX = MIN(MAX(point.x, 15), fBitmapView->fRight);
fMainTime = (bigtime_t)(MAX(MIN((fBitmapView->fPositionX - 15) / (fBitmapView->fRight - 14),1), 0) * fTotalTime);
fMainTime = (bigtime_t)(MAX(MIN((fBitmapView->fPositionX - 15)
/ (fBitmapView->fRight - 14),1), 0) * fTotalTime);
fMainTracking = true;
BMessage msg = *Message();
@ -353,8 +408,8 @@ TrackSlider::_TimeToString(bigtime_t timestamp, char *string)
uint32 seconds = timestamp / 1000000LL;
timestamp -= seconds * 1000000LL;
uint32 centiseconds = timestamp / 10000LL;
sprintf(string, "%02ld:%02ld:%02ld:%02ld", hours, minutes, seconds, centiseconds);
sprintf(string, "%02ld:%02ld:%02ld:%02ld", hours, minutes, seconds,
centiseconds);
}
@ -362,12 +417,15 @@ void
TrackSlider::SetMainTime(bigtime_t timestamp, bool reset)
{
fMainTime = timestamp;
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14) * ((double)fMainTime / fTotalTime);
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
* ((double)fMainTime / fTotalTime);
if (reset) {
fRightTime = fTotalTime;
fLeftTime = 0;
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15)
* ((double)fLeftTime / fTotalTime);
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16)
* ((double)fRightTime / fTotalTime);
_RenderBitmap();
}
Invalidate();
@ -382,9 +440,12 @@ TrackSlider::SetTotalTime(bigtime_t timestamp, bool reset)
fRightTime = fTotalTime;
fLeftTime = 0;
}
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14) * ((double)fMainTime / fTotalTime);
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
* ((double)fMainTime / fTotalTime);
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15)
* ((double)fLeftTime / fTotalTime);
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16)
* ((double)fRightTime / fTotalTime);
_RenderBitmap();
Invalidate();
}
@ -394,7 +455,8 @@ void
TrackSlider::ResetMainTime()
{
fMainTime = fLeftTime;
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14) * ((double)fMainTime / fTotalTime);
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
* ((double)fMainTime / fTotalTime);
Invalidate();
}
@ -403,10 +465,13 @@ void
TrackSlider::FrameResized(float width, float height)
{
fBitmapView->fRight = Bounds().right - kLeftRightTrackSliderWidth;
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14) * ((double)fMainTime / fTotalTime);
fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
* ((double)fMainTime / fTotalTime);
_InitBitmap();
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15) * ((double)fLeftTime / fTotalTime);
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16) * ((double)fRightTime / fTotalTime);
fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15)
* ((double)fLeftTime / fTotalTime);
fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16)
* ((double)fRightTime / fTotalTime);
_RenderBitmap();
Invalidate();
}
@ -416,13 +481,19 @@ SliderOffscreenView::SliderOffscreenView(BRect frame, char *name)
: BView(frame, name, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW),
leftBitmap(BRect(BPoint(0,0), kLeftRightTrackSliderSize), B_CMAP8),
rightBitmap(BRect(BPoint(0,0), kLeftRightTrackSliderSize), B_CMAP8),
leftThumbBitmap(BRect(0, 0, kLeftRightThumbWidth - 1, kLeftRightThumbHeight - 1), B_CMAP8),
rightThumbBitmap(BRect(0, 0, kLeftRightThumbWidth - 1, kLeftRightThumbHeight - 1), B_CMAP8)
leftThumbBitmap(BRect(0, 0, kLeftRightThumbWidth - 1,
kLeftRightThumbHeight - 1), B_CMAP8),
rightThumbBitmap(BRect(0, 0, kLeftRightThumbWidth - 1,
kLeftRightThumbHeight - 1), B_CMAP8)
{
leftBitmap.SetBits(kLeftTrackSliderBits, kLeftRightTrackSliderWidth * kLeftRightTrackSliderHeight, 0, B_CMAP8);
rightBitmap.SetBits(kRightTrackSliderBits, kLeftRightTrackSliderWidth * kLeftRightTrackSliderHeight, 0, B_CMAP8);
leftThumbBitmap.SetBits(kLeftThumbBits, kLeftRightThumbWidth * kLeftRightThumbHeight, 0, B_CMAP8);
rightThumbBitmap.SetBits(kRightThumbBits, kLeftRightThumbWidth * kLeftRightThumbHeight, 0, B_CMAP8);
leftBitmap.SetBits(kLeftTrackSliderBits,
kLeftRightTrackSliderWidth * kLeftRightTrackSliderHeight, 0, B_CMAP8);
rightBitmap.SetBits(kRightTrackSliderBits,
kLeftRightTrackSliderWidth * kLeftRightTrackSliderHeight, 0, B_CMAP8);
leftThumbBitmap.SetBits(kLeftThumbBits,
kLeftRightThumbWidth * kLeftRightThumbHeight, 0, B_CMAP8);
rightThumbBitmap.SetBits(kRightThumbBits,
kLeftRightThumbWidth * kLeftRightThumbHeight, 0, B_CMAP8);
}
@ -451,7 +522,8 @@ SliderOffscreenView::DrawX()
SetLowColor(HighColor());
BPoint leftPoint(5, SLIDER_BASE + 1);
DrawBitmapAsync(&leftBitmap, BRect(BPoint(0, 0), kLeftRightTrackSliderSize - BPoint(5, 0)),
DrawBitmapAsync(&leftBitmap, BRect(BPoint(0, 0),
kLeftRightTrackSliderSize - BPoint(5, 0)),
BRect(leftPoint, leftPoint + kLeftRightTrackSliderSize - BPoint(5, 0)));
BPoint rightPoint(fRight + 1, SLIDER_BASE + 1);
DrawBitmapAsync(&rightBitmap, BRect(BPoint(5, 0), kLeftRightTrackSliderSize),
@ -461,20 +533,32 @@ SliderOffscreenView::DrawX()
FillRect(BRect(11, SLIDER_BASE + 3, fLeftX - 9, SLIDER_BASE + 16));
FillRect(BRect(fRightX + 9, SLIDER_BASE + 3, fRight, SLIDER_BASE + 16));
if (fLeftX > 19) {
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 3), BPoint(fLeftX - 6, SLIDER_BASE + 3));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 4), BPoint(fLeftX - 7, SLIDER_BASE + 4));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 5), BPoint(fLeftX - 8, SLIDER_BASE + 5));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 16), BPoint(fLeftX - 6, SLIDER_BASE + 16));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 15), BPoint(fLeftX - 7, SLIDER_BASE + 15));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 14), BPoint(fLeftX - 8, SLIDER_BASE + 14));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 3), BPoint(fLeftX - 6,
SLIDER_BASE + 3));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 4), BPoint(fLeftX - 7,
SLIDER_BASE + 4));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 5), BPoint(fLeftX - 8,
SLIDER_BASE + 5));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 16), BPoint(fLeftX - 6,
SLIDER_BASE + 16));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 15), BPoint(fLeftX - 7,
SLIDER_BASE + 15));
StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 14), BPoint(fLeftX - 8,
SLIDER_BASE + 14));
}
if (fRightX < fRight - 5) {
StrokeLine(BPoint(fRightX + 5, SLIDER_BASE + 3), BPoint(fRightX + 8, SLIDER_BASE + 3));
StrokeLine(BPoint(fRightX + 7, SLIDER_BASE + 4), BPoint(fRightX + 8, SLIDER_BASE + 4));
StrokeLine(BPoint(fRightX + 8, SLIDER_BASE + 5), BPoint(fRightX + 8, SLIDER_BASE + 6));
StrokeLine(BPoint(fRightX + 8, SLIDER_BASE + 13), BPoint(fRightX + 8, SLIDER_BASE + 14));
StrokeLine(BPoint(fRightX + 5, SLIDER_BASE + 16), BPoint(fRightX + 8, SLIDER_BASE + 16));
StrokeLine(BPoint(fRightX + 7, SLIDER_BASE + 15), BPoint(fRightX + 8, SLIDER_BASE + 15));
StrokeLine(BPoint(fRightX + 5, SLIDER_BASE + 3), BPoint(fRightX + 8,
SLIDER_BASE + 3));
StrokeLine(BPoint(fRightX + 7, SLIDER_BASE + 4), BPoint(fRightX + 8,
SLIDER_BASE + 4));
StrokeLine(BPoint(fRightX + 8, SLIDER_BASE + 5), BPoint(fRightX + 8,
SLIDER_BASE + 6));
StrokeLine(BPoint(fRightX + 8, SLIDER_BASE + 13), BPoint(fRightX + 8,
SLIDER_BASE + 14));
StrokeLine(BPoint(fRightX + 5, SLIDER_BASE + 16), BPoint(fRightX + 8,
SLIDER_BASE + 16));
StrokeLine(BPoint(fRightX + 7, SLIDER_BASE + 15), BPoint(fRightX + 8,
SLIDER_BASE + 15));
}
SetHighColor(144, 186, 136);
FillRect(BRect(fLeftX + 1, SLIDER_BASE + 3, fRightX, SLIDER_BASE + 4));
@ -524,12 +608,16 @@ SliderOffscreenView::DrawX()
SetLowColor(HighColor());
BPoint leftThumbPoint(fLeftX - 8, SLIDER_BASE + 3);
DrawBitmapAsync(&leftThumbBitmap, BRect(BPoint(0, 0), kLeftRightThumbSize - BPoint(7, 0)),
BRect(leftThumbPoint, leftThumbPoint + kLeftRightThumbSize - BPoint(7, 0)));
DrawBitmapAsync(&leftThumbBitmap, BRect(BPoint(0, 0),
kLeftRightThumbSize - BPoint(7, 0)),
BRect(leftThumbPoint, leftThumbPoint
+ kLeftRightThumbSize - BPoint(7, 0)));
BPoint rightThumbPoint(fRightX, SLIDER_BASE + 3);
DrawBitmapAsync(&rightThumbBitmap, BRect(BPoint(6, 0), kLeftRightThumbSize),
BRect(rightThumbPoint, rightThumbPoint + kLeftRightThumbSize-BPoint(6, 0)));
DrawBitmapAsync(&rightThumbBitmap, BRect(BPoint(6, 0),
kLeftRightThumbSize),
BRect(rightThumbPoint, rightThumbPoint
+ kLeftRightThumbSize-BPoint(6, 0)));
Sync();
}

View File

@ -2,7 +2,8 @@
* Copyright 2005, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers and Producers)
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers
* and Producers)
*/
#include <Bitmap.h>
@ -56,7 +57,8 @@ BitmapStash::GetBitmap(uint32 signature)
BitmapStash::~BitmapStash()
{
// delete all the bitmaps
for (map<uint32, BBitmap *>::iterator i = stash.begin(); i != stash.end(); i++)
for (map<uint32, BBitmap *>::iterator i = stash.begin();
i != stash.end(); i++)
delete (*i).second;
}
@ -100,7 +102,8 @@ PeriodicMessageSender *
PeriodicMessageSender::Launch(BMessenger target, const BMessage *message,
bigtime_t period)
{
PeriodicMessageSender *result = new PeriodicMessageSender(target, message, period);
PeriodicMessageSender *result = new PeriodicMessageSender(target,
message, period);
thread_id thread = spawn_thread(&PeriodicMessageSender::TrackBinder,
"ButtonRepeatingThread", B_NORMAL_PRIORITY, result);
@ -209,7 +212,8 @@ TransportButton::TransportButton(BRect frame, const char *name,
BMessage *invokeMessage, BMessage *startPressingMessage,
BMessage *pressingMessage, BMessage *donePressingMessage, bigtime_t period,
uint32 key, uint32 modifiers, uint32 resizeFlags)
: BControl(frame, name, "", invokeMessage, resizeFlags, B_WILL_DRAW | B_NAVIGABLE),
: BControl(frame, name, "", invokeMessage, resizeFlags,
B_WILL_DRAW | B_NAVIGABLE),
bitmaps(new BitmapStash(this)),
normalBits(normalBits),
pressedBits(pressedBits),
@ -301,8 +305,8 @@ BBitmap *
TransportButton::MakeBitmap(uint32 mask)
{
BBitmap *result = new BBitmap(Bounds(), B_CMAP8);
result->SetBits(BitsForMask(mask), (Bounds().Width() + 1) * (Bounds().Height() + 1),
0, B_CMAP8);
result->SetBits(BitsForMask(mask), (Bounds().Width() + 1)
* (Bounds().Height() + 1), 0, B_CMAP8);
ReplaceTransparentColor(result, Parent()->ViewColor());
@ -493,7 +497,8 @@ TransportButton::SetPressingPeriod(bigtime_t newTime)
PlayPauseButton::PlayPauseButton(BRect frame, const char *name,
BMessage *invokeMessage, BMessage *blinkMessage,
uint32 key, uint32 modifiers, uint32 resizeFlags)
: TransportButton(frame, name, kPlayButtonBitmapBits, kPressedPlayButtonBitmapBits,
: TransportButton(frame, name, kPlayButtonBitmapBits,
kPressedPlayButtonBitmapBits,
kDisabledPlayButtonBitmapBits, invokeMessage, NULL,
NULL, NULL, 0, key, modifiers, resizeFlags),
fState(PlayPauseButton::kStopped),
@ -616,7 +621,8 @@ PlayPauseButton::DonePressing()
} else if (fState == kAboutToPlay) {
fState = kPlayingLedOn;
if (!fRunner && fBlinkMessage)
fRunner = new BMessageRunner(Messenger(), fBlinkMessage, kPlayingBlinkPeriod);
fRunner = new BMessageRunner(Messenger(), fBlinkMessage,
kPlayingBlinkPeriod);
}
_inherited::DonePressing();
@ -626,7 +632,8 @@ PlayPauseButton::DonePressing()
RecordButton::RecordButton(BRect frame, const char *name,
BMessage *invokeMessage, BMessage *blinkMessage,
uint32 key, uint32 modifiers, uint32 resizeFlags)
: TransportButton(frame, name, kRecordButtonBitmapBits, kPressedRecordButtonBitmapBits,
: TransportButton(frame, name, kRecordButtonBitmapBits,
kPressedRecordButtonBitmapBits,
kDisabledRecordButtonBitmapBits, invokeMessage, NULL, NULL,
NULL, 0, key, modifiers, resizeFlags),
fState(RecordButton::kStopped),
@ -675,7 +682,7 @@ RecordButton::ModeMask() const
if (Value())
result = kPressedMask;
if (fState == kAboutToStop || fState == kRecordingLedOn)
if (fState == kAboutToStop || fState == kRecordingLedOn)
result |= kRecordingMask;
return result;
@ -729,7 +736,8 @@ RecordButton::DonePressing()
} else if (fState == kAboutToRecord) {
fState = kRecordingLedOn;
if (!fRunner && fBlinkMessage)
fRunner = new BMessageRunner(Messenger(), fBlinkMessage, kRecordingBlinkPeriod);
fRunner = new BMessageRunner(Messenger(), fBlinkMessage,
kRecordingBlinkPeriod);
}
_inherited::DonePressing();

View File

@ -2,7 +2,8 @@
* Copyright 2005, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers and Producers)
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers
* and Producers)
*/
#include "UpDownButton.h"
#include "icon_button.h"
@ -13,11 +14,14 @@ UpDownButton::UpDownButton(BRect _rect, BMessage *msg, uint32 resizeFlags)
{
BRect rect = BRect(0, 0, kUpDownButtonWidth - 1, kUpDownButtonHeight - 1);
fBitmapUp = new BBitmap(rect, B_CMAP8);
fBitmapUp->SetBits(kButtonUpBits, kUpDownButtonWidth * kUpDownButtonHeight, 0, B_CMAP8);
fBitmapUp->SetBits(kButtonUpBits, kUpDownButtonWidth * kUpDownButtonHeight,
0, B_CMAP8);
fBitmapDown = new BBitmap(rect, B_CMAP8);
fBitmapDown->SetBits(kButtonDownBits, kUpDownButtonWidth * kUpDownButtonHeight, 0, B_CMAP8);
fBitmapDown->SetBits(kButtonDownBits, kUpDownButtonWidth
* kUpDownButtonHeight, 0, B_CMAP8);
fBitmapMiddle = new BBitmap(rect, B_CMAP8);
fBitmapMiddle->SetBits(kButtonMiddleBits, kUpDownButtonWidth * kUpDownButtonHeight, 0, B_CMAP8);
fBitmapMiddle->SetBits(kButtonMiddleBits, kUpDownButtonWidth
* kUpDownButtonHeight, 0, B_CMAP8);
}

View File

@ -76,7 +76,8 @@ VUView::Draw(BRect updateRect)
void
VUView::_Run()
{
fThreadId = spawn_thread(_RenderLaunch, "VU view", B_NORMAL_PRIORITY, this);
fThreadId = spawn_thread(_RenderLaunch, "VU view", B_NORMAL_PRIORITY,
this);
if (fThreadId < 0)
return;
resume_thread(fThreadId);
@ -138,7 +139,8 @@ VUView::_RenderLoop()
} else {
SHIFT_UNTIL(levels[i][channel].red, 7, back_color.red);
SHIFT_UNTIL(levels[i][channel].blue, 7, back_color.blue);
SHIFT_UNTIL(levels[i][channel].green, 14, back_color.green);
SHIFT_UNTIL(levels[i][channel].green, 14,
back_color.green);
}
}
}
@ -173,7 +175,8 @@ VUView::_RenderLoop()
template<typename T>
T
VUView::_ComputeNextLevel(void *data, size_t size, uint32 format, int32 channel)
VUView::_ComputeNextLevel(void *data, size_t size, uint32 format,
int32 channel)
{
T* samp = (T*)data;

View File

@ -2,9 +2,10 @@
* Copyright 2005, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers and Producers)
* Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers
* and Producers)
*/
#include <stdio.h>
#include "VolumeSlider.h"
@ -14,89 +15,95 @@
#define RATIO 2.0f
VolumeSlider::VolumeSlider(BRect rect, const char *title, uint32 resizeFlags)
: BControl(rect, "slider", NULL, new BMessage(VOLUME_CHANGED), resizeFlags, B_WILL_DRAW),
fLeftBitmap(BRect(0, 0, kLeftVolumeWidth - 1, kLeftVolumeHeight - 1), B_CMAP8),
fRightBitmap(BRect(0, 0, kRightVolumeWidth - 1, kRightVolumeHeight - 1), B_CMAP8),
: BControl(rect, "slider", NULL, new BMessage(VOLUME_CHANGED),
resizeFlags, B_WILL_DRAW),
fLeftBitmap(BRect(0, 0, kLeftVolumeWidth - 1, kLeftVolumeHeight - 1),
B_CMAP8),
fRightBitmap(BRect(0, 0, kRightVolumeWidth - 1, kRightVolumeHeight - 1),
B_CMAP8),
fButtonBitmap(BRect(0, 0, kThumbWidth - 1, kThumbHeight - 1), B_CMAP8),
fSoundPlayer(NULL)
{
fLeftBitmap.SetBits(kLeftVolumeBits, kLeftVolumeWidth * kLeftVolumeHeight, 0, B_CMAP8);
fRightBitmap.SetBits(kRightVolumeBits, kRightVolumeWidth * kRightVolumeHeight, 0, B_CMAP8);
fLeftBitmap.SetBits(kLeftVolumeBits, kLeftVolumeWidth * kLeftVolumeHeight,
0, B_CMAP8);
fRightBitmap.SetBits(kRightVolumeBits, kRightVolumeWidth * kRightVolumeHeight,
0, B_CMAP8);
fButtonBitmap.SetBits(kThumbBits, kThumbWidth * kThumbHeight, 0, B_CMAP8);
fRight = Bounds().right - 15;
fRight = Bounds().right - 15;
}
VolumeSlider::~VolumeSlider()
{
}
void
VolumeSlider::Draw(BRect updateRect)
{
SetHighColor(189,186,189);
StrokeLine(BPoint(11,1), BPoint(fRight,1));
SetHighColor(0,0,0);
StrokeLine(BPoint(11,2), BPoint(fRight,2));
SetHighColor(255,255,255);
StrokeLine(BPoint(11,14), BPoint(fRight,14));
SetHighColor(231,227,231);
StrokeLine(BPoint(11,15), BPoint(fRight,15));
SetHighColor(189, 186, 189);
StrokeLine(BPoint(11, 1), BPoint(fRight, 1));
SetHighColor(0, 0, 0);
StrokeLine(BPoint(11, 2), BPoint(fRight, 2));
SetHighColor(255, 255, 255);
StrokeLine(BPoint(11, 14), BPoint(fRight, 14));
SetHighColor(231, 227, 231);
StrokeLine(BPoint(11, 15), BPoint(fRight, 15));
SetLowColor(ViewColor());
SetDrawingMode(B_OP_OVER);
DrawBitmapAsync(&fLeftBitmap, BPoint(5,1));
DrawBitmapAsync(&fRightBitmap, BPoint(fRight + 1,1));
DrawBitmapAsync(&fLeftBitmap, BPoint(5, 1));
DrawBitmapAsync(&fRightBitmap, BPoint(fRight + 1, 1));
float position = 11 + (fRight - 11) * (fSoundPlayer
? fSoundPlayer->Volume() / RATIO : 0);
SetHighColor(102, 152, 102);
FillRect(BRect(11, 3, position, 4));
SetHighColor(152, 203, 152);
FillRect(BRect(11, 5, position, 13));
float position = 11 + (fRight - 11) * (fSoundPlayer ? fSoundPlayer->Volume() / RATIO : 0);
SetHighColor(102,152,102);
FillRect(BRect(11,3,position,4));
SetHighColor(152,203,152);
FillRect(BRect(11,5,position,13));
if (fSoundPlayer)
SetHighColor(152,152,152);
SetHighColor(152, 152, 152);
else
SetHighColor(200,200,200);
FillRect(BRect(position,3,fRight,13));
SetHighColor(102,152,102);
for (int i=15; i<=fRight + 1; i+=5) {
if (i>position)
SetHighColor(128,128,128);
StrokeLine(BPoint(i,8), BPoint(i,9));
}
DrawBitmapAsync(&fButtonBitmap, BPoint(position-5,3));
SetHighColor(200, 200, 200);
FillRect(BRect(position, 3, fRight, 13));
SetHighColor(102, 152, 102);
for (int i = 15; i <= fRight + 1; i += 5) {
if (i > position)
SetHighColor(128, 128, 128);
StrokeLine(BPoint(i, 8), BPoint(i, 9));
}
DrawBitmapAsync(&fButtonBitmap, BPoint(position - 5, 3));
Sync();
SetDrawingMode(B_OP_COPY);
}
void
void
VolumeSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
{
if (!IsTracking())
return;
uint32 mouseButtons;
BPoint where;
GetMouse(&where, &mouseButtons, true);
// button not pressed, exit
if (! (mouseButtons & B_PRIMARY_MOUSE_BUTTON)) {
Invoke();
SetTracking(false);
}
if (!fSoundPlayer || !Bounds().InsetBySelf(2,2).Contains(point))
if (!fSoundPlayer || !Bounds().InsetBySelf(2, 2).Contains(point))
return;
_UpdateVolume(point);
@ -106,7 +113,7 @@ VolumeSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
void
VolumeSlider::MouseDown(BPoint point)
{
if (!fSoundPlayer || !Bounds().InsetBySelf(2,2).Contains(point))
if (!fSoundPlayer || !Bounds().InsetBySelf(2, 2).Contains(point))
return;
_UpdateVolume(point);
@ -120,10 +127,10 @@ VolumeSlider::MouseUp(BPoint point)
{
if (!IsTracking())
return;
if (fSoundPlayer && Bounds().InsetBySelf(2,2).Contains(point)) {
if (fSoundPlayer && Bounds().InsetBySelf(2, 2).Contains(point)) {
_UpdateVolume(point);
}
Invoke();
SetTracking(false);
Draw(Bounds());
@ -153,15 +160,17 @@ VolumeSlider::SetSoundPlayer(BSoundPlayer *player)
SpeakerView::SpeakerView(BRect rect, uint32 resizeFlags)
: BBox(rect, "speaker", resizeFlags, B_WILL_DRAW, B_NO_BORDER),
fSpeakerBitmap(BRect(0, 0, kSpeakerIconBitmapWidth - 1, kSpeakerIconBitmapHeight - 1), B_CMAP8)
fSpeakerBitmap(BRect(0, 0, kSpeakerIconBitmapWidth - 1,
kSpeakerIconBitmapHeight - 1), B_CMAP8)
{
fSpeakerBitmap.SetBits(kSpeakerIconBits, kSpeakerIconBitmapWidth * kSpeakerIconBitmapHeight, 0, B_CMAP8);
fSpeakerBitmap.SetBits(kSpeakerIconBits, kSpeakerIconBitmapWidth
* kSpeakerIconBitmapHeight, 0, B_CMAP8);
}
SpeakerView::~SpeakerView()
{
}
@ -169,8 +178,8 @@ void
SpeakerView::Draw(BRect updateRect)
{
SetDrawingMode(B_OP_OVER);
DrawBitmap(&fSpeakerBitmap);
SetDrawingMode(B_OP_COPY);
}