コード例 #1
0
ファイル: AudioView.cpp プロジェクト: ruthmagnus/audacity
// What to do when a view is created. Creates actual
// windows for displaying the view.
bool AudioView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
{
  gNumViewsOpen++;

  frame = wxGetApp().CreateChildFrame(doc, this, TRUE);

  //
  // Create Menu Bar
  //

  menuBar = new wxMenuBar();

  fileMenu = new wxMenu();
  fileMenu->Append(wxID_NEW, "&New...\tCtrl+N");
  fileMenu->Append(wxID_OPEN, "&Open...\tCtrl+O");
  fileMenu->Append(wxID_CLOSE, "&Close\tCtrl+W");
  fileMenu->Append(wxID_SAVE, "&Save\tCtrl+S");
  fileMenu->Append(wxID_SAVEAS, "Save As...");
  fileMenu->Append(ExportID, "&Export...");
  fileMenu->AppendSeparator();
  fileMenu->Append(wxID_PRINT, "&Print...\tCtrl+P");
  fileMenu->Append(wxID_PRINT_SETUP, "Print Setup...");
  fileMenu->Append(wxID_PREVIEW, "Print Preview");
  fileMenu->AppendSeparator();
  fileMenu->Append(wxID_EXIT, "E&xit");

  editMenu = new wxMenu();
  editMenu->Append(UndoID, "&Undo\tCtrl+Z");
  editMenu->Append(RedoID, "&Redo\tCtrl+R");
  editMenu->AppendSeparator();
  editMenu->Append(CutID, "Cut\tCtrl+X");
  editMenu->Append(CopyID, "Copy\tCtrl+C");
  editMenu->Append(PasteID, "Paste\tCtrl+V");
  editMenu->Append(ClearID, "Clear\tCtrl+B");
  editMenu->AppendSeparator();
  editMenu->Append(SelectAllID, "Select All\tCtrl+A");

  doc->GetCommandProcessor()->SetEditMenu(editMenu);

  projectMenu = new wxMenu();

  projectMenu->Append(ImportID, "&Import Audio...\tCtrl+I");
  projectMenu->Append(ImportRawID, "Import Raw Data...");
  projectMenu->Append(ImportMIDIID, "Import &MIDI...");
  projectMenu->Append(ImportMP3ID, "Import MP3...");
  projectMenu->AppendSeparator();
  projectMenu->Append(WaveTrackID, "New Audio Track");
  //  projectMenu->Append(LabelTrackID, "New Label Track");
  projectMenu->AppendSeparator();
  projectMenu->Append(RemoveTrackID, "&Remove Track(s)");

  trackMenu = new wxMenu();
  trackMenu->Append(QuickMixID, "Quick Mix");
  trackMenu->AppendSeparator();
  trackMenu->Append(WaveDisplayID, "Waveform Display");
  trackMenu->Append(SpectrumDisplayID, "Spectrum Display");
  trackMenu->AppendSeparator();
  //  trackMenu->Append(AutoCorrelateID, "AutoCorrelate");
  trackMenu->Append(PitchID, "Pitch Extract");
  
  effectMenu = new wxMenu();

  numEffects = Effect::GetNumEffects();
  for(int fi = 0; fi < numEffects; fi++)
    effectMenu->Append(FirstEffectID+fi,
		       (Effect::GetEffect(fi))->GetEffectName());

  helpMenu = new wxMenu;
  helpMenu->Append(wxID_ABOUT, "&About Audacity...");

  menuBar->Append(fileMenu, "&File");
  menuBar->Append(editMenu, "&Edit");
  menuBar->Append(projectMenu, "&Project");
  menuBar->Append(trackMenu, "&Track");
  menuBar->Append(effectMenu, "E&ffect");
  menuBar->Append(helpMenu, "&Help");

  frame->SetMenuBar(menuBar);  
  
  //
  // Make all child windows
  //

  int sbarWidth = 15;

  rulerPanel =
	new RulerPanel(this, frame, wxDefaultPosition,
				   wxSize(600 - labelWidth, 30), 0);

  trackPanel =
	new TrackPanel(this, frame, wxDefaultPosition,
				   wxSize(600, 300), 0);

  hsbar =
	new wxScrollBar(frame, HSBarID, wxDefaultPosition,
					wxSize(600, sbarWidth), wxSB_HORIZONTAL);

  vsbar =
	new wxScrollBar(frame, VSBarID, wxDefaultPosition,
					wxSize(sbarWidth, 300), wxSB_VERTICAL);

  status = new wxStaticText(frame, 0, "", wxDefaultPosition,
			  wxDefaultSize);
  status->SetLabel("");

  wxButton *b1;
  wxButton *b2;
  wxButton *b3;
  wxButton *b4;

  wxBitmap *zoomIn = new wxBitmap();
  wxBitmap *zoomOut = new wxBitmap();
  wxBitmap *play = new wxBitmap();
  wxBitmap *stop = new wxBitmap();

  if (zoomIn->LoadFile(BITMAP_PRE "ZoomIn" BITMAP_SUF,AUDACITY_BITMAP_TYPE) &&
      zoomOut->LoadFile(BITMAP_PRE "ZoomOut" BITMAP_SUF,AUDACITY_BITMAP_TYPE) &&
      play->LoadFile(BITMAP_PRE "Play" BITMAP_SUF,AUDACITY_BITMAP_TYPE) &&
      stop->LoadFile(BITMAP_PRE "Stop" BITMAP_SUF,AUDACITY_BITMAP_TYPE)) {
    
    b1 = (wxButton *)new wxBitmapButton
      (frame, ZoomInButtonID, *zoomIn,
       wxPoint(0, 0), wxSize(36, 36));
    b2 = (wxButton *)new wxBitmapButton
      (frame, ZoomOutButtonID, *zoomOut,
       wxPoint(30, 0), wxSize(36, 36));
    b3 = (wxButton *)new wxBitmapButton
      (frame, PlayButtonID, *play,
	   wxPoint(30, 0), wxSize(36, 36));
    b4 = (wxButton *)new wxBitmapButton
      (frame, StopButtonID, *stop,
       wxPoint(30, 0), wxSize(36, 36));

    b1->SetBackgroundColour(backgroundColor);
    b2->SetBackgroundColour(backgroundColor);
    b3->SetBackgroundColour(backgroundColor);
    b4->SetBackgroundColour(backgroundColor);
  }	  
  else {
	delete zoomIn;
	delete zoomOut;
	delete play;
	delete stop;
	
	b1 = new wxButton(frame, ZoomInButtonID, "<",
					  wxPoint(0, 0), wxSize(36,36));
	b2 = new wxButton(frame, ZoomOutButtonID, ">",
					  wxPoint(0, 0), wxSize(36,36));
	b3 = new wxButton(frame, PlayButtonID, "Play",
					  wxPoint(0, 0), wxSize(128,36));
	b4 = new wxButton(frame, StopButtonID, "Stop",
					  wxPoint(0, 0), wxSize(128,36));
  }

  wxBitmap *smallLogoBitmap = new wxBitmap();
  wxStaticBitmap *smallLogo = 0;
  if (smallLogoBitmap->LoadFile(BITMAP_PRE "AudacitySmall" BITMAP_SUF,
				AUDACITY_BITMAP_TYPE)) {
    smallLogo = new wxStaticBitmap(frame, 0, *smallLogoBitmap,
				   wxDefaultPosition, wxDefaultSize);
  }

  //
  // Lay them out using box sizers
  //

  mainSizer = new wxBoxSizer(wxVERTICAL);
  topSizer = new wxBoxSizer(wxHORIZONTAL);
  bottomSizer = new wxBoxSizer(wxHORIZONTAL);
  trackSizer = new wxBoxSizer(wxVERTICAL);

  mainSizer->Add(topSizer, 1, wxEXPAND, 0);
  mainSizer->Add(bottomSizer, 0, wxEXPAND | wxALL, 2);

  topSizer->Add(trackSizer, 1, wxEXPAND, 0);
  topSizer->Add(vsbar, 0, wxEXPAND | wxBOTTOM, sbarWidth);

  trackSizer->Add(rulerPanel, 0, wxEXPAND | wxLEFT, labelWidth);
  trackSizer->Add(trackPanel, 1, wxEXPAND, 0);
  trackSizer->Add(hsbar, 0, wxEXPAND, 0);

  bottomSizer->Add(b1, 0, wxEXPAND, 0);
  bottomSizer->Add(b2, 0, wxEXPAND, 0);
  bottomSizer->Add(b3, 0, wxEXPAND | wxLEFT, 24);
  bottomSizer->Add(b4, 0, wxEXPAND, 0);
  bottomSizer->Add(status, 1, wxEXPAND | wxLEFT, 24);
  if (smallLogo)
    bottomSizer->Add(smallLogo, 0, wxLEFT | wxRIGHT, 24);

  frame->SetAutoLayout(true);
  frame->SetSizer(mainSizer);

  mainSizer->Fit(frame);
  mainSizer->SetSizeHints(frame);

  //
  //
  //

  InitialState();

  FixScrollbars();
  
  frame->SetBackgroundColour(backgroundColor);

#ifdef __X__
  // X seems to require a forced resize
  int x, y;
  frame->GetSize(&x, &y);
  frame->SetSize(-1, -1, x, y);
#endif

  // Min size, max size
  frame->SetSizeHints(250,200,20000,20000);

  frame->Show(TRUE);

  #ifdef __WXMAC__
  
  // This (hack) tells various windows not to erase the background on update events.
  //frame->m_MacEraseBack = false;
  trackPanel->m_MacEraseBack = false;
  rulerPanel->m_MacEraseBack = false;
  hsbar->m_MacEraseBack = false;
  vsbar->m_MacEraseBack = false;
  #endif

  #ifdef DEBUG_PASTE_BUG  // probably can remove this - fixed

  WaveTrack *left = 0;
  WaveTrack *right = 0;
  ImportWAV("Mussorgsky1.WAV", &left, &right,
			&((AudioDoc *)GetDocument())->dirManager);

  selected->Clear();  
  GetTracks()->Add(left);
  selected->Add(left);

  PushState();

  sel0 = 2.0;
  sel1 = 4.0;

  Cut();

  left->Debug();

  sel0 = 4.0;
  sel1 = 4.0;

  Paste();

  left->Debug();

  FixScrollbars();
  REDRAW(trackPanel);
  REDRAW(rulerPanel);

  #endif
  
  return TRUE;
}