Audacity  2.2.2
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ExportMixerPanel Class Referencefinal

Panel that displays mixing for advanced mixing option. More...

#include <Export.h>

Inheritance diagram for ExportMixerPanel:
wxPanelWrapper wxTabTraversalWrapper< wxPanel >

Public Member Functions

 ExportMixerPanel (MixerSpec *mixerSpec, wxArrayString trackNames, wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 
virtual ~ExportMixerPanel ()
 
void OnMouseEvent (wxMouseEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&...args)
 
 ~wxTabTraversalWrapper ()
 

Private Member Functions

void SetFont (wxMemoryDC &memDC, const wxString &text, int width, int height)
 
double Distance (wxPoint &a, wxPoint &b)
 
bool IsOnLine (wxPoint p, wxPoint la, wxPoint lb)
 

Private Attributes

std::unique_ptr< wxBitmap > mBitmap
 
wxRect mEnvRect
 
int mWidth
 
int mHeight
 
MixerSpecmMixerSpec
 
ArrayOf< wxRect > mChannelRects
 
ArrayOf< wxRect > mTrackRects
 
int mSelectedTrack
 
int mSelectedChannel
 
wxArrayString mTrackNames
 
int mBoxWidth
 
int mChannelHeight
 
int mTrackHeight
 

Detailed Description

Panel that displays mixing for advanced mixing option.

Definition at line 220 of file Export.h.

Constructor & Destructor Documentation

ExportMixerPanel::ExportMixerPanel ( MixerSpec mixerSpec,
wxArrayString  trackNames,
wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize 
)

Definition at line 1008 of file Export.cpp.

1010  :
1011  wxPanelWrapper(parent, id, pos, size)
1012  , mMixerSpec{mixerSpec}
1015 {
1016  mBitmap = NULL;
1017  mWidth = 0;
1018  mHeight = 0;
1020 
1021  mTrackNames = trackNames;
1022 }
int mSelectedChannel
Definition: Export.h:239
ArrayOf< wxRect > mTrackRects
Definition: Export.h:238
int mSelectedTrack
Definition: Export.h:239
unsigned GetNumTracks()
Definition: Mix.h:75
wxArrayString mTrackNames
Definition: Export.h:240
std::unique_ptr< wxBitmap > mBitmap
Definition: Export.h:232
unsigned GetMaxNumChannels()
Definition: Mix.h:74
ArrayOf< wxRect > mChannelRects
Definition: Export.h:237
MixerSpec * mMixerSpec
Definition: Export.h:236
ExportMixerPanel::~ExportMixerPanel ( )
virtual

Definition at line 1024 of file Export.cpp.

1025 {
1026 }

Member Function Documentation

double ExportMixerPanel::Distance ( wxPoint &  a,
wxPoint &  b 
)
private

Definition at line 1167 of file Export.cpp.

Referenced by IsOnLine().

1168 {
1169  return sqrt( pow( a.x - b.x, 2.0 ) + pow( a.y - b.y, 2.0 ) );
1170 }
bool ExportMixerPanel::IsOnLine ( wxPoint  p,
wxPoint  la,
wxPoint  lb 
)
private

Definition at line 1173 of file Export.cpp.

References Distance().

Referenced by OnMouseEvent().

1174 {
1175  return Distance( p, la ) + Distance( p, lb ) - Distance( la, lb ) < 0.1;
1176 }
double Distance(wxPoint &a, wxPoint &b)
Definition: Export.cpp:1167
void ExportMixerPanel::OnMouseEvent ( wxMouseEvent &  event)

Definition at line 1178 of file Export.cpp.

References MixerSpec::GetNumChannels(), MixerSpec::GetNumTracks(), IsOnLine(), mBoxWidth, mChannelHeight, mChannelRects, MixerSpec::mMap, mMixerSpec, mSelectedChannel, mSelectedTrack, mTrackHeight, and mTrackRects.

1179 {
1180  if( event.ButtonDown() )
1181  {
1182  bool reset = true;
1183  //check tracks
1184  for( unsigned int i = 0; i < mMixerSpec->GetNumTracks(); i++ )
1185  if( mTrackRects[ i ].Contains( event.m_x, event.m_y ) )
1186  {
1187  reset = false;
1188  if( mSelectedTrack == (int)i )
1189  mSelectedTrack = -1;
1190  else
1191  {
1192  mSelectedTrack = i;
1193  if( mSelectedChannel != -1 )
1196  }
1197  goto found;
1198  }
1199 
1200  //check channels
1201  for( unsigned int i = 0; i < mMixerSpec->GetNumChannels(); i++ )
1202  if( mChannelRects[ i ].Contains( event.m_x, event.m_y ) )
1203  {
1204  reset = false;
1205  if( mSelectedChannel == (int)i )
1206  mSelectedChannel = -1;
1207  else
1208  {
1209  mSelectedChannel = i;
1210  if( mSelectedTrack != -1 )
1213  }
1214  goto found;
1215  }
1216 
1217  //check links
1218  for( unsigned int i = 0; i < mMixerSpec->GetNumTracks(); i++ )
1219  for( unsigned int j = 0; j < mMixerSpec->GetNumChannels(); j++ )
1220  if( mMixerSpec->mMap[ i ][ j ] && IsOnLine( wxPoint( event.m_x,
1221  event.m_y ), wxPoint( mTrackRects[ i ].x + mBoxWidth,
1222  mTrackRects[ i ].y + mTrackHeight / 2 ),
1223  wxPoint( mChannelRects[ j ].x, mChannelRects[ j ].y +
1224  mChannelHeight / 2 ) ) )
1225  mMixerSpec->mMap[ i ][ j ] = false;
1226 
1227 found:
1228  if( reset )
1230  Refresh( false );
1231  }
1232 }
int mSelectedChannel
Definition: Export.h:239
ArrayOf< wxRect > mTrackRects
Definition: Export.h:238
int mSelectedTrack
Definition: Export.h:239
bool IsOnLine(wxPoint p, wxPoint la, wxPoint lb)
Definition: Export.cpp:1173
unsigned GetNumTracks()
Definition: Mix.h:75
ArraysOf< bool > mMap
Definition: Mix.h:65
unsigned GetNumChannels()
Definition: Mix.h:72
ArrayOf< wxRect > mChannelRects
Definition: Export.h:237
int mChannelHeight
Definition: Export.h:241
int mTrackHeight
Definition: Export.h:241
MixerSpec * mMixerSpec
Definition: Export.h:236
void ExportMixerPanel::OnPaint ( wxPaintEvent &  event)

Definition at line 1050 of file Export.cpp.

References _(), AColor::envelopeBrush, MixerSpec::GetNumChannels(), MixerSpec::GetNumTracks(), AColor::Line(), mBitmap, mBoxWidth, mChannelHeight, mChannelRects, mHeight, MixerSpec::mMap, mMixerSpec, mSelectedChannel, mSelectedTrack, mTrackHeight, mTrackNames, mTrackRects, mWidth, PI, AColor::playRegionBrush, and SetFont().

1051 {
1052  wxPaintDC dc( this );
1053 
1054  int width, height;
1055  GetSize( &width, &height );
1056 
1057  if( !mBitmap || mWidth != width || mHeight != height )
1058  {
1059  mWidth = width;
1060  mHeight = height;
1061  mBitmap = std::make_unique<wxBitmap>( mWidth, mHeight );
1062  }
1063 
1064  wxColour bkgnd = GetBackgroundColour();
1065  wxBrush bkgndBrush( bkgnd, wxSOLID );
1066 
1067  wxMemoryDC memDC;
1068  memDC.SelectObject( *mBitmap );
1069 
1070  //draw background
1071  wxRect bkgndRect;
1072  bkgndRect.x = 0;
1073  bkgndRect.y = 0;
1074  bkgndRect.width = mWidth;
1075  bkgndRect.height = mHeight;
1076 
1077  memDC.SetBrush( *wxWHITE_BRUSH );
1078  memDC.SetPen( *wxBLACK_PEN );
1079  memDC.DrawRectangle( bkgndRect );
1080 
1081  //box dimensions
1082  mBoxWidth = mWidth / 6;
1083 
1084  mTrackHeight = ( mHeight * 3 ) / ( mMixerSpec->GetNumTracks() * 4 );
1085  if( mTrackHeight > 30 )
1086  mTrackHeight = 30;
1087 
1088  mChannelHeight = ( mHeight * 3 ) / ( mMixerSpec->GetNumChannels() * 4 );
1089  if( mChannelHeight > 30 )
1090  mChannelHeight = 30;
1091 
1092  static double PI = 2 * acos( 0.0 );
1093  double angle = atan( ( 3.0 * mHeight ) / mWidth );
1094  double radius = mHeight / ( 2.0 * sin( PI - 2.0 * angle ) );
1095  double totAngle = ( asin( mHeight / ( 2.0 * radius ) ) * 2.0 );
1096 
1097  //draw tracks
1098  memDC.SetBrush( AColor::envelopeBrush );
1099  angle = totAngle / ( mMixerSpec->GetNumTracks() + 1 );
1100 
1101  int max = 0, w, h;
1102  for( unsigned int i = 1; i < mMixerSpec->GetNumTracks(); i++ )
1103  if( mTrackNames[ i ].length() > mTrackNames[ max ].length() )
1104  max = i;
1105 
1106  SetFont( memDC, mTrackNames[ max ], mBoxWidth, mTrackHeight );
1107 
1108  for( unsigned int i = 0; i < mMixerSpec->GetNumTracks(); i++ )
1109  {
1110  mTrackRects[ i ].x = (int)( mBoxWidth * 2 + radius - radius *
1111  cos( totAngle / 2.0 - angle * ( i + 1 ) ) - mBoxWidth + 0.5 );
1112  mTrackRects[ i ].y = (int)( mHeight * 0.5 - radius *
1113  sin( totAngle * 0.5 - angle * ( i + 1.0 ) ) -
1114  0.5 * mTrackHeight + 0.5 );
1115 
1116  mTrackRects[ i ].width = mBoxWidth;
1117  mTrackRects[ i ].height = mTrackHeight;
1118 
1119  memDC.SetPen( mSelectedTrack == (int)i ? *wxRED_PEN : *wxBLACK_PEN );
1120  memDC.DrawRectangle( mTrackRects[ i ] );
1121 
1122  memDC.GetTextExtent( mTrackNames[ i ], &w, &h );
1123  memDC.DrawText( mTrackNames[ i ],
1124  mTrackRects[ i ].x + ( mBoxWidth - w ) / 2,
1125  mTrackRects[ i ].y + ( mTrackHeight - h ) / 2 );
1126  }
1127 
1128  //draw channels
1129  memDC.SetBrush( AColor::playRegionBrush[ 0 ] );
1130  angle = ( asin( mHeight / ( 2.0 * radius ) ) * 2.0 ) /
1131  ( mMixerSpec->GetNumChannels() + 1 );
1132 
1133  SetFont( memDC, wxT( "Channel: XX" ), mBoxWidth, mChannelHeight );
1134  memDC.GetTextExtent( wxT( "Channel: XX" ), &w, &h );
1135 
1136  for( unsigned int i = 0; i < mMixerSpec->GetNumChannels(); i++ )
1137  {
1138  mChannelRects[ i ].x = (int)( mBoxWidth * 4 - radius + radius *
1139  cos( totAngle * 0.5 - angle * ( i + 1 ) ) + 0.5 );
1140  mChannelRects[ i ].y = (int)( mHeight * 0.5 - radius *
1141  sin( totAngle * 0.5 - angle * ( i + 1 ) ) -
1142  0.5 * mChannelHeight + 0.5 );
1143 
1144  mChannelRects[ i ].width = mBoxWidth;
1145  mChannelRects[ i ].height = mChannelHeight;
1146 
1147  memDC.SetPen( mSelectedChannel == (int)i ? *wxRED_PEN : *wxBLACK_PEN );
1148  memDC.DrawRectangle( mChannelRects[ i ] );
1149 
1150  memDC.DrawText( wxString::Format( _( "Channel: %2d" ), i + 1 ),
1151  mChannelRects[ i ].x + ( mBoxWidth - w ) / 2,
1152  mChannelRects[ i ].y + ( mChannelHeight - h ) / 2 );
1153  }
1154 
1155  //draw links
1156  memDC.SetPen( wxPen( *wxBLACK, mHeight / 200 ) );
1157  for( unsigned int i = 0; i < mMixerSpec->GetNumTracks(); i++ )
1158  for( unsigned int j = 0; j < mMixerSpec->GetNumChannels(); j++ )
1159  if( mMixerSpec->mMap[ i ][ j ] )
1160  AColor::Line(memDC, mTrackRects[ i ].x + mBoxWidth,
1161  mTrackRects[ i ].y + mTrackHeight / 2, mChannelRects[ j ].x,
1162  mChannelRects[ j ].y + mChannelHeight / 2 );
1163 
1164  dc.Blit( 0, 0, mWidth, mHeight, &memDC, 0, 0, wxCOPY, FALSE );
1165 }
#define PI
Definition: ScienFilter.cpp:62
int mSelectedChannel
Definition: Export.h:239
ArrayOf< wxRect > mTrackRects
Definition: Export.h:238
int mSelectedTrack
Definition: Export.h:239
void SetFont(wxMemoryDC &memDC, const wxString &text, int width, int height)
Definition: Export.cpp:1029
unsigned GetNumTracks()
Definition: Mix.h:75
ArraysOf< bool > mMap
Definition: Mix.h:65
wxArrayString mTrackNames
Definition: Export.h:240
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
static wxBrush envelopeBrush
Definition: AColor.h:124
std::unique_ptr< wxBitmap > mBitmap
Definition: Export.h:232
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
unsigned GetNumChannels()
Definition: Mix.h:72
ArrayOf< wxRect > mChannelRects
Definition: Export.h:237
int mChannelHeight
Definition: Export.h:241
int mTrackHeight
Definition: Export.h:241
static wxBrush playRegionBrush[2]
Definition: AColor.h:115
MixerSpec * mMixerSpec
Definition: Export.h:236
void ExportMixerPanel::SetFont ( wxMemoryDC &  memDC,
const wxString &  text,
int  width,
int  height 
)
private

Definition at line 1029 of file Export.cpp.

Referenced by OnPaint().

1031 {
1032  int l = 0, u = 13, m, w, h;
1033  wxFont font = memDC.GetFont();
1034  while( l < u - 1 )
1035  {
1036  m = ( l + u ) / 2;
1037  font.SetPointSize( m );
1038  memDC.SetFont( font );
1039  memDC.GetTextExtent( text, &w, &h );
1040 
1041  if( w < width && h < height )
1042  l = m;
1043  else
1044  u = m;
1045  }
1046  font.SetPointSize( l );
1047  memDC.SetFont( font );
1048 }

Member Data Documentation

std::unique_ptr<wxBitmap> ExportMixerPanel::mBitmap
private

Definition at line 232 of file Export.h.

Referenced by OnPaint().

int ExportMixerPanel::mBoxWidth
private

Definition at line 241 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mChannelHeight
private

Definition at line 241 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

ArrayOf<wxRect> ExportMixerPanel::mChannelRects
private

Definition at line 237 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

wxRect ExportMixerPanel::mEnvRect
private

Definition at line 233 of file Export.h.

int ExportMixerPanel::mHeight
private

Definition at line 235 of file Export.h.

Referenced by OnPaint().

MixerSpec* ExportMixerPanel::mMixerSpec
private

Definition at line 236 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mSelectedChannel
private

Definition at line 239 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mSelectedTrack
private

Definition at line 239 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mTrackHeight
private

Definition at line 241 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

wxArrayString ExportMixerPanel::mTrackNames
private

Definition at line 240 of file Export.h.

Referenced by OnPaint().

ArrayOf<wxRect> ExportMixerPanel::mTrackRects
private

Definition at line 238 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mWidth
private

Definition at line 234 of file Export.h.

Referenced by OnPaint().


The documentation for this class was generated from the following files: