Audacity 3.2.0
MixerBoard.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 MixerBoard.cpp
6
7 Vaughan Johnson, January 2007
8 Dominic Mazzoni
9
10**********************************************************************/
11
12
13#include "MixerBoard.h"
14
15
16
17#include <cfloat>
18#include <math.h>
19
20#include <wx/setup.h> // for wxUSE_* macros
21
22#include <wx/app.h>
23#include <wx/bmpbuttn.h>
24#include <wx/dcclient.h>
25#include <wx/icon.h>
26#include <wx/settings.h> // for wxSystemSettings::GetColour and wxSystemSettings::GetMetric
27
28#include "AColor.h"
29#include "AllThemeResources.h"
30#include "AudioIO.h"
31
32#ifdef USE_MIDI
33#include "NoteTrack.h"
34#endif
35
37#include "CommonCommandFlags.h"
38#include "KeyboardCapture.h"
39#include "prefs/GUISettings.h" // for RTL_WORKAROUND
40#include "PendingTracks.h"
41#include "Project.h"
42#include "ProjectAudioIO.h"
43#include "ProjectAudioManager.h"
44#include "ProjectHistory.h"
45#include "ProjectFileIO.h"
46#include "ProjectWindow.h"
47#include "ProjectWindows.h"
48#include "SelectUtilities.h"
49#include "Theme.h"
50#include "TrackPanel.h"
51#include "TrackUtilities.h"
52#include "UndoManager.h"
53#include "Viewport.h"
54#include "WaveTrack.h"
55
56#include "widgets/AButton.h"
57#include "widgets/MeterPanel.h"
59
60
61#include "../images/MusicalInstruments.h"
62#ifdef __WXMSW__
63 #include "../images/AudacityLogo.xpm"
64#else
65 #include "../images/AudacityLogo48x48.xpm"
66#endif
67
68#include "MenuCreator.h"
69
70#include <numeric> // accumulate
71
72#define AudacityMixerBoardTitle XO("Audacity Mixer%s")
73
74// class MixerTrackSlider
75
76BEGIN_EVENT_TABLE(MixerTrackSlider, ASlider)
77 EVT_MOUSE_EVENTS(MixerTrackSlider::OnMouseEvent)
78
79 EVT_SET_FOCUS(MixerTrackSlider::OnFocus)
80 EVT_KILL_FOCUS(MixerTrackSlider::OnFocus)
81 EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, MixerTrackSlider::OnCaptureKey)
82
84
86 wxWindowID id,
88 const wxPoint & pos,
89 const wxSize & size,
90 const ASlider::Options &options)
91: ASlider(parent, id, name, pos, size, options)
92{
93}
94
95void MixerTrackSlider::OnMouseEvent(wxMouseEvent &event)
96{
98
99 if (event.ButtonUp())
100 {
101 MixerTrackCluster* pMixerTrackCluster = (MixerTrackCluster*)(this->GetParent());
102 switch (mStyle)
103 {
104 case DB_SLIDER: pMixerTrackCluster->HandleSliderGain(true); break;
105 case PAN_SLIDER: pMixerTrackCluster->HandleSliderPan(true); break;
106 default: break; // no-op
107 }
108 }
109}
110
111void MixerTrackSlider::OnFocus(wxFocusEvent &event)
112{
113 KeyboardCapture::OnFocus( *this, event );
114}
115
116void MixerTrackSlider::OnCaptureKey(wxCommandEvent &event)
117{
118 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
119 int keyCode = kevent->GetKeyCode();
120
121 // Pass LEFT/RIGHT/UP/DOWN/PAGEUP/PAGEDOWN through for input/output sliders
122 if (keyCode == WXK_LEFT || keyCode == WXK_RIGHT ||
123 keyCode == WXK_UP || keyCode == WXK_DOWN ||
124 keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN) {
125 return;
126 }
127
128 event.Skip();
129
130 return;
131}
132
133
134
135// class MixerTrackCluster
136
137const int kInset = 4;
138const int kDoubleInset = (2 * kInset);
139const int kTripleInset = (3 * kInset);
140const int kQuadrupleInset = (4 * kInset);
141
142const int TRACK_NAME_HEIGHT = 18;
144const int MUTE_SOLO_HEIGHT = 19;
145const int PAN_HEIGHT = 24;
146
147const int kLeftSideStackWidth = MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH - kDoubleInset; //vvv Change when numbers shown on slider scale.
149const int kMixerTrackClusterWidth = kLeftSideStackWidth + kRightSideStackWidth + kQuadrupleInset; // kDoubleInset margin on both sides
150
151enum {
158};
159
160BEGIN_EVENT_TABLE(MixerTrackCluster, wxPanelWrapper)
161 EVT_MOUSE_EVENTS(MixerTrackCluster::OnMouseEvent)
163
168 //v EVT_COMMAND_SCROLL(ID_SLIDER_GAIN, MixerTrackCluster::OnSliderScroll_Gain)
172
174 MixerBoard* grandParent, AudacityProject* project,
175 PlayableTrack &track,
176 const wxPoint& pos /*= wxDefaultPosition*/,
177 const wxSize& size /*= wxDefaultSize*/)
178: wxPanelWrapper(parent, -1, pos, size)
179, mTrack{ track.SharedPointer<PlayableTrack>() }
180{
181 mMixerBoard = grandParent;
182 mProject = project;
183 assert(mTrack);
184
185 SetName( Verbatim( mTrack->GetName() ) );
186
187 //this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
188 this->SetBackgroundColour( theTheme.Colour( clrMedium ) );
189 // Not sure why, but sizers weren't getting offset vertically,
190 // probably because not using wxDefaultPosition,
191 // so positions are calculated explicitly below, and sizers code was removed.
192 // (Still available in Audacity_UmixIt branch off 1.2.6.)
193
194 // track name
195 wxPoint ctrlPos(kDoubleInset, kDoubleInset);
196 wxSize ctrlSize(size.GetWidth() - kQuadrupleInset, TRACK_NAME_HEIGHT);
197 mStaticText_TrackName =
198 safenew auStaticText(this, mTrack->GetName());
199 //v Useful when different tracks are different colors, but not now.
200 // mStaticText_TrackName->SetBackgroundColour(this->GetTrackColor());
201 mStaticText_TrackName->SetForegroundColour(theTheme.Colour(clrMedium));
202 mStaticText_TrackName->SetForegroundColour(theTheme.Colour(clrTrackPanelText));
203 mStaticText_TrackName->SetSize( ctrlSize );
204 mStaticText_TrackName->SetPosition( ctrlPos );
205
206
207 // volume and velocity sliders at left (both in same place)
208 ctrlPos.x = kDoubleInset;
209 ctrlPos.y += TRACK_NAME_HEIGHT + kDoubleInset;
210 const int nGainSliderHeight =
211 size.GetHeight() - ctrlPos.y - kQuadrupleInset;
212 ctrlSize.Set(kLeftSideStackWidth - kQuadrupleInset, nGainSliderHeight);
213
214 mSlider_Volume =
216 this, ID_SLIDER_GAIN,
217 /* i18n-hint: title of the Volume slider, used to adjust the volume */
218 XO("Volume"),
219 ctrlPos, ctrlSize,
221 .Style( DB_SLIDER )
222 .Orientation( wxVERTICAL ));
223 mSlider_Volume->SetName(_("Volume"));
224
225 mSlider_Velocity =
227 this, ID_SLIDER_VELOCITY,
228 /* i18n-hint: title of the MIDI Velocity slider */
229 XO("Velocity"),
230 ctrlPos, ctrlSize,
232 .Style( VEL_SLIDER )
233 .Orientation( wxVERTICAL ));
234 mSlider_Velocity->SetName(_("Velocity"));
235
236 // other controls and meter at right
237
238 // musical instrument image
239 ctrlPos.x += kLeftSideStackWidth + kInset; // + kInset to center it in right side stack
241 wxBitmap* bitmap = mMixerBoard->GetMusicalInstrumentBitmap(mTrack.get());
242 wxASSERT(bitmap);
243 mBitmapButton_MusicalInstrument =
244 safenew wxBitmapButton(this, ID_BITMAPBUTTON_MUSICAL_INSTRUMENT, *bitmap,
245 ctrlPos, ctrlSize,
246 wxBU_AUTODRAW, wxDefaultValidator,
247 _("Musical Instrument"));
248 mBitmapButton_MusicalInstrument->SetName(_("Musical Instrument"));
249
250
251 // pan slider
252 ctrlPos.x -= kInset; // Remove inset for instrument, so Pan is at leftmost of left side stack.
254 ctrlSize.Set(kRightSideStackWidth, PAN_HEIGHT);
255
256 // The width of the pan slider must be odd (don't ask).
257 if (!(ctrlSize.x & 1))
258 ctrlSize.x--;
259
260 mSlider_Pan =
262 this, ID_SLIDER_PAN,
263 /* i18n-hint: Title of the Pan slider, used to move the sound left or right */
264 XO("Pan"),
265 ctrlPos, ctrlSize,
267 mSlider_Pan->SetName(_("Pan"));
268
269 // mute/solo buttons stacked below Pan slider
270 ctrlPos.y += PAN_HEIGHT + kDoubleInset;
271 ctrlSize.Set(mMixerBoard->mMuteSoloWidth, MUTE_SOLO_HEIGHT);
272 mToggleButton_Mute =
274 ctrlPos, ctrlSize,
275 *(mMixerBoard->mImageMuteUp), *(mMixerBoard->mImageMuteOver),
276 *(mMixerBoard->mImageMuteDown), *(mMixerBoard->mImageMuteDown),
277 *(mMixerBoard->mImageMuteDisabled),
278 true); // toggle button
279 mToggleButton_Mute->SetName(_("Mute"));
280 mToggleButton_Mute->SetAlternateImages(
281 1,
282 *(mMixerBoard->mImageMuteUp), *(mMixerBoard->mImageMuteOver),
283 *(mMixerBoard->mImageMuteDown), *(mMixerBoard->mImageMuteDown),
284 *(mMixerBoard->mImageMuteDisabled));
285
286 ctrlPos.y += MUTE_SOLO_HEIGHT;
287 mToggleButton_Solo =
289 ctrlPos, ctrlSize,
290 *(mMixerBoard->mImageSoloUp), *(mMixerBoard->mImageSoloOver),
291 *(mMixerBoard->mImageSoloDown), *(mMixerBoard->mImageSoloDown),
292 *(mMixerBoard->mImageSoloDisabled),
293 true); // toggle button
294 mToggleButton_Solo->SetName(_("Solo"));
295
296
297 // meter
298 ctrlPos.y += MUTE_SOLO_HEIGHT + kDoubleInset;
299 const int nMeterHeight =
300 nGainSliderHeight -
304 ctrlSize.Set(kRightSideStackWidth, nMeterHeight);
305
306 mMeter.Release();
307 if (GetWave()) {
308 mMeter =
309 safenew MeterPanel(mProject, // AudacityProject* project,
310 this, -1, // wxWindow* parent, wxWindowID id,
311 false, // bool isInput
312 ctrlPos, ctrlSize, // const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
313 MeterPanel::MixerTrackCluster); // Style style = HorizontalStereo,
314 mMeter->SetName(XO("Signal Level Meter"));
315 }
316
317 #if wxUSE_TOOLTIPS
318 mStaticText_TrackName->SetToolTip(mTrack->GetName());
319 mToggleButton_Mute->SetToolTip(XO("Mute"));
320 mToggleButton_Solo->SetToolTip(XO("Solo"));
321 if (GetWave())
322 mMeter->SetToolTip(XO("Signal Level Meter"));
323 #endif // wxUSE_TOOLTIPS
324
325 UpdateForStateChange();
326
327 #ifdef __WXMAC__
328 wxSizeEvent event(GetSize(), GetId());
329 event.SetEventObject(this);
330 GetEventHandler()->ProcessEvent(event);
331 #endif
332}
333
335{
336 return dynamic_cast< WaveTrack * >( mTrack.get() );
337}
338
340{
341 // TODO: more-than-two-channels
342 auto left = GetWave();
343 if (left) {
344 auto channels = left->Channels();
345 if (channels.size() > 1)
346 return (* ++ channels.first).get();
347 }
348 return nullptr;
349}
350
352{
353 return dynamic_cast< NoteTrack * >( mTrack.get() );
354}
355
356// Old approach modified things in situ.
357// However with a theme change there is so much to modify, it is easier
358// to recreate.
359#if 0
360void MixerTrackCluster::UpdatePrefs()
361{
362 this->SetBackgroundColour( theTheme.Colour( clrMedium ) );
363 mStaticText_TrackName->SetForegroundColour(theTheme.Colour(clrTrackPanelText));
364 HandleResize(); // in case TracksBehaviorsSolo changed
365}
366#endif
367
368void MixerTrackCluster::HandleResize() // For wxSizeEvents, update volume slider and meter.
369{
370 wxSize scrolledWindowClientSize = this->GetParent()->GetClientSize();
371 const int newClusterHeight =
372 scrolledWindowClientSize.GetHeight() - kDoubleInset - // nClusterHeight from MixerBoard::UpdateTrackClusters
373 wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y) + // wxScrolledWindow::GetClientSize doesn't account for its scrollbar size.
375
376 this->SetSize(-1, newClusterHeight);
377
378 // Change only the heights of mSlider_Volume and mMeter.
379 // But update shown status of mToggleButton_Solo, which affects top of mMeter.
380 const int nGainSliderHeight =
381 newClusterHeight -
382 (kInset + // margin above mStaticText_TrackName
383 TRACK_NAME_HEIGHT + kDoubleInset) - // mStaticText_TrackName + margin
384 kQuadrupleInset; // margin below volume slider
385 mSlider_Volume->SetSize(-1, nGainSliderHeight);
386 mSlider_Velocity->SetSize(-1, nGainSliderHeight);
387
388 const int nRequiredHeightAboveMeter =
392 const int nMeterY =
393 kDoubleInset + // margin at top
395 nRequiredHeightAboveMeter;
396 const int nMeterHeight = nGainSliderHeight - nRequiredHeightAboveMeter;
397 if (mMeter)
398 mMeter->SetSize(-1, nMeterY, -1, nMeterHeight);
399}
400
401void MixerTrackCluster::HandleSliderGain(const bool bWantPushState /*= false*/)
402{
403 float fValue = mSlider_Volume->Get();
404 if (GetWave())
405 GetWave()->SetVolume(fValue);
406
407 // Update the TrackPanel correspondingly.
408 TrackPanel::Get( *mProject ).RefreshTrack(mTrack.get());
409 if (bWantPushState)
411 .PushState(XO("Moved volume slider"), XO("Volume"), UndoPush::CONSOLIDATE );
412}
413
414void MixerTrackCluster::HandleSliderVelocity(const bool bWantPushState /*= false*/)
415{
416 float fValue = mSlider_Velocity->Get();
417 if (GetNote())
418 GetNote()->SetVelocity(fValue);
419
420 // Update the TrackPanel correspondingly.
421 TrackPanel::Get( *mProject ).RefreshTrack(mTrack.get());
422 if (bWantPushState)
424 .PushState(XO("Moved velocity slider"), XO("Velocity"),
426}
427
428void MixerTrackCluster::HandleSliderPan(const bool bWantPushState /*= false*/)
429{
430 float fValue = mSlider_Pan->Get();
431 if (GetWave()) // test in case track is a NoteTrack
432 GetWave()->SetPan(fValue);
433
434 // Update the TrackPanel correspondingly.
435 TrackPanel::Get( *mProject ).RefreshTrack(mTrack.get());
436
437 if (bWantPushState)
439 .PushState(XO("Moved pan slider"), XO("Pan"),
441}
442
443void MixerTrackCluster::ResetMeter(const bool bResetClipping)
444{
445 if (mMeter)
446 mMeter->Reset(GetWave()->GetRate(), bResetClipping);
447 // Release view to allow cache eviction after/before playback.
448 mSampleView.clear();
449}
450
451
452// Update appearance to match the state of the track
454{
455 const wxString newName = mTrack->GetName();
456 if (newName != GetName()) {
457 SetName( Verbatim( newName ) );
458 mStaticText_TrackName->SetLabel(newName);
459 mStaticText_TrackName->SetName(newName);
460#if wxUSE_TOOLTIPS
461 mStaticText_TrackName->SetToolTip(newName);
462#endif
463 mBitmapButton_MusicalInstrument->SetBitmapLabel(
465 }
466
467 mToggleButton_Mute->SetAlternateIdx(mTrack->GetSolo() ? 1 : 0);
468 if (mTrack->GetMute())
470 else
472
473 bool bIsSolo = mTrack->GetSolo();
474 if (bIsSolo)
476 else
478 mToggleButton_Mute->SetAlternateIdx(bIsSolo ? 1 : 0);
479
480 if (!GetWave())
481 mSlider_Pan->Hide();
482 else
483 mSlider_Pan->Set(GetWave()->GetPan());
484
485 if (!GetWave())
486 mSlider_Volume->Hide();
487 else
488 mSlider_Volume->Set(GetWave()->GetVolume());
489
490 if (!GetNote())
491 mSlider_Velocity->Hide();
492 else
493 mSlider_Velocity->Set(GetNote()->GetVelocity());
494}
495
496namespace {
498{
499 return std::accumulate(
500 view.begin(), view.end(), 0,
501 [](size_t total, const AudioSegmentSampleView& segmentView) {
502 return total + segmentView.GetSampleCount();
503 });
504}
505
506// Assumes that buffer has capacity >= GetNumSamplesInView(view)
507void FillBufferWithSampleView(float* buffer, const ChannelSampleView& view)
508{
509 size_t copiedSamples = 0;
510 for (const auto& segmentView : view)
511 {
512 const auto sampleCount = segmentView.GetSampleCount();
513 segmentView.Copy(buffer + copiedSamples, sampleCount);
514 copiedSamples += sampleCount;
515 }
516}
517}
518
519void MixerTrackCluster::UpdateMeter(const double t0, const double t1)
520{
521 // NoteTracks do not (currently) register on meters. It would probably be
522 // a good idea to display 16 channel "active" lights rather than a meter
523 if (!GetWave())
524 return;
525
526 if ((t0 < 0.0) || (t1 < 0.0) || (t0 >= t1) || // bad time value or nothing to show
527 ((mMixerBoard->HasSolo() || mTrack->GetMute()) && !mTrack->GetSolo())
528 )
529 {
530 //v Vaughan, 2011-02-25: Moved the update back to TrackPanel::OnTimer() as it helps with
531 // playback issues reported by Bill and noted on Bug 258, so no assert.
532 // Vaughan, 2011-02-04: Now that we're updating all meters from audacityAudioCallback,
533 // this causes an assert if you click Mute while playing, because ResetMeter() resets
534 // the timer, and wxTimerbase says that can only be done from main thread --
535 // but it seems to work fine.
536 this->ResetMeter(false);
537 return;
538 }
539
540 // Vaughan, 2010-11-27:
541 // This commented out code is flawed. Mistaken understanding of "frame" vs "window".
542 // Caused me to override MeterPanel::UpdateDisplay().
543 // But I think it's got a good idea, of calling WaveTracks' GetMinMax and GetRMS
544 // instead of passing in all the data and asking the meter to derive peak and rms.
545 // May be worth revisiting as I think it should perform better, because it uses the min/max/rms
546 // stored in sample blocks, rather than calculating them, but for now, changing it to use the
547 // original MeterPanel::UpdateDisplay(). New code is below the previous (now commented out).
548 //
549 //const size_t kFramesPerBuffer = 4;
550 //float min; // dummy, since it's not shown in meters
551 //Floats maxLeft{kFramesPerBuffer};
552 //Floats rmsLeft{kFramesPerBuffer};
553 //Floats maxRight{kFramesPerBuffer};
554 //Floats rmsRight{kFramesPerBuffer};
555 //
556 // bool bSuccess = (GetWave() != nullptr);
557
558 //const double dFrameInterval = (t1 - t0) / (double)kFramesPerBuffer;
559 //double dFrameT0 = t0;
560 //double dFrameT1 = t0 + dFrameInterval;
561 //int i = 0;
562 //while (bSuccess && (i < kFramesPerBuffer))
563 //{
564 // bSuccess &=
565 // mTrack->GetMinMax(&min, &(maxLeft[i]), dFrameT0, dFrameT1) &&
566 // mTrack->GetRMS(&(rmsLeft[i]), dFrameT0, dFrameT1);
567 // if (bSuccess && mRightTrack)
568 // bSuccess &=
569 // mRightTrack->GetMinMax(&min, &(maxRight[i]), dFrameT0, dFrameT1) &&
570 // mRightTrack->GetRMS(&(rmsRight[i]), dFrameT0, dFrameT1);
571 // else
572 // {
573 // // Mono: Start with raw values same as left.
574 // // To be modified by bWantPostFadeValues and channel pan/gain.
575 // maxRight[i] = maxLeft[i];
576 // rmsRight[i] = rmsLeft[i];
577 // }
578 // dFrameT0 += dFrameInterval;
579 // dFrameT1 += dFrameInterval;
580 // i++;
581 //}
582 //
583 //const bool bWantPostFadeValues = true; //v Turn this into a checkbox on MixerBoard? For now, always true.
584 //if (bSuccess && bWantPostFadeValues)
585 //if (bSuccess)
586 //{
587 // for (i = 0; i < kFramesPerBuffer; i++)
588 // {
589 // float gain = mTrack->GetChannelVolume(0);
590 // maxLeft[i] *= gain;
591 // rmsLeft[i] *= gain;
592 // if (mRightTrack)
593 // gain = mRightTrack->GetChannelVolume(1);
594 // maxRight[i] *= gain;
595 // rmsRight[i] *= gain;
596 // }
597 // if ( mMeter ) mMeter->UpdateDisplay(
598 // 2, // If mono, show left track values in both meters, as in MeterToolBar, rather than nChannels.
599 // kFramesPerBuffer,
600 // maxLeft, rmsLeft,
601 // maxRight, rmsRight,
602 // mTrack->TimeToLongSamples(t1 - t0));
603 //}
604 //
605
606 // PRL: TODO: don't fetch from wave tracks at calculated times, for update
607 // of the meter display, but instead consult PlaybackPolicy
608
609 const auto pTrack = GetWave();
610
611 // Don't throw on read error in this drawing update routine
612 constexpr auto mayThrow = false;
613
614 // Not sure how to prove satisfaction of the invariant of GetSampleView
615 mSampleView = pTrack->GetSampleView(t0, t1, mayThrow);
616
617 // Expect that the difference of t1 and t0 is the part of a track played
618 // in about 1/20 second (ticks of TrackPanel timer), so this won't overflow,
619 // unless stretch ratio is extremely low.
620 const auto nFrames = GetNumSamplesInView(mSampleView[0]);
621
622 Floats tempFloatsArray;
623 try {
624 tempFloatsArray.reinit(nFrames);
625 }
626 catch (const std::bad_alloc&) {
627 // Just in case we did not satisfy GetSampleView and computed a bogus
628 // size_t value
629 return;
630 }
631 FillBufferWithSampleView(tempFloatsArray.get(), mSampleView[0]);
632
633 decltype(tempFloatsArray) meterFloatsArray;
634 // We always pass a stereo sample array to the meter, as it shows 2 channels.
635 // Mono shows same in both meters.
636 // Since we're not mixing, need to duplicate same signal for "right" channel in mono case.
637 try {
638 meterFloatsArray.reinit(2 * nFrames );
639 }
640 catch (const std::bad_alloc&) {
641 // Just in case we did not satisfy GetSampleView and computed a bogus
642 // size_t value
643 return;
644 }
645
646 // Interleave for stereo. Left/mono first.
647 for (unsigned int index = 0; index < nFrames; index++)
648 meterFloatsArray[2 * index] = tempFloatsArray[index];
649
650 if (mSampleView.size() > 1u)
651 FillBufferWithSampleView(tempFloatsArray.get(), mSampleView[1]);
652
653 // Interleave right channel, or duplicate same signal for "right" channel in mono case.
654 for (unsigned int index = 0; index < nFrames; index++)
655 meterFloatsArray[(2 * index) + 1] = tempFloatsArray[index];
656
657 //const bool bWantPostFadeValues = true; //v Turn this into a checkbox on MixerBoard? For now, always true.
658 //if (bSuccess && bWantPostFadeValues)
659 //vvv Need to apply envelope, too? See Mixer::MixSameRate.
660 float volume = pTrack->GetChannelVolume(0);
661 for (unsigned int index = 0; index < nFrames; index++)
662 meterFloatsArray[2 * index] *= volume;
663 volume = pTrack->GetChannelVolume(1);
664 for (unsigned int index = 0; index < nFrames; index++)
665 meterFloatsArray[(2 * index) + 1] *= volume;
666 // Clip to [-1.0, 1.0] range.
667 for (unsigned int index = 0; index < 2 * nFrames; index++)
668 if (meterFloatsArray[index] < -1.0)
669 meterFloatsArray[index] = -1.0;
670 else if (meterFloatsArray[index] > 1.0)
671 meterFloatsArray[index] = 1.0;
672
673 if (mMeter)
674 mMeter->UpdateDisplay(2, nFrames, meterFloatsArray.get());
675}
676
677// private
678
680{
681 return wxColour(102, 255, 102); // same as Meter playback color
682}
683
684
685// event handlers
686
687void MixerTrackCluster::HandleSelect(bool bShiftDown, bool bControlDown)
688{
690 *mTrack, bShiftDown, bControlDown, true);
691}
692
693void MixerTrackCluster::OnMouseEvent(wxMouseEvent& event)
694{
695 if (event.ButtonUp())
696 this->HandleSelect(event.ShiftDown(), event.ControlDown());
697 else
698 event.Skip();
699}
700
701void MixerTrackCluster::OnPaint(wxPaintEvent & WXUNUSED(event))
702{
704
705 auto selected = mTrack->GetSelected();
706
707 wxColour col = theTheme.Colour(selected ? clrTrackInfoSelected : clrTrackInfo) ;
708 SetBackgroundColour( col );
709 if (mMeter)
710 mMeter->SetBackgroundColour( col );
711 mStaticText_TrackName->SetBackgroundColour( col );
714
715 wxPaintDC dc(this);
716
717 AColor::MediumTrackInfo(&dc, selected);
718 dc.DrawRectangle(this->GetClientRect());
719
720 wxSize clusterSize = this->GetSize();
721 wxRect bev(0, 0, clusterSize.GetWidth() - 1, clusterSize.GetHeight() - 1);
722
723 //bev.Inflate(-1, -1);
724 AColor::Bevel(dc, true, bev);// same bevel whether selected or not.
725}
726
727
728void MixerTrackCluster::OnButton_MusicalInstrument(wxCommandEvent& WXUNUSED(event))
729{
730 const auto &state = ::wxGetMouseState();
731 this->HandleSelect(state.ShiftDown(), state.ControlDown());
732}
733
734void MixerTrackCluster::OnSlider_Gain(wxCommandEvent& WXUNUSED(event))
735{
736 this->HandleSliderGain();
737}
738
739void MixerTrackCluster::OnSlider_Velocity(wxCommandEvent& WXUNUSED(event))
740{
741 this->HandleSliderVelocity();
742}
743
744void MixerTrackCluster::OnSlider_Pan(wxCommandEvent& WXUNUSED(event))
745{
746 this->HandleSliderPan();
747}
748
749void MixerTrackCluster::OnButton_Mute(wxCommandEvent& WXUNUSED(event))
750{
753 mToggleButton_Mute->SetAlternateIdx(mTrack->GetSolo() ? 1 : 0);
754
755 // Update the TrackPanel correspondingly.
756 if (TracksBehaviorsSolo.ReadEnum() == SoloBehaviorSimple)
757 Viewport::Get(*mProject).Redraw();
758 else
759 // Update only the changed track.
760 TrackPanel::Get( *mProject ).RefreshTrack(mTrack.get());
761}
762
763void MixerTrackCluster::OnButton_Solo(wxCommandEvent& WXUNUSED(event))
764{
767 bool bIsSolo = mTrack->GetSolo();
768 mToggleButton_Mute->SetAlternateIdx(bIsSolo ? 1 : 0);
769
770 // Update the TrackPanel correspondingly.
771 // Bug 509: Must repaint all, as many tracks can change with one Solo change.
772 Viewport::Get(*mProject).Redraw();
773}
774
775
776// class MusicalInstrument
777
778MusicalInstrument::MusicalInstrument(std::unique_ptr<wxBitmap> &&pBitmap, const wxString & strXPMfilename)
779{
780 mBitmap = std::move(pBitmap);
781
782 int nUnderscoreIndex;
783 wxString strFilename = strXPMfilename;
784 strFilename.MakeLower(); // Make sure, so we don't have to do case insensitive comparison.
785 wxString strKeyword;
786 while ((nUnderscoreIndex = strFilename.Find(wxT('_'))) != -1)
787 {
788 strKeyword = strFilename.Left(nUnderscoreIndex);
789 mKeywords.push_back(strKeyword);
790 strFilename = strFilename.Mid(nUnderscoreIndex + 1);
791 }
792 if (!strFilename.empty()) // Skip trailing underscores.
793 mKeywords.push_back(strFilename); // Add the last one.
794}
795
797{
798 mKeywords.clear();
799}
800
801
802// class MixerBoardScrolledWindow
803
804// wxScrolledWindow ignores mouse clicks in client area,
805// but they don't get passed to Mixerboard.
806// We need to catch them to deselect all track clusters.
807
808BEGIN_EVENT_TABLE(MixerBoardScrolledWindow, wxScrolledWindow)
811
813 MixerBoard* parent, wxWindowID id /*= -1*/,
814 const wxPoint& pos /*= wxDefaultPosition*/,
815 const wxSize& size /*= wxDefaultSize*/,
816 long style /*= wxHSCROLL | wxVSCROLL*/)
817: wxScrolledWindow(parent, id, pos, size, style)
818{
819 mMixerBoard = parent;
820 mProject = project;
821}
822
824{
825}
826
828{
829 if (event.ButtonUp())
830 {
831 //v Even when I implement MixerBoard::OnMouseEvent and call event.Skip()
832 // here, MixerBoard::OnMouseEvent never gets called.
833 // So, added mProject to MixerBoardScrolledWindow and just directly do what's needed here.
835 }
836 else
837 event.Skip();
838}
839
840
841// class MixerBoard
842
843#define MIXER_BOARD_MIN_HEIGHT 460
844
845// Min width is one cluster wide, plus margins.
846#define MIXER_BOARD_MIN_WIDTH kTripleInset + kMixerTrackClusterWidth*2 + kTripleInset
847
848
849BEGIN_EVENT_TABLE(MixerBoard, wxWindow)
850 EVT_PAINT(MixerBoard::OnPaint)
851 EVT_SIZE(MixerBoard::OnSize)
853
855 wxFrame* parent,
856 const wxPoint& pos /*= wxDefaultPosition*/,
857 const wxSize& size /*= wxDefaultSize*/)
858: wxWindow(parent, -1, pos, size)
859{
860 // public data members
861
862 // mute & solo button images
863 // Create once and store on MixerBoard for use in all MixerTrackClusters.
864 mImageMuteUp = NULL;
865 mImageMuteOver = NULL;
866 mImageMuteDown = NULL;
867 mImageMuteDownWhileSolo = NULL;
868 mImageMuteDisabled = NULL;
869 mImageSoloUp = NULL;
870 mImageSoloOver = NULL;
871 mImageSoloDown = NULL;
872 mImageSoloDisabled = NULL;
873
874 mMuteSoloWidth = kRightSideStackWidth - kInset; // correct for max width, but really set in MixerBoard::CreateMuteSoloImages
875
876 // private data members
877 this->LoadMusicalInstruments(); // Set up mMusicalInstruments.
878 mProject = pProject;
879
880 wxASSERT(pProject); // to justify safenew
881 mScrolledWindow =
883 pProject, // AudacityProject* project,
884 this, -1, // wxWindow* parent, wxWindowID id = -1,
885 this->GetClientAreaOrigin(), // const wxPoint& pos = wxDefaultPosition,
886 size, // const wxSize& size = wxDefaultSize,
887 wxHSCROLL); // long style = wxHSCROLL | wxVSCROLL, const wxString& name = "scrolledWindow")
888
889 // Set background color to same as TrackPanel background.
890// mScrolledWindow->SetBackgroundColour(this->GetParent()->GetBackgroundColour());
891 mScrolledWindow->SetBackgroundColour( theTheme.Colour( clrMedium ) );
892 RTL_WORKAROUND(mScrolledWindow);
893
894 mScrolledWindow->SetScrollRate(10, 0); // no vertical scroll
895 mScrolledWindow->SetVirtualSize(size);
896
897 /* This doesn't work to make the mScrolledWindow automatically resize, so do it explicitly in OnSize.
898 auto pBoxSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
899 pBoxSizer->push_back(mScrolledWindow, 0, wxExpand, 0);
900 this->SetAutoLayout(true);
901 this->SetSizer(pBoxSizer);
902 pBoxSizer->Fit(this);
903 pBoxSizer->SetSizeHints(this);
904 */
905
906 mPrevT1 = 0.0;
907 mTracks = &TrackList::Get( *mProject );
908
909 // Events from the project don't propagate directly to this other frame, so...
910 mPlaybackScrollerSubscription =
913
914 mTrackPanelSubscription =
915 PendingTracks::Get(*mProject).Subscribe([this](const TrackListEvent &event){
916 switch (event.mType) {
917 case TrackListEvent::SELECTION_CHANGE:
918 case TrackListEvent::TRACK_DATA_CHANGE:
919 OnTrackChanged(event); break;
920 case TrackListEvent::PERMUTED:
921 case TrackListEvent::ADDITION:
922 case TrackListEvent::DELETION:
923 OnTrackSetChanged(); break;
924 default:
925 break;
926 }
927 });
928
929 mAudioIOSubscription =
931}
932
933
934
935
937{
938 // Destroys this:
939 static_cast<MixerBoardFrame*>(GetParent())->Recreate( mProject );
940
941// Old approach modified things in situ.
942// However with a theme change there is so much to modify, it is easier
943// to recreate.
944#if 0
945 mScrolledWindow->SetBackgroundColour( theTheme.Colour( clrMedium ) );
946 if( mImageMuteUp ){
947 mImageMuteUp.reset();
948 mImageMuteOver.reset();
949 mImageMuteDown.reset();
951 mImageMuteDisabled.reset();
952 mImageSoloUp.reset();
953 mImageSoloOver.reset();
954 mImageSoloDown.reset();
955 mImageSoloDisabled.reset();
956 }
957 for (unsigned int nClusterIndex = 0; nClusterIndex < mMixerTrackClusters.size(); nClusterIndex++)
958 mMixerTrackClusters[nClusterIndex]->UpdatePrefs();
959 Refresh();
960#endif
961}
962
963// Reassign mixer input strips (MixerTrackClusters) to Track Clusters
964// both have the same order.
965// Note Tracks appear in the mixer,
966// and we must be able to convert and reuse a MixerTrackCluster
967// from audio to midi or midi to audio. This task is handled by
968// UpdateForStateChange().
969//
971{
972 if (!mImageMuteUp)
973 this->CreateMuteSoloImages();
974
975 const int nClusterHeight = mScrolledWindow->GetClientSize().GetHeight() - kDoubleInset;
976 size_t nClusterCount = mMixerTrackClusters.size();
977 unsigned int nClusterIndex = 0;
978 MixerTrackCluster* pMixerTrackCluster = NULL;
979
980 for (auto pPlayableTrack: mTracks->Any<PlayableTrack>()) {
981 // TODO: more-than-two-channels
982 auto spTrack = pPlayableTrack->SharedPointer<PlayableTrack>();
983 // Track iterations always yield non-null pointers; maintain invariant
984 // when reassigning
985 assert(spTrack);
986 if (nClusterIndex < nClusterCount)
987 {
988 // Already showing it.
989 // Track clusters are maintained in the same order as the WaveTracks.
990 // Track pointers can change for the "same" track for different states
991 // on the undo stack, so update the pointers and display name.
992 mMixerTrackClusters[nClusterIndex]->mTrack = spTrack;
993 // Assume linked track is wave or null
994 mMixerTrackClusters[nClusterIndex]->UpdateForStateChange();
995 }
996 else
997 {
998 // Not already showing it. Add a NEW MixerTrackCluster.
999 wxPoint clusterPos(
1000 kInset + nClusterIndex * kMixerTrackClusterWidth,
1001 kInset);
1002 wxSize clusterSize(kMixerTrackClusterWidth, nClusterHeight);
1003 pMixerTrackCluster =
1005 *spTrack, clusterPos, clusterSize);
1006 if (pMixerTrackCluster)
1007 mMixerTrackClusters.push_back(pMixerTrackCluster);
1008 }
1009 nClusterIndex++;
1010 }
1011
1012 if (pMixerTrackCluster)
1013 {
1014 // Added at least one MixerTrackCluster.
1015 this->UpdateWidth();
1016 this->ResizeTrackClusters();
1017 }
1018 else while (nClusterIndex < nClusterCount)
1019 {
1020 // We've got too many clusters.
1021 // This can happen only on things like Undo New Audio Track or Undo Import
1022 // that don't call RemoveTrackCluster explicitly.
1023 // We've already updated the track pointers for the clusters to the left, so just remove all the rest.
1024 // Successively DELETE from right to left.
1025 RemoveTrackCluster(--nClusterCount);
1026 }
1027}
1028
1030{
1031 return
1032 kInset + // extra margin at left for first one
1033 (mMixerTrackClusters.size() * // number of tracks times
1034 (kInset + kMixerTrackClusterWidth)) + // left margin and width for each
1035 kDoubleInset; // plus final right margin
1036}
1037
1039{
1040 auto pMixerTrackCluster = mMixerTrackClusters[nIndex];
1041 mMixerTrackClusters.erase(mMixerTrackClusters.begin() + nIndex);
1042 pMixerTrackCluster->Destroy(); // DELETE is unsafe on wxWindow.
1043
1044 // Close the gap, if any.
1045 wxPoint pos;
1046 int targetX;
1047 for (unsigned int i = nIndex; i < mMixerTrackClusters.size(); i++)
1048 {
1049 pos = mMixerTrackClusters[i]->GetPosition();
1050 targetX =
1051 kInset + // extra inset to left for first one, so it's double
1052 (i * (kInset + kMixerTrackClusterWidth)) + // left margin and width for each
1053 kInset; // plus left margin for this cluster
1054 if (pos.x != targetX)
1055 mMixerTrackClusters[i]->Move(targetX, pos.y);
1056 }
1057
1058 this->UpdateWidth();
1059}
1060
1061
1063{
1064 if (mMusicalInstruments.empty())
1065 return NULL;
1066
1067 // random choice: return mMusicalInstruments[(int)pTrack % mMusicalInstruments.size()].mBitmap;
1068
1069 const wxString strTrackName(
1070 wxString{ pTrack->GetName() }.MakeLower());
1071 size_t nBestItemIndex = 0;
1072 unsigned int nBestScore = 0;
1073 unsigned int nInstrIndex = 0;
1074 unsigned int nKeywordIndex;
1075 unsigned int nNumKeywords;
1076 unsigned int nPointsPerMatch;
1077 unsigned int nScore;
1078 for (nInstrIndex = 0; nInstrIndex < mMusicalInstruments.size(); nInstrIndex++)
1079 {
1080 nScore = 0;
1081
1082 nNumKeywords = mMusicalInstruments[nInstrIndex]->mKeywords.size();
1083 if (nNumKeywords > 0)
1084 {
1085 nPointsPerMatch = 10 / nNumKeywords;
1086 for (nKeywordIndex = 0; nKeywordIndex < nNumKeywords; nKeywordIndex++)
1087 if (strTrackName.Contains(mMusicalInstruments[nInstrIndex]->mKeywords[nKeywordIndex]))
1088 {
1089 nScore +=
1090 nPointsPerMatch +
1091 // Longer keywords get more points.
1092 (2 * mMusicalInstruments[nInstrIndex]->mKeywords[nKeywordIndex].length());
1093 }
1094 }
1095
1096 // Choose later one if just matching nBestScore, for better variety,
1097 // and so default works as last element.
1098 if (nScore >= nBestScore)
1099 {
1100 nBestScore = nScore;
1101 nBestItemIndex = nInstrIndex;
1102 }
1103 }
1104 return mMusicalInstruments[nBestItemIndex]->mBitmap.get();
1105}
1106
1108{
1109 return
1111}
1112
1113void MixerBoard::RefreshTrackClusters(bool bEraseBackground /*= true*/)
1114{
1115 for (unsigned int i = 0; i < mMixerTrackClusters.size(); i++)
1116 mMixerTrackClusters[i]->Refresh(bEraseBackground);
1117}
1118
1120{
1121 for (unsigned int nClusterIndex = 0; nClusterIndex < mMixerTrackClusters.size(); nClusterIndex++)
1122 mMixerTrackClusters[nClusterIndex]->HandleResize();
1123}
1124
1125void MixerBoard::ResetMeters(const bool bResetClipping)
1126{
1128
1129 if (!this->IsShown())
1130 return;
1131
1132 for (unsigned int i = 0; i < mMixerTrackClusters.size(); i++)
1133 mMixerTrackClusters[i]->ResetMeter(bResetClipping);
1134}
1135
1136void MixerBoard::UpdateMeters(const double t1, const bool bLoopedPlay)
1137{
1138 if (!this->IsShown() || (t1 == BAD_STREAM_TIME))
1139 return;
1140
1141 if (mPrevT1 == BAD_STREAM_TIME)
1142 {
1143 mPrevT1 = t1;
1144 return;
1145 }
1146
1147 // PRL: TODO: reexamine the assumptions below
1148
1149 // In loopedPlay mode, at the end of the loop, mPrevT1 is set to
1150 // selection end, so the next t1 will be less, but we do want to
1151 // keep updating the meters.
1152 if (t1 <= mPrevT1)
1153 {
1154 if (bLoopedPlay)
1155 mPrevT1 = t1;
1156 return;
1157 }
1158
1159 for (unsigned int i = 0; i < mMixerTrackClusters.size(); i++)
1160 mMixerTrackClusters[i]->UpdateMeter(mPrevT1, t1);
1161
1162 mPrevT1 = t1;
1163}
1164
1165
1167{
1168 int newWidth = this->GetTrackClustersWidth();
1169
1170 // Min width is one cluster wide, plus margins.
1171 if (newWidth < MIXER_BOARD_MIN_WIDTH)
1172 newWidth = MIXER_BOARD_MIN_WIDTH;
1173
1174 mScrolledWindow->SetVirtualSize(newWidth, -1);
1175 this->GetParent()->SetSize(newWidth + kDoubleInset, -1);
1176}
1177
1178//
1179// private methods
1180//
1181
1182
1183void MixerBoard::MakeButtonBitmap( wxMemoryDC & dc, wxBitmap & WXUNUSED(bitmap), wxRect & bev, const TranslatableString & str, bool up )
1184{
1185
1186 const auto translation = str.Translation();
1187 int textWidth, textHeight;
1188
1189 int fontSize = 10;
1190 #ifdef __WXMSW__
1191 fontSize = 8;
1192 #endif
1193 wxFont font(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1194 GetTextExtent(translation, &textWidth, &textHeight, NULL, NULL, &font);
1195
1196 AColor::UseThemeColour( &dc, clrMedium );
1197 dc.DrawRectangle(bev);
1198
1199 AColor::Bevel2( dc, up, bev, false );
1200
1201 wxCoord x = bev.x + (bev.width - textWidth) / 2;
1202 wxCoord y = bev.y + (bev.height - textHeight) / 2;
1203 dc.SetFont(font);
1204 dc.SetTextForeground(theTheme.Colour(clrTrackPanelText));
1205 dc.SetBackgroundMode(wxTRANSPARENT);
1206 dc.DrawText(translation, x, y);
1207// dc.DrawText(translation, 0, 0);
1208}
1209
1211{
1212 // Much of this is similar to TrackInfo::MuteOrSoloDrawFunction.
1213 wxMemoryDC dc;
1214 auto str = XO("Mute");
1215
1216 //mMuteSoloWidth = textWidth + kQuadrupleInset;
1217 //if (mMuteSoloWidth < kRightSideStackWidth - kInset)
1219
1220 wxBitmap bitmap(mMuteSoloWidth, MUTE_SOLO_HEIGHT,24);
1221 dc.SelectObject(bitmap);
1222 wxRect bev(0, 0, mMuteSoloWidth, MUTE_SOLO_HEIGHT);
1223
1224 const bool up=true;
1225 const bool down=false;
1226
1227 MakeButtonBitmap( dc, bitmap, bev, str, up );
1228 mImageMuteUp = std::make_unique<wxImage>(bitmap.ConvertToImage());
1229 mImageMuteOver = std::make_unique<wxImage>(bitmap.ConvertToImage()); // Same as up, for now.
1230
1231 MakeButtonBitmap( dc, bitmap, bev, str, down );
1232 //AColor::Bevel(dc, false, bev);
1233 mImageMuteDown = std::make_unique<wxImage>(bitmap.ConvertToImage());
1234
1235 MakeButtonBitmap( dc, bitmap, bev, str, down );
1236 mImageMuteDownWhileSolo = std::make_unique<wxImage>(bitmap.ConvertToImage());
1237
1238 mImageMuteDisabled = std::make_unique<wxImage>(mMuteSoloWidth, MUTE_SOLO_HEIGHT); // Leave empty because unused.
1239
1240 str = XO("Solo");
1241 MakeButtonBitmap( dc, bitmap, bev, str, up );
1242 mImageSoloUp = std::make_unique<wxImage>(bitmap.ConvertToImage());
1243 mImageSoloOver = std::make_unique<wxImage>(bitmap.ConvertToImage()); // Same as up, for now.
1244
1245 MakeButtonBitmap( dc, bitmap, bev, str, down );
1246 mImageSoloDown = std::make_unique<wxImage>(bitmap.ConvertToImage());
1247
1248 mImageSoloDisabled = std::make_unique<wxImage>(mMuteSoloWidth, MUTE_SOLO_HEIGHT); // Leave empty because unused.
1249}
1250
1252 MixerTrackCluster** hMixerTrackCluster) const
1253{
1254 *hMixerTrackCluster = NULL;
1255 for (unsigned int i = 0; i < mMixerTrackClusters.size(); i++)
1256 {
1257 if (mMixerTrackClusters[i]->mTrack.get() == pTrack)
1258 {
1259 *hMixerTrackCluster = mMixerTrackClusters[i];
1260 return i;
1261 }
1262 }
1263 return -1;
1264}
1265
1267{
1268 const struct Data { const char * const *bitmap; wxString name; } table[] = {
1269 {acoustic_guitar_gtr_xpm, wxT("acoustic_guitar_gtr")},
1270 {acoustic_piano_pno_xpm, wxT("acoustic_piano_pno")},
1271 {back_vocal_bg_vox_xpm, wxT("back_vocal_bg_vox")},
1272 {clap_xpm, wxT("clap")},
1273 {drums_dr_xpm, wxT("drums_dr")},
1274 {electric_bass_guitar_bs_gtr_xpm, wxT("electric_bass_guitar_bs_gtr")},
1275 {electric_guitar_gtr_xpm, wxT("electric_guitar_gtr")},
1276 {electric_piano_pno_key_xpm, wxT("electric_piano_pno_key")},
1277 {kick_xpm, wxT("kick")},
1278 {loop_xpm, wxT("loop")},
1279 {organ_org_xpm, wxT("organ_org")},
1280 {perc_xpm, wxT("perc")},
1281 {sax_xpm, wxT("sax")},
1282 {snare_xpm, wxT("snare")},
1283 {string_violin_cello_xpm, wxT("string_violin_cello")},
1284 {synth_xpm, wxT("synth")},
1285 {tambo_xpm, wxT("tambo")},
1286 {trumpet_horn_xpm, wxT("trumpet_horn")},
1287 {turntable_xpm, wxT("turntable")},
1288 {vibraphone_vibes_xpm, wxT("vibraphone_vibes")},
1289 {vocal_vox_xpm, wxT("vocal_vox")},
1290
1291 // This one must be last, so it wins when best score is 0.
1292 {_default_instrument_xpm, wxEmptyString},
1293 };
1294
1296 wxMemoryDC dc;
1297
1298 for (const auto &data : table) {
1299 auto bmp = std::make_unique<wxBitmap>(data.bitmap);
1300 dc.SelectObject(*bmp);
1301 AColor::Bevel(dc, false, bev);
1302 mMusicalInstruments.push_back(std::make_unique<MusicalInstrument>(
1303 std::move(bmp), data.name
1304 ));
1305 };
1306}
1307
1308// event handlers
1309
1310void MixerBoard::OnPaint(wxPaintEvent& evt)
1311{
1312 if (!mUpToDate) {
1313 mUpToDate = true;
1315 Refresh();
1316 }
1317 // Does the base class do anything for repainting?
1318 evt.Skip();
1319}
1320
1321void MixerBoard::OnSize(wxSizeEvent &evt)
1322{
1323 // this->FitInside() doesn't work, and it doesn't happen automatically. Is wxScrolledWindow wrong?
1324 mScrolledWindow->SetSize(evt.GetSize());
1325
1326 this->ResizeTrackClusters();
1327 this->RefreshTrackClusters(true);
1328}
1329
1331{
1332 // PRL 12 Jul 2015: Moved the below (with comments) out of TrackPanel::OnTimer.
1333
1334 // Vaughan, 2011-01-28: No longer doing this on timer.
1335 // Now it's in AudioIO::SetMeters() and AudioIO::StopStream(), as with Meter Toolbar meters.
1336 //if (pMixerBoard)
1337 // pMixerBoard->ResetMeters(false);
1338
1339 //v Vaughan, 2011-02-25: Moved this update back here from audacityAudioCallback.
1340 // See note there.
1341 // Vaughan, 2010-01-30:
1342 // Since all we're doing here is updating the meters, I moved it to
1343 // audacityAudioCallback where it calls gAudioIO->mOutputMeter->UpdateDisplay().
1344 if (ProjectAudioIO::Get( *mProject ).IsAudioActive())
1345 {
1346 auto gAudioIO = AudioIO::Get();
1348 gAudioIO->GetStreamTime(),
1351 );
1352 }
1353}
1354
1356{
1357 auto pTrack = evt.mpTrack.lock();
1358 auto pPlayable = dynamic_cast<PlayableTrack*>( pTrack.get() );
1359 if ( pPlayable ) {
1360 MixerTrackCluster *pMixerTrackCluster;
1361 FindMixerTrackCluster( pPlayable, &pMixerTrackCluster );
1362 if ( pMixerTrackCluster )
1363 pMixerTrackCluster->Refresh();
1364 }
1365}
1366
1368{
1369 mUpToDate = false;
1371 Refresh();
1372}
1373
1375{
1376 if (evt.type == AudioIOEvent::PLAYBACK)
1377 ResetMeters( evt.on );
1378}
1379
1380// class MixerBoardFrame
1381
1382BEGIN_EVENT_TABLE(MixerBoardFrame, wxFrame)
1383 EVT_KEY_DOWN(MixerBoardFrame::OnKeyEvent)
1385 EVT_MAXIMIZE(MixerBoardFrame::OnMaximize)
1386 EVT_SIZE(MixerBoardFrame::OnSize)
1388
1389// Default to fitting one track.
1390const wxSize kDefaultSize =
1392
1394: wxFrame( &GetProjectFrame( *parent ), -1, wxString{},
1395 wxDefaultPosition, kDefaultSize,
1396 wxDEFAULT_FRAME_STYLE | wxFRAME_FLOAT_ON_PARENT)
1397 , mProject(parent)
1398{
1399 SetWindowTitle();
1400 mTitleChangeSubscription = ProjectFileIO::Get(*parent)
1401 .Subscribe([this](ProjectFileIOMessage message){
1403 SetWindowTitle();
1404 });
1405
1406 mMixerBoard = safenew MixerBoard(parent, this, wxDefaultPosition, kDefaultSize);
1407
1408 this->SetSizeHints(MIXER_BOARD_MIN_WIDTH, MIXER_BOARD_MIN_HEIGHT);
1409
1410 mMixerBoard->UpdateTrackClusters();
1411
1412 // loads either the XPM or the windows resource, depending on the platform
1413#if !defined(__WXMAC__) && !defined(__WXX11__)
1414 {
1415#ifdef __WXMSW__
1416 wxIcon ic{ wxICON(AudacityLogo) };
1417#else
1418 wxIcon ic{wxICON(AudacityLogo48x48)};
1419#endif
1420 SetIcon(ic);
1421 }
1422#endif
1423 Center();
1424}
1425
1427{
1428}
1429
1430
1431// event handlers
1432void MixerBoardFrame::OnCloseWindow(wxCloseEvent &WXUNUSED(event))
1433{
1434 // Fix for bug #2175.
1435 //
1436 // If the mixerboard enters fullscreen, the main project will be
1437 // "lowered", so ensure it's visible after the mixerboard closes.
1438#if defined(__WXMAC__)
1439 dynamic_cast<wxFrame*>(GetParent())->Raise();
1440#endif
1441
1442 this->Hide();
1443}
1444
1445void MixerBoardFrame::OnMaximize(wxMaximizeEvent &event)
1446{
1447 // Update the size hints to show all tracks before skipping to let default handling happen.
1449 event.Skip();
1450}
1451
1452void MixerBoardFrame::OnSize(wxSizeEvent & WXUNUSED(event))
1453{
1454 mMixerBoard->SetSize(this->GetClientSize());
1455}
1456
1457void MixerBoardFrame::OnKeyEvent(wxKeyEvent & event)
1458{
1459 if (auto project = mMixerBoard->mProject)
1460 MenuCreator::FilterKeyEvent(*project, event, true);
1461}
1462
1464{
1465 wxPoint pos = mMixerBoard->GetPosition();
1466 wxSize siz = mMixerBoard->GetSize();
1467 wxSize siz2 = this->GetSize();
1468
1469 //wxLogDebug("Got rid of board %p", mMixerBoard );
1470 mMixerBoard->Destroy();
1471 mMixerBoard = NULL;
1472 mMixerBoard = safenew MixerBoard(pProject, this, pos, siz);
1473 //wxLogDebug("Created NEW board %p", mMixerBoard );
1475 mMixerBoard->SetSize( siz );
1476
1477 this->SetSize( siz2 );
1479}
1480
1482{
1483 wxString name = mProject->GetProjectName();
1484 if (!name.empty())
1485 {
1486 name.Prepend(wxT(" - "));
1487 }
1488
1489 SetTitle(AudacityMixerBoardTitle.Format(name).Translation());
1490}
1491
1492// Remaining code hooks this add-on into the application
1493#include "CommandContext.h"
1494
1495namespace {
1496
1499 [](const AudacityProject &project){
1500 auto &tracks = TrackList::Get( project );
1501 return
1502 !tracks.Any<const NoteTrack>().empty()
1503 ||
1504 !tracks.Any<const WaveTrack>().empty()
1505 ;
1506 }
1507 }; return flag; }
1508
1509// Mixer board window attached to each project is built on demand by:
1510AttachedWindows::RegisteredFactory sMixerBoardKey{
1511 []( AudacityProject &parent ) -> wxWeakRef< wxWindow > {
1512 return safenew MixerBoardFrame( &parent );
1513 }
1514};
1515
1516// Define our extra menu item that invokes that factory
1517void OnMixerBoard(const CommandContext &context)
1518{
1519 auto &project = context.project;
1520
1521 auto mixerBoardFrame = &GetAttachedWindows(project).Get(sMixerBoardKey);
1522 mixerBoardFrame->Show();
1523 mixerBoardFrame->Raise();
1524 mixerBoardFrame->SetFocus();
1525}
1526
1527// Register that menu item
1528
1529using namespace MenuRegistry;
1531 Command( wxT("MixerBoard"), XXO("&Mixer"), OnMixerBoard,
1533 wxT("View/Windows")
1534};
1535
1536}
1537
#define VEL_SLIDER
Definition: ASlider.h:37
#define DB_SLIDER
Definition: ASlider.h:33
#define PAN_SLIDER
Definition: ASlider.h:34
wxEVT_COMMAND_BUTTON_CLICKED
wxT("CloseDown"))
#define BAD_STREAM_TIME
Definition: AudioIOBase.h:40
An audio segment is either a whole clip or the silence between clips. Views allow shared references t...
std::vector< AudioSegmentSampleView > ChannelSampleView
END_EVENT_TABLE()
#define str(a)
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define RTL_WORKAROUND(pWnd)
Definition: GUISettings.h:20
#define _(s)
Definition: Internat.h:73
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
Definition: LabelDialog.cpp:89
#define safenew
Definition: MemoryX.h:10
const int MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH
Definition: MixerBoard.cpp:143
const int kDoubleInset
Definition: MixerBoard.cpp:138
const int kMixerTrackClusterWidth
Definition: MixerBoard.cpp:149
const int kQuadrupleInset
Definition: MixerBoard.cpp:140
const int MUTE_SOLO_HEIGHT
Definition: MixerBoard.cpp:144
const int PAN_HEIGHT
Definition: MixerBoard.cpp:145
const int kTripleInset
Definition: MixerBoard.cpp:139
const int kLeftSideStackWidth
Definition: MixerBoard.cpp:147
const int kInset
Definition: MixerBoard.cpp:137
#define MIXER_BOARD_MIN_WIDTH
Definition: MixerBoard.cpp:846
const int kRightSideStackWidth
Definition: MixerBoard.cpp:148
const int TRACK_NAME_HEIGHT
Definition: MixerBoard.cpp:142
#define MIXER_BOARD_MIN_HEIGHT
Definition: MixerBoard.cpp:843
const wxSize kDefaultSize
#define AudacityMixerBoardTitle
Definition: MixerBoard.cpp:72
@ ID_BITMAPBUTTON_MUSICAL_INSTRUMENT
Definition: MixerBoard.cpp:152
@ ID_SLIDER_PAN
Definition: MixerBoard.cpp:153
@ ID_SLIDER_VELOCITY
Definition: MixerBoard.cpp:155
@ ID_SLIDER_GAIN
Definition: MixerBoard.cpp:154
@ ID_TOGGLEBUTTON_MUTE
Definition: MixerBoard.cpp:156
@ ID_TOGGLEBUTTON_SOLO
Definition: MixerBoard.cpp:157
EnumSetting< SoloBehavior > TracksBehaviorsSolo
@ SoloBehaviorSimple
Definition: PlayableTrack.h:70
ProjectFileIOMessage
Subscribe to ProjectFileIO to receive messages; always in idle time.
Definition: ProjectFileIO.h:50
@ ProjectTitleChange
A normal occurrence.
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
AUDACITY_DLL_API AttachedWindows & GetAttachedWindows(AudacityProject &project)
accessors for certain important windows associated with each project
wxString name
Definition: TagsEditor.cpp:166
const auto tracks
const auto project
THEME_API Theme theTheme
Definition: Theme.cpp:82
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
static std::once_flag flag
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
void PushDown()
Definition: AButton.cpp:664
void SetAlternateIdx(unsigned idx)
Definition: AButton.cpp:287
void PopUp()
Definition: AButton.cpp:672
bool WasShiftDown()
Definition: AButton.cpp:628
static void Bevel2(wxDC &dc, bool up, const wxRect &r, bool bSel=false, bool bHighlight=false)
Definition: AColor.cpp:298
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:278
static void MediumTrackInfo(wxDC *dc, bool selected)
Definition: AColor.cpp:415
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:354
ASlider is a custom slider, allowing for a slicker look and feel.
Definition: ASlider.h:260
void Set(float value)
Definition: ASlider.cpp:1864
int mStyle
Definition: ASlider.h:353
void OnMouseEvent(wxMouseEvent &event)
Definition: ASlider.cpp:1801
bool SetBackgroundColour(const wxColour &colour) override
Definition: ASlider.cpp:1743
float Get(bool convert=true)
Definition: ASlider.cpp:1859
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:59
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
const wxString & GetProjectName() const
Definition: Project.cpp:100
static AudioIO * Get()
Definition: AudioIO.cpp:126
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
Definition: ClientData.h:318
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
static bool FilterKeyEvent(AudacityProject &project, const wxKeyEvent &evt, bool permit=false)
MeterPanel is a panel that paints the meter used for monitoring or playback.
Definition: MeterPanel.h:91
@ MixerTrackCluster
Definition: MeterPanel.h:101
void OnKeyEvent(wxKeyEvent &evt)
void OnMaximize(wxMaximizeEvent &event)
void OnCloseWindow(wxCloseEvent &WXUNUSED(event))
AudacityProject * mProject
Definition: MixerBoard.h:287
void OnSize(wxSizeEvent &evt)
MixerBoard * mMixerBoard
Definition: MixerBoard.h:289
virtual ~MixerBoardFrame()
void Recreate(AudacityProject *pProject)
bool mUpToDate
Definition: MixerBoard.h:260
void OnSize(wxSizeEvent &evt)
void OnStartStop(AudioIOEvent)
int FindMixerTrackCluster(const PlayableTrack *pTrack, MixerTrackCluster **hMixerTrackCluster) const
std::unique_ptr< wxImage > mImageMuteDownWhileSolo
Definition: MixerBoard.h:242
void UpdateWidth()
void ResizeTrackClusters()
MusicalInstrumentArray mMusicalInstruments
Definition: MixerBoard.h:255
void UpdateMeters(const double t1, const bool bLoopedPlay)
void OnPaint(wxPaintEvent &evt)
void OnTrackSetChanged()
TrackList * mTracks
Definition: MixerBoard.h:259
std::unique_ptr< wxImage > mImageMuteDown
Definition: MixerBoard.h:241
std::unique_ptr< wxImage > mImageMuteDisabled
Definition: MixerBoard.h:243
std::unique_ptr< wxImage > mImageMuteOver
Definition: MixerBoard.h:241
std::unique_ptr< wxImage > mImageSoloDown
Definition: MixerBoard.h:243
void MakeButtonBitmap(wxMemoryDC &dc, wxBitmap &bitmap, wxRect &bev, const TranslatableString &str, bool up)
void UpdatePrefs() override
Definition: MixerBoard.cpp:936
void OnTimer(Observer::Message)
MixerBoardScrolledWindow * mScrolledWindow
Definition: MixerBoard.h:257
std::unique_ptr< wxImage > mImageMuteUp
Definition: MixerBoard.h:241
wxBitmap * GetMusicalInstrumentBitmap(const Track *pTrack)
void OnTrackChanged(const TrackListEvent &event)
void UpdateTrackClusters()
Definition: MixerBoard.cpp:970
bool HasSolo()
void ResetMeters(const bool bResetClipping)
std::unique_ptr< wxImage > mImageSoloDisabled
Definition: MixerBoard.h:243
std::unique_ptr< wxImage > mImageSoloUp
Definition: MixerBoard.h:243
int GetTrackClustersWidth()
void RemoveTrackCluster(size_t nIndex)
void CreateMuteSoloImages()
std::unique_ptr< wxImage > mImageSoloOver
Definition: MixerBoard.h:243
void LoadMusicalInstruments()
AudacityProject * mProject
Definition: MixerBoard.h:256
std::vector< MixerTrackCluster * > mMixerTrackClusters
Definition: MixerBoard.h:253
void RefreshTrackClusters(bool bEraseBackground=true)
int mMuteSoloWidth
Definition: MixerBoard.h:245
double mPrevT1
Definition: MixerBoard.h:258
AudacityProject * mProject
Definition: MixerBoard.h:181
virtual ~MixerBoardScrolledWindow()
Definition: MixerBoard.cpp:823
void OnMouseEvent(wxMouseEvent &event)
Definition: MixerBoard.cpp:827
void HandleSliderVelocity(const bool bWantPushState=false)
Definition: MixerBoard.cpp:414
wxBitmapButton * mBitmapButton_MusicalInstrument
Definition: MixerBoard.h:135
void OnSlider_Gain(wxCommandEvent &event)
Definition: MixerBoard.cpp:734
void HandleSliderGain(const bool bWantPushState=false)
Definition: MixerBoard.cpp:401
void UpdateForStateChange()
Definition: MixerBoard.cpp:453
void OnButton_MusicalInstrument(wxCommandEvent &event)
Definition: MixerBoard.cpp:728
std::shared_ptr< PlayableTrack > mTrack
Invariant not null.
Definition: MixerBoard.h:127
AudacityProject * mProject
Definition: MixerBoard.h:131
NoteTrack * GetNote() const
Definition: MixerBoard.cpp:351
void ResetMeter(const bool bResetClipping)
Definition: MixerBoard.cpp:443
void OnSlider_Pan(wxCommandEvent &event)
Definition: MixerBoard.cpp:744
WaveTrack * GetWave() const
Definition: MixerBoard.cpp:334
AButton * mToggleButton_Mute
Definition: MixerBoard.h:136
ChannelGroupSampleView mSampleView
Definition: MixerBoard.h:142
MixerBoard * mMixerBoard
Definition: MixerBoard.h:130
wxWeakRef< MeterPanel > mMeter
Definition: MixerBoard.h:141
MixerTrackSlider * mSlider_Volume
Definition: MixerBoard.h:139
void UpdateMeter(const double t0, const double t1)
Definition: MixerBoard.cpp:519
void OnPaint(wxPaintEvent &evt)
Definition: MixerBoard.cpp:701
void OnButton_Mute(wxCommandEvent &event)
Definition: MixerBoard.cpp:749
WaveChannel * GetRight() const
Definition: MixerBoard.cpp:339
void HandleSelect(bool bShiftDown, bool bControlDown)
Definition: MixerBoard.cpp:687
wxColour GetTrackColor()
Definition: MixerBoard.cpp:679
void OnMouseEvent(wxMouseEvent &event)
Definition: MixerBoard.cpp:693
void OnSlider_Velocity(wxCommandEvent &event)
Definition: MixerBoard.cpp:739
MixerTrackSlider * mSlider_Velocity
Definition: MixerBoard.h:140
void OnButton_Solo(wxCommandEvent &event)
Definition: MixerBoard.cpp:763
MixerTrackSlider * mSlider_Pan
Definition: MixerBoard.h:138
void HandleSliderPan(const bool bWantPushState=false)
Definition: MixerBoard.cpp:428
auStaticText * mStaticText_TrackName
Definition: MixerBoard.h:134
AButton * mToggleButton_Solo
Definition: MixerBoard.h:137
void OnCaptureKey(wxCommandEvent &event)
Definition: MixerBoard.cpp:116
void OnFocus(wxFocusEvent &event)
Definition: MixerBoard.cpp:111
void OnMouseEvent(wxMouseEvent &event)
Definition: MixerBoard.cpp:95
MusicalInstrument(std::unique_ptr< wxBitmap > &&pBitmap, const wxString &strXPMfilename)
Definition: MixerBoard.cpp:778
virtual ~MusicalInstrument()
Definition: MixerBoard.cpp:796
std::unique_ptr< wxBitmap > mBitmap
Definition: MixerBoard.h:155
wxArrayString mKeywords
Definition: MixerBoard.h:156
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:78
void SetVelocity(float velocity)
Definition: NoteTrack.cpp:514
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
static PendingTracks & Get(AudacityProject &project)
AudioTrack subclass that can also be audibly replayed by the program.
Definition: PlayableTrack.h:40
bool GetSolo() const
Definition: PlayableTrack.h:48
bool IsAudioActive() const
static ProjectAudioIO & Get(AudacityProject &project)
static ProjectAudioManager & Get(AudacityProject &project)
PlayMode GetLastPlayMode() const
static ProjectFileIO & Get(AudacityProject &project)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
PlaybackScroller & GetPlaybackScroller()
static ProjectWindow & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Definition: Registry.h:388
wxColour & Colour(int iIndex)
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
const wxString & GetName() const
Name is always the same for all channels of a group.
Definition: Track.cpp:64
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:950
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
void RefreshTrack(Track *trk, bool refreshbacking=true)
Definition: TrackPanel.cpp:768
Holds a msgid for the translation catalog; may also bind format arguments.
void Redraw()
Definition: Viewport.cpp:753
static Viewport & Get(AudacityProject &project)
Definition: Viewport.cpp:33
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
void SetPan(float newPan)
Definition: WaveTrack.cpp:870
void SetVolume(float newVolume)
Definition: WaveTrack.cpp:852
is like wxStaticText, except it can be themed. wxStaticText can't be.
Definition: auStaticText.h:20
Positions or offsets within audio files need a wide type.
Definition: SampleCount.h:19
void OnFocus(wxWindow &window, wxFocusEvent &event)
a function useful to implement a focus event handler The window releases the keyboard if the event is...
constexpr auto Command
Definition: MenuRegistry.h:456
void SelectNone(AudacityProject &project)
void DoListSelection(AudacityProject &project, Track &t, bool shift, bool ctrl, bool modifyState)
AUDACITY_DLL_API void DoTrackSolo(AudacityProject &project, Track &track, bool exclusive)
AUDACITY_DLL_API void DoTrackMute(AudacityProject &project, Track &track, bool exclusive)
"exclusive" mute means mute the chosen track and unmute all others.
const ReservedCommandFlag & PlayableTracksExistFlag()
size_t GetNumSamplesInView(const ChannelSampleView &view)
Definition: MixerBoard.cpp:497
void FillBufferWithSampleView(float *buffer, const ChannelSampleView &view)
Definition: MixerBoard.cpp:507
AttachedWindows::RegisteredFactory sMixerBoardKey
void OnMixerBoard(const CommandContext &context)
double GetRate(const Track &track)
Definition: TimeTrack.cpp:182
Options & Style(int s)
Definition: ASlider.h:280
bool on
Definition: AudioIO.h:68
enum AudioIOEvent::Type type
Default message type for Publisher.
Definition: Observer.h:26
Notification of changes in individual tracks of TrackList, or of TrackList's composition.
Definition: Track.h:803
const std::weak_ptr< Track > mpTrack
Definition: Track.h:838