From 948356def10dbbd2647dde0f098028ae44ac2d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 5 Jul 2005 22:55:35 +0000 Subject: [PATCH] added a loop button git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13468 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/soundrecorder/DrawButton.cpp | 53 +++++++++++++++++++ src/apps/soundrecorder/DrawButton.h | 33 ++++++++++++ src/apps/soundrecorder/Jamfile | 1 + src/apps/soundrecorder/RecorderWindow.cpp | 21 +++++++- src/apps/soundrecorder/RecorderWindow.h | 5 ++ src/apps/soundrecorder/icon_button.h | 62 ++++++++++++++++------- 6 files changed, 157 insertions(+), 18 deletions(-) create mode 100644 src/apps/soundrecorder/DrawButton.cpp create mode 100644 src/apps/soundrecorder/DrawButton.h diff --git a/src/apps/soundrecorder/DrawButton.cpp b/src/apps/soundrecorder/DrawButton.cpp new file mode 100644 index 0000000000..9d9eb70bed --- /dev/null +++ b/src/apps/soundrecorder/DrawButton.cpp @@ -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)); + } +} diff --git a/src/apps/soundrecorder/DrawButton.h b/src/apps/soundrecorder/DrawButton.h new file mode 100644 index 0000000000..92778c7262 --- /dev/null +++ b/src/apps/soundrecorder/DrawButton.h @@ -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 +#include + +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 diff --git a/src/apps/soundrecorder/Jamfile b/src/apps/soundrecorder/Jamfile index 6b896a32e5..8a539e2af8 100644 --- a/src/apps/soundrecorder/Jamfile +++ b/src/apps/soundrecorder/Jamfile @@ -1,6 +1,7 @@ SubDir OBOS_TOP src apps soundrecorder ; App SoundRecorder : + DrawButton.cpp DrawingTidbits.cpp FileUtils.cpp RecorderApp.cpp diff --git a/src/apps/soundrecorder/RecorderWindow.cpp b/src/apps/soundrecorder/RecorderWindow.cpp index 6ad0c6631a..e9802f6e9b 100644 --- a/src/apps/soundrecorder/RecorderWindow.cpp +++ b/src/apps/soundrecorder/RecorderWindow.cpp @@ -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); diff --git a/src/apps/soundrecorder/RecorderWindow.h b/src/apps/soundrecorder/RecorderWindow.h index a2beb57d80..cbaf6451ed 100644 --- a/src/apps/soundrecorder/RecorderWindow.h +++ b/src/apps/soundrecorder/RecorderWindow.h @@ -18,6 +18,7 @@ #include #include +#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; diff --git a/src/apps/soundrecorder/icon_button.h b/src/apps/soundrecorder/icon_button.h index 2a73d3bb25..50f9c726a7 100644 --- a/src/apps/soundrecorder/icon_button.h +++ b/src/apps/soundrecorder/icon_button.h @@ -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 +}; +