added a loop button

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13468 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2005-07-05 22:55:35 +00:00
parent 21027896c8
commit 948356def1
6 changed files with 157 additions and 18 deletions
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright 2005, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Reworked from DarkWyrm version in CDPlayer
*/
#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)
: BControl(frame, name, "", msg, resize, flags | B_WILL_DRAW),
fOn(frame, B_COLOR_8_BIT),
fOff(frame, B_COLOR_8_BIT),
fButtonState(false)
{
fOff.SetBits(off, (frame.Width() + 1) * (frame.Height() + 1), 0, B_COLOR_8_BIT);
fOn.SetBits(on, (frame.Width() + 1) * (frame.Height() + 1), 0, B_COLOR_8_BIT);
}
DrawButton::~DrawButton(void)
{
}
void
DrawButton::AttachedToWindow()
{
ReplaceTransparentColor(&fOn, Parent()->ViewColor());
ReplaceTransparentColor(&fOff, Parent()->ViewColor());
}
void
DrawButton::MouseUp(BPoint pt)
{
fButtonState = fButtonState ? false : true;
Invalidate();
Invoke();
}
void
DrawButton::Draw(BRect update)
{
if (fButtonState) {
DrawBitmap(&fOn, BPoint(0,0));
} else {
DrawBitmap(&fOff, BPoint(0,0));
}
}
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright 2005, Jérôme Duval. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Reworked from DarkWyrm version in CDPlayer
*/
#ifndef _DRAW_BUTTON_H
#define _DRAW_BUTTON_H
#include <Control.h>
#include <Bitmap.h>
class DrawButton : public BControl
{
public:
DrawButton(BRect frame, const char *name, const unsigned char *on,
const unsigned char *off, BMessage *msg, int32 resize = 0,
int32 flags = 0);
~DrawButton(void);
void Draw(BRect update);
void AttachedToWindow();
void MouseUp(BPoint pt);
bool ButtonState() { return fButtonState; };
private:
BBitmap fOn;
BBitmap fOff;
bool fButtonState;
};
#endif
+1
View File
@@ -1,6 +1,7 @@
SubDir OBOS_TOP src apps soundrecorder ;
App SoundRecorder :
DrawButton.cpp
DrawingTidbits.cpp
FileUtils.cpp
RecorderApp.cpp
+20 -1
View File
@@ -105,6 +105,7 @@ RecorderWindow::RecorderWindow() :
fPlayFile(NULL),
fPlayTrack(NULL),
fPlayFrames(0),
fLooping(false),
fSavePanel(NULL),
fInitCheck(B_OK)
{
@@ -113,6 +114,7 @@ RecorderWindow::RecorderWindow() :
fPlayButton = NULL;
fStopButton = NULL;
fSaveButton = NULL;
fLoopButton = NULL;
fLengthControl = NULL;
fInputField = NULL;
fRecordNode = 0;
@@ -311,6 +313,15 @@ RecorderWindow::InitWindow()
fSaveButton->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_TOP);
background->AddChild(fSaveButton);
// Button Loop
buttonRect = BRect(BPoint(0,0), kArrowSize);
buttonRect.OffsetTo(background->Bounds().RightBottom() - BPoint(23, 48));
fLoopButton = new DrawButton(buttonRect, "Loop",
kLoopArrowBits, kArrowBits, new BMessage(LOOP));
fLoopButton->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_TOP);
fLoopButton->SetTarget(this);
background->AddChild(fLoopButton);
buttonRect = BRect(BPoint(0,0), kSpeakerIconBitmapSize);
buttonRect.OffsetTo(background->Bounds().RightBottom() - BPoint(121, 17));
SpeakerView *speakerView = new SpeakerView(buttonRect, B_FOLLOW_LEFT | B_FOLLOW_TOP);
@@ -584,6 +595,9 @@ RecorderWindow::MessageReceived(BMessage * message)
}
}
break;
case LOOP:
fLooping = fLoopButton->ButtonState();
break;
case B_SIMPLE_DATA:
case B_REFS_RECEIVED:
{
@@ -1226,7 +1240,12 @@ RecorderWindow::PlayFile(void * cookie, void * data, size_t size, const media_ra
int32 frame_size = (window->fPlayFormat.u.raw_audio.format & 0xf) *
window->fPlayFormat.u.raw_audio.channel_count;
if (window->fPlayFrame < window->fPlayLimit) {
if ((window->fPlayFrame < window->fPlayLimit) || window->fLooping) {
if (window->fPlayFrame >= window->fPlayLimit) {
bigtime_t left = window->fTrackSlider->LeftTime();
window->fPlayTrack->SeekToTime(&left);
window->fPlayFrame = window->fPlayTrack->CurrentFrame();
}
int64 frames = 0;
window->fPlayTrack->ReadFrames(data, &frames);
window->fVUView->ComputeNextLevel(data, size/frame_size);
+5
View File
@@ -18,6 +18,7 @@
#include <SoundPlayer.h>
#include <Window.h>
#include "DrawButton.h"
#include "ScopeView.h"
#include "TransportButton.h"
#include "TrackSlider.h"
@@ -55,6 +56,7 @@ public:
FORWARD,
SAVE,
VIEW_LIST,
LOOP,
INPUT_SELECTED = 'cW00', // control messages
LENGTH_CHANGED,
SOUND_SELECTED,
@@ -78,6 +80,7 @@ private:
TransportButton * fRewindButton;
TransportButton * fForwardButton;
TransportButton * fSaveButton;
DrawButton * fLoopButton;
VolumeSlider *fVolumeSlider;
TrackSlider *fTrackSlider;
UpDownButton * fUpDownButton;
@@ -123,6 +126,8 @@ private:
int64 fPlayFrame;
int64 fPlayFrames;
bool fLooping;
media_node fAudioMixerNode;
BFilePanel *fSavePanel;
+45 -17
View File
@@ -2024,23 +2024,7 @@ const unsigned char kLeftThumbBits [] = {
0xff,0x17,0x17,0x18,0x1b,0x1b,0x1b,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0x14,0x13,0x14,0x17,0x1a,0x1a,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0x14,0x10,0x0d,0x0d,0x0d,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff
};/*
const unsigned char kLeftThumbBits [] = {
0xff,0xff,0x16,0x16,0x19,0x19,0x1d,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0x17,0x1c,0x1d,0x1c,0x1b,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x18,0x1e,0x1c,0x1b,0x1b,0x1b,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x1c,0x1c,0x1b,0x1b,0x1b,0x1b,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x1e,0x1b,0x3f,0x1b,0x3f,0x1b,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x1c,0x1b,0x1b,0x17,0x1b,0x17,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x1b,0x1b,0x3f,0x1b,0x3f,0x1b,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x1b,0x1b,0x1b,0x17,0x1b,0x17,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x1c,0x1b,0x3f,0x1b,0x3f,0x1b,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x1c,0x1b,0x1b,0x17,0x1b,0x17,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x1a,0x1a,0x1b,0x1b,0x1b,0x1b,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x17,0x17,0x18,0x1b,0x1b,0x1b,0x1b,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0x14,0x13,0x14,0x17,0x1a,0x1a,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0x14,0x10,0x0d,0x0d,0x0d,0x0c,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
};*/
};
const unsigned char kRightThumbBits [] = {
0xff,0xff,0xff,0xff,0xff,0xff,0x3f,0x1d,0x1c,0x18,0x15,0xff,0xff,0xff,0xff,0xff,
@@ -2059,3 +2043,47 @@ const unsigned char kRightThumbBits [] = {
0xff,0xff,0xff,0xff,0xff,0xff,0x11,0x11,0x10,0x0e,0x0e,0xff,0xff,0xff,0xff,0xff
};
const int32 kArrowWidth = 16;
const int32 kArrowHeight = 16;
const color_space kArrowColorSpace = B_CMAP8;
const BPoint kArrowSize(kArrowWidth - 1, kArrowHeight - 1);
const unsigned char kArrowBits [] = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x11,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x11,0xff,0xff,0xff,0xff,
0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0xff,0xff,
0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,
0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x11,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x11,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
};
const unsigned char kLoopArrowBits [] = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0x11,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0xff,0xff,0xff,0xff,
0xff,0x11,0x00,0x00,0x00,0x00,0x11,0x11,0x11,0x00,0x00,0x00,0x00,0xff,0xff,0xff,
0xff,0x00,0x00,0x00,0x11,0xff,0xff,0xff,0xff,0xff,0x11,0x00,0x00,0x00,0xff,0xff,
0x11,0x00,0x00,0x11,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x11,0x00,0x00,0xff,0xff,
0x00,0x00,0x11,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x11,0x00,0x00,0xff,
0x00,0x00,0x11,0xff,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0xff,0x11,0x00,0x00,0xff,
0x00,0x00,0x00,0x11,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0x00,0x00,0x00,0xff,
0xff,0x00,0x00,0x00,0x11,0x11,0x11,0x00,0x00,0x00,0xff,0xff,0xff,0x00,0xff,0xff,
0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0x11,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
};