1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
|
/**********************************************************************
Audacity: A Digital Audio Editor
APalette.cpp
Dominic Mazzoni
This class manages the miniframe window (aka floating window)
which contains the tool selection (ibeam, envelope, move, zoom),
the play/stop/record buttons, and the volume control. All of the
controls in this window were custom-written for Audacity - they
are not native controls on any platform - however, it is intended
that the images could be easily replaced to allow "skinning" or
just customization to match the look and feel of each platform.
**********************************************************************/
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#include <wx/brush.h>
#include <wx/image.h>
#endif
#include <math.h>
#include "AButton.h"
#include "ASlider.h"
#include "APalette.h"
#include "AudioIO.h"
#include "Project.h"
APaletteFrame *gAPaletteFrame = NULL;
bool gWindowedPalette = false;
#ifdef __WXMAC__
#define APALETTE_HEIGHT_OFFSET 0
#endif
#ifdef __WXGTK__
#define APALETTE_HEIGHT_OFFSET 22
#endif
#ifdef __WXMSW__
#define APALETTE_HEIGHT_OFFSET 25
#endif
#if defined(__WXMAC__) // && defined(TARGET_CARBON)
#include "xpm/Aqua.xpm"
#else
#include "xpm/Palette.xpm"
#endif
void InitAPaletteFrame(wxWindow * parent)
{
wxPoint where;
where.x = 10;
where.y = 10;
#ifdef __WXMAC__
where.y += 20;
#endif
gAPaletteFrame = new APaletteFrame(parent, -1, "Audacity Palette",
where);
if (gWindowedPalette) {
gAPaletteFrame->Show(TRUE);
}
}
int GetAPaletteHeight()
{
return 55;
}
void ShowWindowedPalette(wxPoint * where /* = NULL */ )
{
if (where)
gAPaletteFrame->Move(*where);
gAPaletteFrame->Show(true);
gWindowedPalette = true;
int len = gAudacityProjects.Count();
for (int i = 0; i < len; i++)
gAudacityProjects[i]->HidePalette();
}
void HideWindowedPalette()
{
gAPaletteFrame->Show(false);
gWindowedPalette = false;
int len = gAudacityProjects.Count();
for (int i = 0; i < len; i++)
gAudacityProjects[i]->ShowPalette();
}
// APaletteFrame
BEGIN_EVENT_TABLE(APaletteFrame, wxMiniFrame)
EVT_CLOSE(APaletteFrame::OnCloseWindow)
END_EVENT_TABLE()
APaletteFrame::APaletteFrame(wxWindow * parent,
wxWindowID id,
const wxString & title,
const wxPoint & pos):wxMiniFrame(parent,
id,
title,
pos,
wxSize
(360,
GetAPaletteHeight
() +
APALETTE_HEIGHT_OFFSET),
wxTINY_CAPTION_HORIZ |
wxSTAY_ON_TOP |
wxMINIMIZE_BOX |
wxFRAME_FLOAT_ON_PARENT),
mPalette(this, 0, wxPoint(0, 0), wxSize(300, GetAPaletteHeight()))
{
}
// APalette
BEGIN_EVENT_TABLE(APalette, wxWindow)
EVT_PAINT(APalette::OnPaint)
EVT_CHAR(APalette::OnKeyEvent)
EVT_COMMAND_RANGE(ID_FIRST_TOOL, ID_LAST_TOOL,
wxEVT_COMMAND_BUTTON_CLICKED, APalette::OnTool)
EVT_COMMAND_RANGE(ID_PLAY_BUTTON, ID_PLAY_BUTTON,
wxEVT_COMMAND_BUTTON_CLICKED, APalette::OnPlay)
EVT_COMMAND_RANGE(ID_STOP_BUTTON, ID_STOP_BUTTON,
wxEVT_COMMAND_BUTTON_CLICKED, APalette::OnStop)
EVT_COMMAND_RANGE(ID_RECORD_BUTTON, ID_RECORD_BUTTON,
wxEVT_COMMAND_BUTTON_CLICKED, APalette::OnRecord)
END_EVENT_TABLE()
APalette::APalette(wxWindow * parent, wxWindowID id,
const wxPoint & pos,
const wxSize & size):wxWindow(parent, id, pos, size)
{
#if defined(__WXMAC__) // && defined(TARGET_CARBON)
int off = 1;
#else
int off = 0;
#endif
mTool[0] =
new AButton(this, ID_IBEAM, wxPoint(off, off), wxSize(27, 27),
(char **) IBeamUp, (char **) IBeamOver,
(char **) IBeamDown, (char **) IBeamUp);
mTool[1] =
new AButton(this, ID_SELECT, wxPoint(28, off), wxSize(27, 27),
(char **) SelectUp, (char **) SelectOver,
(char **) SelectDown, (char **) SelectUp);
mTool[2] =
new AButton(this, ID_MOVE, wxPoint(off, 28), wxSize(27, 27),
(char **) MoveUp, (char **) MoveOver,
(char **) MoveDown, (char **) MoveUp);
mTool[3] =
new AButton(this, ID_ZOOM, wxPoint(28, 28), wxSize(27, 27),
(char **) ZoomUp, (char **) ZoomOver,
(char **) ZoomDown, (char **) ZoomUp);
mPlay =
new AButton(this, ID_PLAY_BUTTON, wxPoint(64, 4), wxSize(48, 48),
(char **) PlayUp, (char **) PlayOver,
(char **) PlayDown, (char **) PlayDisabled);
mStop =
new AButton(this, ID_STOP_BUTTON, wxPoint(114, 4), wxSize(48, 48),
(char **) StopUp, (char **) StopOver,
(char **) StopDown, (char **) StopDisabled);
mRecord =
new AButton(this, ID_RECORD_BUTTON, wxPoint(164, 4), wxSize(48, 48),
(char **) RecordUp, (char **) RecordOver,
(char **) RecordDown, (char **) RecordDisabled);
#if defined(__WXMAC__) // && defined(TARGET_CARBON)
int sliderX = 262;
#else
int sliderX = 222;
#endif
mVolume =
new ASlider(this, 0, wxPoint(sliderX, 14), wxSize(100, 28),
(char **) Slider, (char **) SliderThumb, 100);
mVolume->Set(80);
mCurrentTool = 0;
mTool[0]->PushDown();
mBackgroundBrush.SetColour(wxColour(204, 204, 204));
mBackgroundPen.SetColour(wxColour(204, 204, 204));
mBackgroundBitmap = NULL;
mBackgroundHeight = 0;
mBackgroundWidth = 0;
#if defined(__WXMAC__) // && defined(TARGET_CARBON)
mDivBitmap = new wxBitmap((const char **) Div);
mMuteBitmap = new wxBitmap((const char **) Mute);
mLoudBitmap = new wxBitmap((const char **) Loud);
#endif
}
APalette::~APalette()
{
for (int i = 0; i < 4; i++)
delete mTool[i];
delete mPlay;
delete mStop;
delete mRecord;
delete mVolume;
if (mBackgroundBitmap)
delete mBackgroundBitmap;
#if defined(__WXMAC__) // && defined(TARGET_CARBON)
delete mDivBitmap;
delete mMuteBitmap;
delete mLoudBitmap;
#endif
}
void APalette::OnKeyEvent(wxKeyEvent & event)
{
if (event.ControlDown()) {
event.Skip();
return;
}
long key = event.KeyCode();
if (event.KeyCode() == WXK_SPACE) {
if (gAudioIO->IsBusy()) {
OnStop();
SetPlay(false);
SetStop(true);
} else {
OnPlay();
SetPlay(true);
SetStop(false);
}
}
}
int APalette::GetCurrentTool()
{
return mCurrentTool;
}
void APalette::SetPlay(bool down)
{
if (down)
mPlay->PushDown();
else
mPlay->PopUp();
}
void APalette::SetStop(bool down)
{
if (down)
mStop->PushDown();
else
mStop->PopUp();
}
void APalette::SetRecord(bool down)
{
if (down)
mRecord->PushDown();
else
mRecord->PopUp();
}
void APalette::OnPlay()
{
if (gAudioIO->IsBusy())
return;
AudacityProject *p = GetActiveProject();
if (p) {
TrackList *t = p->GetTracks();
double t0 = p->GetSel0();
double t1 = p->GetSel1();
if (t1 == t0)
t1 = t->GetMaxLen();
bool success = gAudioIO->StartPlay(p, t, t0, t1);
if (!success) {
SetPlay(false);
SetStop(false);
SetRecord(false);
}
}
}
void APalette::OnStop()
{
gAudioIO->Stop();
SetStop(false);
}
void APalette::OnRecord()
{
if (gAudioIO->IsBusy())
return;
AudacityProject *p = GetActiveProject();
if (p) {
TrackList *t = p->GetTracks();
bool success = gAudioIO->StartRecord(p, t);
if (!success) {
SetPlay(false);
SetStop(false);
SetRecord(false);
}
}
}
float APalette::GetSoundVol()
{
int v = mVolume->Get();
float vol;
if (v == 0)
vol = 0.0;
else
vol = (pow(2.0, (v / 10.0)) / 256.0);
return vol;
}
void APalette::OnTool(wxCommandEvent & evt)
{
int prev = mCurrentTool;
mCurrentTool = evt.GetId() - ID_FIRST_TOOL;
for (int i = 0; i < 4; i++)
if (i == mCurrentTool)
mTool[i]->PushDown();
else
mTool[i]->PopUp();
if (mCurrentTool == 1 || prev == 1)
RedrawAllProjects();
}
void APalette::OnPaint(wxPaintEvent & evt)
{
wxPaintDC dc(this);
int width, height;
GetSize(&width, &height);
#if defined(__WXMAC__) // && defined(TARGET_CARBON)
if (mBackgroundWidth < width) {
if (mBackgroundBitmap)
delete mBackgroundBitmap;
mBackgroundBitmap = new wxBitmap(width, height);
wxMemoryDC memDC;
memDC.SelectObject(*mBackgroundBitmap);
int y;
memDC.SetPen(wxPen(wxColour(231, 231, 231), 1, wxSOLID));
for (y = 0; y < height; y += 4)
memDC.DrawLine(0, y, width, y);
memDC.SetPen(wxPen(wxColour(239, 239, 239), 1, wxSOLID));
for (y = 1; y < height; y += 2)
memDC.DrawLine(0, y, width, y);
memDC.SetPen(wxPen(wxColour(255, 255, 255), 1, wxSOLID));
for (y = 2; y < height; y += 4)
memDC.DrawLine(0, y, width, y);
memDC.DrawBitmap(*mDivBitmap, 212, 4);
memDC.DrawBitmap(*mMuteBitmap, 222, 4);
memDC.DrawBitmap(*mLoudBitmap, 376, 4);
}
wxMemoryDC memDC;
memDC.SelectObject(*mBackgroundBitmap);
dc.Blit(0, 0, width, height, &memDC, 0, 0, wxCOPY, FALSE);
#else
dc.SetBrush(mBackgroundBrush);
dc.SetPen(mBackgroundPen);
dc.DrawRectangle(0, 0, width, height);
dc.SetPen(*wxBLACK_PEN);
dc.DrawLine(27, 0, 27, height - 1);
dc.DrawLine(55, 0, 55, height - 1);
dc.DrawLine(0, 27, 55, 27);
#endif
}
void APaletteFrame::OnCloseWindow(wxCloseEvent & WXUNUSED(event))
{
HideWindowedPalette();
}
|