📄 meter.cpp
字号:
mBar[j].tailPeakCount+msg.headPeakCount[j] >= mNumPeakSamplesToClip) mBar[j].clipping = true; mBar[j].tailPeakCount = msg.tailPeakCount[j]; } } // while if (numChanges > 0) RepaintBarsNow();}wxFont Meter::GetFont(){ int fontSize = 10;#if defined __WXMSW__ fontSize = 8;#endif return wxFont(fontSize, wxSWISS, wxNORMAL, wxNORMAL);}void Meter::ResetBar(MeterBar *b, bool resetClipping){ b->peak = 0.0; b->rms = 0.0; b->peakHold = 0.0; b->peakHoldTime = 0.0; if (resetClipping) { b->clipping = false; b->peakPeakHold =0.0; } b->tailPeakCount = 0;}void Meter::HandleLayout(){ int iconWidth = mIcon->GetWidth(); int iconHeight = mIcon->GetHeight(); int menuWidth = 17; int menuHeight = 14; int width = mWidth; int height = mHeight; int left = 0, top = 0; int right, bottom; int barw, barh; int i;#ifdef USE_AQUA_THEME if (!mBackgroundBitmap || mBackgroundBitmap->GetWidth() != mWidth || mBackgroundBitmap->GetWidth() != mHeight) { if (mBackgroundBitmap) delete mBackgroundBitmap; wxImage *image = CreateAquaBackground(mWidth, mHeight, 0); mBackgroundBitmap = new wxBitmap(image); delete image; }#endif mRuler.SetFlip(true); mRuler.SetLabelEdges(true); switch(mStyle) { default: wxPrintf(wxT("Style not handled yet!\n")); case Disable: break; case VerticalStereo: mMenuRect = wxRect(mWidth - menuWidth - 5, mHeight - menuHeight - 2, menuWidth, menuHeight); if (mHeight < (menuHeight + iconHeight + 8)) mIconPos = wxPoint(-999, -999); // Don't display else mIconPos = wxPoint(mWidth - iconWidth - 1, 1); width = intmin(mWidth-(iconWidth+2), mWidth-(menuWidth+3)); if (width >= mLeftSize.x + mRightSize.x + 24) { mLeftTextPos = wxPoint(2, height-2-mLeftSize.y); mRightTextPos = wxPoint(width-mLeftSize.x, height-2-mLeftSize.y); left += mLeftSize.x+4; width -= mLeftSize.x + mRightSize.x + 8; } barw = (width-2)/2; barh = height - 4; mNumBars = 2; mBar[0].vert = true; ResetBar(&mBar[0], false); mBar[0].r = wxRect(left + width/2 - barw - 1, 2, barw, barh); if (mClip) { mBar[0].rClip = mBar[0].r; mBar[0].rClip.height = 3; mBar[0].r.y += 4; mBar[0].r.height -= 4; } mBar[1].vert = true; ResetBar(&mBar[1], false); mBar[1].r = wxRect(left + width/2 + 1, 2, barw, barh); if (mClip) { mBar[1].rClip = mBar[1].r; mBar[1].rClip.height = 3; mBar[1].r.y += 4; mBar[1].r.height -= 4; } mRuler.SetOrientation(wxVERTICAL); mRuler.SetBounds(mBar[1].r.x + mBar[1].r.width + 1, mBar[1].r.y, mBar[1].r.x + width, mBar[1].r.height); if (mDB) { mRuler.SetRange(0, -mDBRange); mRuler.SetFormat(Ruler::LinearDBFormat); } else { mRuler.SetRange(1, 0); mRuler.SetFormat(Ruler::RealFormat); } mRuler.OfflimitsPixels(mMenuRect.y-mBar[1].r.y, mBar[1].r.height); break; case HorizontalStereo: if (mWidth < menuWidth + iconWidth + 8) { mIconPos = wxPoint(-999, -999); // Don't display icon mMenuRect = wxRect(2, mHeight - menuHeight - 2, menuWidth, menuHeight); } else { mIconPos = wxPoint(2, mHeight - iconHeight); mMenuRect = wxRect(iconWidth + 2, mHeight - menuHeight - 5, menuWidth, menuHeight); } height = intmin(height-(menuHeight+3), height-iconHeight) - 2; left = 2 + intmax(mLeftSize.x, mRightSize.x); width -= left; mLeftTextPos = wxPoint(2, (height)/4 - mLeftSize.y/2); mRightTextPos = wxPoint(2, (height*3)/4 - mLeftSize.y/2); barw = width - 4; barh = (height-2)/2; mNumBars = 2; mBar[0].vert = false; ResetBar(&mBar[0], false); mBar[0].r = wxRect(left+2, height/2 - barh - 1, barw, barh); if (mClip) { mBar[0].rClip = mBar[0].r; mBar[0].rClip.x += mBar[0].rClip.width-3; mBar[0].rClip.width = 3; mBar[0].r.width -= 4; } mBar[1].vert = false; ResetBar(&mBar[1], false); mBar[1].r = wxRect(left+2, height/2 + 1, barw, barh); if (mClip) { mBar[1].rClip = mBar[1].r; mBar[1].rClip.x += mBar[1].rClip.width-3; mBar[1].rClip.width = 3; mBar[1].r.width -= 4; } mRuler.SetOrientation(wxHORIZONTAL); mRuler.SetBounds(mBar[1].r.x, mBar[1].r.y + mBar[1].r.height + 1, mBar[1].r.x + mBar[1].r.width, mWidth); if (mDB) { mRuler.SetRange(-mDBRange, 0); mRuler.SetFormat(Ruler::LinearDBFormat); } else { mRuler.SetRange(0, 1); mRuler.SetFormat(Ruler::RealFormat); } mRuler.OfflimitsPixels(0, mMenuRect.x+mMenuRect.width-4); break; case Waveform: mNumBars = 0; break; } if (mNumBars > 0) { // Compute bounding rectangle of all bars (to save time when // blitting just the bars to the screen) left = mBar[0].r.x; top = mBar[0].r.y; right = mBar[0].r.x + mBar[0].r.width; bottom = mBar[0].r.y + mBar[0].r.height; for(i=1; i<mNumBars; i++) { left = intmin(left, mBar[i].r.x); top = intmin(top, mBar[i].r.y); right = intmax(right, mBar[i].r.x + mBar[i].r.width); bottom = intmax(bottom, mBar[i].r.y + mBar[i].r.height); left = intmin(left, mBar[i].rClip.x); top = intmin(top, mBar[i].rClip.y); right = intmax(right, mBar[i].rClip.x + mBar[i].rClip.width); bottom = intmax(bottom, mBar[i].rClip.y + mBar[i].rClip.height); } mAllBarsRect = wxRect(left, top, right-left+1, bottom-top+1); } CreateIcon(mIconPos.y % 4); mLayoutValid = true;}void Meter::HandlePaint(wxDC &dc){ int i; dc.SetFont(GetFont()); if (mLeftSize.x == 0) { dc.GetTextExtent(mLeftText, &mLeftSize.x, &mLeftSize.y); dc.GetTextExtent(mRightText, &mRightSize.x, &mRightSize.y); } if (!mLayoutValid) HandleLayout();#ifdef USE_AQUA_THEME dc.DrawBitmap(*mBackgroundBitmap, 0, 0);#else dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(mBkgndBrush); dc.DrawRectangle(0, 0, mWidth, mHeight);#endif dc.DrawBitmap(*mIcon, mIconPos.x, mIconPos.y); // Draws a beveled button and a down pointing triangle. // The style and sizing matches the ones in the title // bar of the waveform left-hand-side panels. { wxRect r = mMenuRect; AColor::Bevel(dc, true, r); dc.SetPen(*wxBLACK_PEN); int triWid = 11; int xStart = r.x+3; int yStart = r.y+4; for(i=0;i<=triWid/2;i++){ dc.DrawLine(xStart+i, yStart+i, xStart + triWid - i,yStart+i); } } if (mNumBars>0) mRuler.Draw(dc); dc.SetFont(GetFont()); dc.DrawText(mLeftText, mLeftTextPos.x, mLeftTextPos.y); dc.DrawText(mRightText, mRightTextPos.x, mRightTextPos.y); for(i=0; i<mNumBars; i++) DrawMeterBar(dc, &mBar[i]);}void Meter::RepaintBarsNow(){ if (!mLayoutValid) return; wxClientDC dc(this); int i; #ifdef __WXMAC__ // Mac OS X automatically double-buffers the screen for you, // so our bitmap is unneccessary for(i=0; i<mNumBars; i++) DrawMeterBar(dc, &mBar[i]); #else if (!mBitmap) mBitmap = new wxBitmap(mWidth, mHeight); wxMemoryDC memDC; memDC.SelectObject(*mBitmap); for(i=0; i<mNumBars; i++) DrawMeterBar(memDC, &mBar[i]); dc.Blit(mAllBarsRect.x, mAllBarsRect.y, mAllBarsRect.width, mAllBarsRect.height, &memDC, mAllBarsRect.x, mAllBarsRect.y, wxCOPY, false); #endif }void Meter::DrawMeterBar(wxDC &dc, MeterBar *meterBar){ wxRect r = meterBar->r; wxRect rRMS; dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(mBkgndBrush); dc.DrawRectangle(r); AColor::Bevel(dc, false, r); /* AColor::Dark(&dc, false); for(i=0; i<mNumTicks; i++) if (meterBar->vert) dc.DrawLine(r.x+r.width/2-1, mTick[i], r.x+r.width/2+1, mTick[i]); else dc.DrawLine(mTick[i], r.y+r.height/2-1, mTick[i], r.y+r.height/2+1); */ dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetPen(mPen); if (meterBar->vert) { int ht = (int)(meterBar->peakHold * r.height + 0.5); dc.DrawLine(r.x+1, r.y + r.height - ht, r.x+r.width, r.y + r.height - ht); if (ht > 1) dc.DrawLine(r.x+1, r.y + r.height - ht + 1, r.x+r.width, r.y + r.height - ht + 1); dc.SetPen(mPeakPeakPen); ht = (int)(meterBar->peakPeakHold * r.height + 0.5); dc.DrawLine(r.x+1, r.y + r.height - ht, r.x+r.width, r.y + r.height - ht); if (ht > 1) dc.DrawLine(r.x+1, r.y + r.height - ht + 1, r.x+r.width, r.y + r.height - ht + 1); dc.SetPen(mPen); ht = (int)(meterBar->peak * r.height + 0.5); r = wxRect(r.x, r.y + r.height - ht, r.width, ht); ht = (int)(meterBar->rms * r.height + 0.5); rRMS = wxRect(r.x, r.y + r.height - ht, r.width, ht); } else { int wd = (int)(meterBar->peakHold * r.width + 0.5); dc.DrawLine(r.x + wd, r.y + 1, r.x + wd, r.y + r.height); if (wd > 1) dc.DrawLine(r.x + wd - 1, r.y + 1, r.x + wd - 1, r.y + r.height); dc.SetPen(mPeakPeakPen); wd = (int)(meterBar->peakPeakHold * r.width + 0.5); dc.DrawLine(r.x + wd, r.y + 1, r.x + wd, r.y + r.height); if (wd > 1) dc.DrawLine(r.x + wd - 1, r.y + 1, r.x + wd - 1, r.y + r.height); dc.SetPen(mPen); wd = (int)(meterBar->peak * r.width + 0.5); r = wxRect(r.x, r.y, wd, r.height); wd = (int)(meterBar->rms * r.width + 0.5); rRMS = wxRect(r.x, r.y, wd, r.height); } dc.SetPen(*wxTRANSPARENT_PEN); dc.SetBrush(mBrush); dc.DrawRectangle(r); dc.SetBrush(mRMSBrush); dc.DrawRectangle(rRMS); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.SetPen(mLightPen); dc.DrawLine(r.x, r.y, r.x + r.width, r.y); dc.DrawLine(r.x, r.y, r.x, r.y + r.height); dc.SetPen(mDarkPen); dc.DrawLine(r.x + r.width, r.y, r.x + r.width, r.y + r.height); dc.DrawLine(r.x, r.y + r.height, r.x + r.width + 1, r.y + r.height); if (mClip) { if (meterBar->clipping) dc.SetBrush(mClipBrush); else dc.SetBrush(mBkgndBrush); dc.SetPen(*wxTRANSPARENT_PEN); dc.DrawRectangle(meterBar->rClip); dc.SetBrush(*wxTRANSPARENT_BRUSH); AColor::Bevel(dc, false, meterBar->rClip); }}bool Meter::IsMeterDisabled() {return mMeterDisabled!=0;}void Meter::StartMonitoring(){ if (gAudioIO->IsMonitoring()) gAudioIO->StopStream(); else { if (mMeterDisabled){ wxCommandEvent dummy; OnDisableMeter(dummy); } gAudioIO->StartMonitoring(44100.0); AudacityProject *p = GetActiveProject(); if (p) { MeterToolBar *bar; bar = p->GetMeterToolBar(); if (bar) { Meter *play, *record; bar->GetMeters(&play, &record); gAudioIO->SetMeters(record, play); } } }}//// Pop-up menu handlers//void Meter::OnDisableMeter(wxCommandEvent &evt){ if (mMeterDisabled) //Enable { mLightPen = mSavedLightPen; mDarkPen = mSavedDarkPen; mBkgndBrush = mSavedBkgndBrush; mBrush = mSavedBrush; mRMSBrush = mSavedRMSBrush; mBkgndBrush = mSavedBkgndBrush; mLightPen = mSavedLightPen; SetStyle(mSavedStyle); mMeterDisabled = false; } else { if (mIsInput) { if (gAudioIO->IsMonitoring()) gAudioIO->StopStream(); } mSavedLightPen = mLightPen; mSavedDarkPen = mDarkPen; mSavedBkgndBrush = mBkgndBrush; mSavedBrush = mBrush; mSavedRMSBrush = mRMSBrush; mLightPen = mDisabledPen; mDarkPen = mDisabledPen; mBkgndBrush = mDisabledBkgndBrush; mBrush = mDisabledBkgndBrush; mRMSBrush = mDisabledBkgndBrush; mLayoutValid = false; Refresh(false); mSavedStyle = mStyle; SetStyle(Disable); mMeterDisabled = true; } if (mIsInput) { gPrefs->Write(wxT("/Meter/MeterInputDisabled"), mMeterDisabled); } else { gPrefs->Write(wxT("/Meter/MeterOutputDisabled"), mMeterDisabled); }}void Meter::OnHorizontal(wxCommandEvent &evt){ SetStyle(HorizontalStereo);}void Meter::OnVertical(wxCommandEvent &evt){ SetStyle(VerticalStereo);}void Meter::OnMulti(wxCommandEvent &evt){ SetStyle(VerticalMulti);}void Meter::OnEqualizer(wxCommandEvent &evt){ SetStyle(Equalizer);}void Meter::OnWaveform(wxCommandEvent &evt){ SetStyle(Waveform);}void Meter::OnLinear(wxCommandEvent &evt){ mDB = false; mLayoutValid = false; Refresh(false);}void Meter::OnDB(wxCommandEvent &evt){ mDB = true; mLayoutValid = false; Refresh(false);}void Meter::OnClip(wxCommandEvent &evt){}void Meter::OnMonitor(wxCommandEvent &evt){ StartMonitoring();}void Meter::OnFloat(wxCommandEvent &evt){}void Meter::OnPreferences(wxCommandEvent &evt){ long refreshRate = 0; if (-1 < (refreshRate = ::wxGetNumberFromUser (_("This determines how often the meter is refreshed.\nIf you have a slower PC you may want to select a\nlower refresh rate (30 per second or lower), so that\naudio qualtiy is not affected by the meter display."), _("Meter refresh rate per second [1-100]: "), _("Meter Perferences"), mMeterRefreshRate, 1, 100))) mMeterRefreshRate = refreshRate; gPrefs->Write(wxT("/Meter/MeterRefreshRate"), mMeterRefreshRate); mTimer.Start(1000/mMeterRefreshRate);}// Indentation settings for Vim and Emacs.// Please do not modify past this point.//// Local Variables:// c-basic-offset: 3// indent-tabs-mode: nil// End://// vim: et sts=3 sw=3//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -