#include "stdafx.h"
#include "NSFDialogs.h"

#if 0
NSFDialogManager::NSFDialogManager(NSFplug_Model *p, int mode = 0)
{
  pm = p;
  hWinamp = NULL;
  this->mode = mode;
  info = new NSFInfoDialog();
  info->SetDialogManager(this);
  config = new NSFConfigDialog("NSFPlug");
  config->SetDialogManager(this);
  memory = new NSFMemoryDialog();
  memory->SetDialogManager(this);
  easy = new NSFEasyDialog();
  easy->SetDialogManager(this);
  mixer = new NSFMixerDialog();
  mixer->m_kbflag = mode;
  mixer->SetDialogManager(this);
  panner = new NSFPanDialog();
  panner->SetDialogManager(this);
  mask = new NSFMaskDialog();
  mask->SetDialogManager(this);
  preset = new NSFPresetDialog();
  preset->SetDialogManager(this);
  
  info->Create(mode?MAKEINTRESOURCE(IDD_INFOBOX2):MAKEINTRESOURCE(info->IDD));
  if(mode==0)
  {
    track = new NSFTrackDialog();
    track->SetDialogManager(this);
    track->Create(track->IDD);
  }
  else track = NULL;
  memory->Create(memory->IDD);
  memory->SetWindowPos(NULL,0,0,523,328,SWP_NOZORDER|SWP_NOMOVE);
  mixer->Create(mixer->IDD);
  panner->Create(panner->IDD);
  easy->Create(easy->IDD);
  mask->Create(mask->IDD);
  CString path;
  preset->Create(preset->IDD); config->Create(NULL,WS_SYSMENU|WS_POPUP|WS_CAPTION|DS_MODALFRAME|DS_CONTEXTHELP);

  wa2mod = NULL;
  InitializeCriticalSection(&cso);
}
#endif
NSFDialogManager::NSFDialogManager(NSFplug_Model *p, int mode)
{//by Kobarin
 //mode の意味を変更
 //mode == 0: 曲データごとの情報に関するダイアログ
 //mode == 1: 設定に関するダイアログ(個別の曲データに依らないもの)
 //必要な分だけ作成

  pm = p;
  this->mode = mode;
  info = NULL;
  config = NULL;
  memory = NULL;
  easy = NULL;
  mixer = NULL;
  panner = NULL;
  mask = NULL;
  track = NULL;
  preset = NULL;
  hWinamp = NULL;
  wa2mod = NULL;
  InitializeCriticalSection(&cso);

  if(mode == 0){//曲データごと
    info = new NSFInfoDialog();
    info->SetDialogManager(this);
    memory = new NSFMemoryDialog();
    memory->SetDialogManager(this);
    info->Create(mode?MAKEINTRESOURCE(IDD_INFOBOX2):MAKEINTRESOURCE(info->IDD));
    track = new NSFTrackDialog();
    track->SetDialogManager(this);
    track->Create(track->IDD);
    memory->Create(memory->IDD);
    memory->SetWindowPos(NULL,0,0,523,328,SWP_NOZORDER|SWP_NOMOVE);

  }
  else{//設定のみ
    config = new NSFConfigDialog("NSFPlug");
    config->SetDialogManager(this);
    //easy = new NSFEasyDialog();
    //easy->SetDialogManager(this);
    mixer = new NSFMixerDialog();
    mixer->m_kbflag = mode;
    mixer->SetDialogManager(this);
    panner = new NSFPanDialog();
    panner->SetDialogManager(this);
    mask = new NSFMaskDialog();
    mask->SetDialogManager(this);
    //preset = new NSFPresetDialog();
    //preset->SetDialogManager(this);
    mixer->Create(mixer->IDD);
    panner->Create(panner->IDD);
    //easy->Create(easy->IDD);
    mask->Create(mask->IDD);
    config->Create(NULL,WS_SYSMENU|WS_POPUP|WS_CAPTION|DS_MODALFRAME|DS_CONTEXTHELP);
  }
}

void NSFDialogManager::SetPlayerWindow(HWND hwnd)
{ 
  hWinamp = hwnd ;
}

void NSFDialogManager::UpdateNSFPlayerConfig(bool b)
{
  if(info)info->UpdateNSFPlayerConfig(b);
  if(easy)easy->UpdateNSFPlayerConfig(b);
  if(memory)memory->UpdateNSFPlayerConfig(b);
  if(mixer)mixer->UpdateNSFPlayerConfig(b);
  if(panner)panner->UpdateNSFPlayerConfig(b);
  if(config)config->UpdateNSFPlayerConfig(b);
  if(mask)mask->UpdateNSFPlayerConfig(b);
  if(preset)preset->UpdateNSFPlayerConfig(b);
}

NSFDialogManager::~NSFDialogManager()
{
  if(info)info->DestroyWindow();
  delete info;
  if(memory)memory->DestroyWindow();
  delete memory;
  if(config)config->DestroyWindow();
  delete config;
  if(easy)easy->DestroyWindow();
  delete easy;
  if(mixer)mixer->DestroyWindow();
  delete mixer;
  if(panner)panner->DestroyWindow();
  delete panner;
  if(mask)mask->DestroyWindow();
  delete mask;
  if(preset)preset->DestroyWindow();
  delete preset;

  //if(mode==0)
  //{
  if(track)  track->DestroyWindow();
    delete track;
  //}
}

// 演奏情報へのアクセスを許可
void NSFDialogManager::StartUpdate()
{ 
  EnterCriticalSection(&cso);
  if(mode==0)
  {
    track->InitList();
    track->m_active = true;
  }
  LeaveCriticalSection(&cso); 
}

// 演奏情報へのアクセスを禁止
void NSFDialogManager::StopUpdate()
{ 
  EnterCriticalSection(&cso); 
  if(mode==0)
  {
    track->m_active = false; 
    track->InitList();
  }
  LeaveCriticalSection(&cso); 
}

#define OPENDIALOG(x,y) case x: y->Open(); break;

void NSFDialogManager::OpenDialog(int id)
{
  switch(id)
  {
    OPENDIALOG(DLG_CONFIG,config);
    OPENDIALOG(DLG_INFO,info);
    OPENDIALOG(DLG_EASY,easy);
    OPENDIALOG(DLG_MASK,mask);
    OPENDIALOG(DLG_MEMORY,memory);
    OPENDIALOG(DLG_TRACK,track);
    OPENDIALOG(DLG_MIXER,mixer);
    OPENDIALOG(DLG_PRESET,preset);
  default:
    break;
  }
}

