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 (wxWindow *parent, wxWindowID id, MixerSpec *mixerSpec, wxArrayString trackNames, 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)
 

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 235 of file Export.h.

Constructor & Destructor Documentation

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

Definition at line 1016 of file Export.cpp.

1019  :
1020  wxPanelWrapper(parent, id, pos, size)
1021  , mMixerSpec{mixerSpec}
1024 {
1025  mBitmap = NULL;
1026  mWidth = 0;
1027  mHeight = 0;
1029 
1030  mTrackNames = trackNames;
1031 }
int mSelectedChannel
Definition: Export.h:255
ArrayOf< wxRect > mTrackRects
Definition: Export.h:254
int mSelectedTrack
Definition: Export.h:255
unsigned GetNumTracks()
Definition: Mix.h:75
wxArrayString mTrackNames
Definition: Export.h:256
std::unique_ptr< wxBitmap > mBitmap
Definition: Export.h:248
unsigned GetMaxNumChannels()
Definition: Mix.h:74
ArrayOf< wxRect > mChannelRects
Definition: Export.h:253
MixerSpec * mMixerSpec
Definition: Export.h:252
ExportMixerPanel::~ExportMixerPanel ( )
virtual

Definition at line 1033 of file Export.cpp.

1034 {
1035 }

Member Function Documentation

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

Definition at line 1176 of file Export.cpp.

Referenced by IsOnLine().

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

Definition at line 1182 of file Export.cpp.

References Distance().

Referenced by OnMouseEvent().

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

Definition at line 1187 of file Export.cpp.

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

1188 {
1189  if( event.ButtonDown() )
1190  {
1191  bool reset = true;
1192  //check tracks
1193  for( unsigned int i = 0; i < mMixerSpec->GetNumTracks(); i++ )
1194  if( mTrackRects[ i ].Contains( event.m_x, event.m_y ) )
1195  {
1196  reset = false;
1197  if( mSelectedTrack == (int)i )
1198  mSelectedTrack = -1;
1199  else
1200  {
1201  mSelectedTrack = i;
1202  if( mSelectedChannel != -1 )
1205  }
1206  goto found;
1207  }
1208 
1209  //check channels
1210  for( unsigned int i = 0; i < mMixerSpec->GetNumChannels(); i++ )
1211  if( mChannelRects[ i ].Contains( event.m_x, event.m_y ) )
1212  {
1213  reset = false;
1214  if( mSelectedChannel == (int)i )
1215  mSelectedChannel = -1;
1216  else
1217  {
1218  mSelectedChannel = i;
1219  if( mSelectedTrack != -1 )
1222  }
1223  goto found;
1224  }
1225 
1226  //check links
1227  for( unsigned int i = 0; i < mMixerSpec->GetNumTracks(); i++ )
1228  for( unsigned int j = 0; j < mMixerSpec->GetNumChannels(); j++ )
1229  if( mMixerSpec->mMap[ i ][ j ] && IsOnLine( wxPoint( event.m_x,
1230  event.m_y ), wxPoint( mTrackRects[ i ].x + mBoxWidth,
1231  mTrackRects[ i ].y + mTrackHeight / 2 ),
1232  wxPoint( mChannelRects[ j ].x, mChannelRects[ j ].y +
1233  mChannelHeight / 2 ) ) )
1234  mMixerSpec->mMap[ i ][ j ] = false;
1235 
1236 found:
1237  if( reset )
1239  Refresh( false );
1240  }
1241 }
int mSelectedChannel
Definition: Export.h:255
ArrayOf< wxRect > mTrackRects
Definition: Export.h:254
int mSelectedTrack
Definition: Export.h:255
bool IsOnLine(wxPoint p, wxPoint la, wxPoint lb)
Definition: Export.cpp:1182
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:253
int mChannelHeight
Definition: Export.h:257
int mTrackHeight
Definition: Export.h:257
MixerSpec * mMixerSpec
Definition: Export.h:252
void ExportMixerPanel::OnPaint ( wxPaintEvent &  event)

Definition at line 1059 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().

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

Definition at line 1038 of file Export.cpp.

Referenced by OnPaint().

1040 {
1041  int l = 0, u = 13, m, w, h;
1042  wxFont font = memDC.GetFont();
1043  while( l < u - 1 )
1044  {
1045  m = ( l + u ) / 2;
1046  font.SetPointSize( m );
1047  memDC.SetFont( font );
1048  memDC.GetTextExtent( text, &w, &h );
1049 
1050  if( w < width && h < height )
1051  l = m;
1052  else
1053  u = m;
1054  }
1055  font.SetPointSize( l );
1056  memDC.SetFont( font );
1057 }

Member Data Documentation

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

Definition at line 248 of file Export.h.

Referenced by OnPaint().

int ExportMixerPanel::mBoxWidth
private

Definition at line 257 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mChannelHeight
private

Definition at line 257 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

ArrayOf<wxRect> ExportMixerPanel::mChannelRects
private

Definition at line 253 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

wxRect ExportMixerPanel::mEnvRect
private

Definition at line 249 of file Export.h.

int ExportMixerPanel::mHeight
private

Definition at line 251 of file Export.h.

Referenced by OnPaint().

MixerSpec* ExportMixerPanel::mMixerSpec
private

Definition at line 252 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mSelectedChannel
private

Definition at line 255 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mSelectedTrack
private

Definition at line 255 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mTrackHeight
private

Definition at line 257 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

wxArrayString ExportMixerPanel::mTrackNames
private

Definition at line 256 of file Export.h.

Referenced by OnPaint().

ArrayOf<wxRect> ExportMixerPanel::mTrackRects
private

Definition at line 254 of file Export.h.

Referenced by OnMouseEvent(), and OnPaint().

int ExportMixerPanel::mWidth
private

Definition at line 250 of file Export.h.

Referenced by OnPaint().


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