bool CMixereView::LoadAudio(int Pos, LPCSTR Path) { // undo notification must be deferred until after audio is loaded, so that // the undo handler can save the loaded channel's info; loading audio also // modifies the current position, so we must save it before loading audio m_PrevPos = m_CurPos; // save current position for undo handler bool retc = FALSE; // assume failure int UndoCode; if (Pos < GetItemCount() && IsEmpty(Pos)) { if (retc = GetChan(Pos)->LoadAudio(Path)) UndoCode = UCODE_LOAD_AUDIO; else GetChan(Pos)->Reset(); } else { if (Insert(Pos, NULL, 1)) { if (retc = GetChan(Pos)->LoadAudio(Path)) UndoCode = UCODE_INSERT_AUDIO; else Delete(Pos, NULL, 1); } } if (retc) { // if load succeeded SetCurPos(Pos); // undo handler assumes current position NotifyUndoableEdit(UndoCode); SetCurPos(min(Pos + 1, GetItemCount() - 1)); // bump pos if possible } return(retc); }
void CMixer::SetOriginMotion(int ChanIdx, int OMType) { ASSERT(OMType >= 0 && OMType < OM_TYPES); GetChan(ChanIdx).m_OrgMotion = OMType; if (m_IsExclusive) GetChan(ChanIdx).UpdateMetronome(); }
void CMixereView::SetSolo(int State) { NotifyUndoableEdit(UCODE_SOLO); for (int i = 0; i < GetItemCount(); i++) { if (IsSelOrCurAndFull(i)) GetChan(i)->SetSolo(State < 0 ? !GetChan(i)->GetSolo() : State != 0); } }
void CMixereView::KeepSolo() { NotifyUndoableEdit(UCODE_KEEP_SOLO); for (int i = 0; i < GetItemCount(); i++) { if (!IsEmpty(i)) { GetChan(i)->SetMute(!GetChan(i)->GetSolo()); GetChan(i)->SetSolo(FALSE); } } }
void CMixereView::TimerHook() { for (int i = 0; i < GetItemCount(); i++) { if (!GetChan(i)->IsEmpty()) GetChan(i)->TimerHook(m_Tempo); } m_VolumeBar.TimerHook(); m_TempoBar.TimerHook(); if (m_MultiAutoDlg != NULL) m_MultiAutoDlg->TimerHook(m_Tempo); }
bool CMixereView::SetInfo(const CMixerInfo& Info) { CWaitCursor wc; m_MSFadeBar.SetInfo(Info.m_MSFade); // before creating channels // set the column widths int cols = Info.m_ColumnWidth.GetSize(); for (int i = 0; i < cols; i++) SetColumnWidth(i, Info.m_ColumnWidth[i]); // set the channel count int chans = Info.m_Chan.GetSize(); if (SetItemCount(chans) < chans) // if create failed, bail out return(FALSE); // set the mixer controls CStringArray ErrPath; for (i = 0; i < chans; i++) { if (!GetChan(i)->OpenItem(&Info.m_Chan[i])) // if can't load audio file AddStringUnique(ErrPath, Info.m_Chan[i].m_Path); // add its path to list } // if audio files couldn't be loaded, display error message if (ErrPath.GetSize()) MsgBoxStrList(LDS(CANT_LOAD_AUDIO), ErrPath); m_VolumeBar.SetInfo(Info.m_AutoVol); m_TempoBar.SetInfo(Info.m_AutoTempo); m_ChanDefaults = Info.m_ChanDefaults; m_ChanIDs = Info.m_ChanIDs; // redraw channels all at once, looks and sounds better for (i = 0; i < chans; i++) GetChan(i)->SetInfo(&Info.m_Chan[i]); ScrollToPosition(CPoint(0, 0)); ClearSelection(); SetCurPos(0); ClearUndoHistory(); // restore our bar state if (CMainFrame::VerifyDockState(Info.m_DockState, m_ChildFrm)) m_ChildFrm->SetDockState(Info.m_DockState); // restoring bar state enables bar tool tips; reapply our tip state for (i = 0; i < DLGBARS; i++) m_DlgBar[i]->EnableToolTips(m_HasToolTips); // attach to snapshot object and update our snapshot bar m_Snapshot = const_cast<CSnapshot *>(&Info.m_Snapshot); m_Snapshot->SetMixer(this); m_Snapshot->UpdateList(); // enable status bar panes as needed; see note in CColorStatusBar::Reset CColorStatusBar *csb = ((CMainFrame *)AfxGetMainWnd())->GetStatusBar(); if (GetMuteCount()) csb->EnablePane(CMainFrame::SBP_MUTE); if (GetSoloCount()) csb->EnablePane(CMainFrame::SBP_SOLO); return(TRUE); }
void CMixereView::OnSolo(CChannel *Chan, bool Enable) { int Prev = m_SoloCount; m_SoloCount += Enable ? 1 : -1; if (!Prev || !m_SoloCount) { for (int i = 0; i < GetItemCount(); i++) { // check for null pointer, edit could be in progress if (GetChan(i) != NULL && !GetChan(i)->IsEmpty()) { // solo channel determines whether we're soft muting GetChan(i)->ApplyMuteSolo(Chan->GetMSFadeEnable()); GetChan(i)->UpdateVolume(); } } } }
int CMixereView::FindChanByID(DWORD ChanID) const { for (int i = 0; i < GetItemCount(); i++) { if (GetChan(i)->GetID() == ChanID) return(i); } return(-1); }
void CMixereView::Go() { NotifyUndoableEdit(UCODE_GO); for (int i = 0; i < GetItemCount(); i++) { if (IsSelOrCurAndFull(i)) GetChan(i)->Go(); } }
void CMixereView::TogglePlay() { NotifyUndoableEdit(UCODE_TRANSPORT); for (int i = 0; i < GetItemCount(); i++) { if (IsSelOrCurAndFull(i)) GetChan(i)->TogglePlay(); } }
void CMixereView::SetTransport(int Transport) { NotifyUndoableEdit(UCODE_TRANSPORT); for (int i = 0; i < GetItemCount(); i++) { if (IsSelOrCurAndFull(i)) GetChan(i)->SetTransport(Transport); } }
BOOL CMixereView::EnableToolTips(BOOL bEnable) { for (int i = 0; i < GetItemCount(); i++) GetChan(i)->EnableToolTips(bEnable); for (i = 0; i < DLGBARS; i++) m_DlgBar[i]->EnableToolTips(bEnable); m_HasToolTips = bEnable; return(bEnable); }
CUndoable *CMixereView::FindUndoable(CUndoState::UNDO_KEY Key) { // if key < 0x8000, it's a normal child window ID // if key >= 0xE800, it's a control bar child window ID // otherwise, assume it's a channel index offset by 0x8000 if (Key < CChannel::UNDO_KEY_OFFSET) return(NULL); // we don't own any normal child windows if (Key >= AFX_IDW_CONTROLBAR_FIRST) return(WndToUndo(m_ChildFrm->GetControlBar(Key))); // return control bar return(GetChan(Key - CChannel::UNDO_KEY_OFFSET)); // return channel }
void CMixereView::GetInfo(CMixerInfo& Info) const { int cols = COLUMNS; Info.m_ColumnWidth.SetSize(cols); for (int i = 0; i < cols; i++) Info.m_ColumnWidth[i] = GetColumnWidth(i); int chans = GetItemCount(); Info.m_Chan.SetSize(chans); for (i = 0; i < chans; i++) GetChan(i)->GetInfo(&Info.m_Chan[i]); m_VolumeBar.GetInfo(Info.m_AutoVol); m_TempoBar.GetInfo(Info.m_AutoTempo); m_MSFadeBar.GetInfo(Info.m_MSFade); m_ChildFrm->GetDockState(Info.m_DockState); Info.m_ChanDefaults = m_ChanDefaults; Info.m_ChanIDs = m_ChanIDs; }
void CMixereView::OnPaste(void *Info, int Count, bool Local) { CChanInfo *cip = (CChanInfo *)Info; if (Local) { // if paste channels came from this instance for (int i = 0; i < Count; i++) { // for each paste channel if (cip[i].m_ID) { // if not empty for (int j = 0; j < GetItemCount(); j++) { // look up its ID if (cip[i].m_ID == GetChan(j)->GetID()) { // if duplicate ID cip[i].m_ID = CreateChanID(); // give it a new ID break; } } } } } else { // foreign paste channels get new IDs regardless for (int i = 0; i < Count; i++) { // for each paste channel if (cip[i].m_ID) // if not empty cip[i].m_ID = CreateChanID(); // give it a new ID } } }
bool CMixereView::FindNext() { if (!GetItemCount()) return(FALSE); bool Found = FALSE; int i = m_CurPos; while (!Found) { if (!m_NewFind) { // first time, don't update position if (!m_FindSearchDown) { if (--i < 0) i = GetItemCount() - 1; } else { if (++i >= GetItemCount()) i = 0; } } CString Title = GetChan(i)->GetTitle(); if (!m_FindMatchCase) // if case-insensitive match Title.MakeLower(); // make title lower case int pos = Title.Find(m_FindStr); if (pos >= 0) { // if title contains find string SetCurPos(i); Deselect(); SetSelect(i, TRUE); EnsureVisible(i); Found = TRUE; } if (!m_NewFind && i == m_CurPos) // if we're back where we started break; // we're done m_NewFind = FALSE; } if (!Found) { CString msg; msg.FormatMessage(IDS_CANT_FIND_STRING, m_FindStr); AfxMessageBox(msg); } return(Found); }
void CMixereView::UpdateVolume() { for (int i = 0; i < GetItemCount(); i++) GetChan(i)->UpdateVolume(); }
void read( TString filename, TString dataset ) { double qdep[30]; //book histos TH1F *h1 = new TH1F("nhit","Number of hits;nhits;counts",500,-0.5,499.5); TH1D *h2 = new TH1D("shower1","Shower Profile;x_{cell}-x_{beam};counts",50,-25.,25.); TH1F *h21 = new TH1F("shower2","Shower Profile;channel;counts",64,-0.5,63.5); TProfile *h22 = new TProfile("shower3","Shower Profile;X0;<Q_{dep}",30,-0.5,29.5,0.,500.,"E"); TProfile *h23 = new TProfile("shower4","Shower Profile;dx;<Q_{dep}",50,-25.,25.,0.,500.,"E"); TH1D *h3 = new TH1D("esum","Tot energy; Q_{tot} [MIP]; counts",500,0.,1000.); TH2D *h4 = new TH2D("beam","Beam profile",190,-190.,190.,190,-190.,190.); TH1D *pad[16]; for ( int k=0; k<16; k++){ TString name = dataset + TString("_pad"); name += k; TString title = name + TString(";Q [MIP];counts"); pad[k] = new TH1D(name,title,150,0.,15.); } // attache dictionaries gROOT->ProcessLine(".L ../root-macros/loadDict.C+"); //open file TFile fin( filename ); // get the tree TTree *LcalData = (TTree*)fin.Get("Lcal"); int nentr = LcalData->GetEntries(); // // set addresses double vX, vY, vZ, Emax, Etot[2]; int numPrim, numHits; std::vector<Track_t> *pTracks = 0; std::vector<Hit_t> *pHits = 0; LcalData->SetBranchAddress("vX", &vX ); LcalData->SetBranchAddress("vY", &vY ); LcalData->SetBranchAddress("vZ", &vZ ); LcalData->SetBranchAddress("numPrim", &numPrim ); LcalData->SetBranchAddress("numHits", &numHits ); LcalData->SetBranchAddress("Etot", Etot ); LcalData->SetBranchAddress("Emax", &Emax ); LcalData->SetBranchAddress("Tracks", &pTracks ); LcalData->SetBranchAddress("Hits",&pHits ); // // start loop over events for ( int ientr =0; ientr<nentr; ientr++ ){ LcalData->GetEntry(ientr); int nhits = pHits->size(); double sum = 0.; float vhits = 0.; for(int ipl=0; ipl<30; ipl++) qdep[ipl]=0.; for (int ih=0; ih<nhits; ih++){ Hit_t hit = (*pHits)[ih]; int id = hit.cellID; int ich = GetChan(id); int ipl = GetPlan(id)-1; h21->Fill( float(ich)); double qhit = hit.eHit * E2MIP; h23->Fill(hit.xHit-vX,qhit); vhits++; sum += qhit; qdep[ipl] += qhit; h2->Fill( hit.xCell-vX ); }// end loop over hits for( int ip=0; ip<30; ip++) h22->Fill(double(ip),qdep[ip]); h1->Fill(vhits); h3->Fill( sum ); h4->Fill(vX,vY); }// end loop over events TString title =TString("Plots ") + dataset; TCanvas *c1 = new TCanvas("c1",title,10,10,600,600); c1->Divide(2,2); c1->cd(1); h23->Draw(); c1->cd(2); h2->Draw(); c1->cd(3); h22->Draw(); c1->cd(4); h21->Draw(); }
void CMixereView::EndSolo() { NotifyUndoableEdit(UCODE_END_SOLO); for (int i = 0; i < GetItemCount(); i++) GetChan(i)->SetSolo(FALSE); }
void CMixereView::SetTitleFont(CFont *Font) { m_TitleFont = Font; for (int i = 0; i < GetItemCount(); i++) GetChan(i)->SetTitleFont(Font); }
void CMixereView::ApplyColorScheme() { for (int i = 0; i < GetItemCount(); i++) GetChan(i)->ApplyColorScheme(); }
void CMixereView::EditName() { GetChan(m_CurPos)->EditName(); }
void CMixereView::SetDefaults() { NotifyUndoableEdit(UCODE_SET_DEFAULTS); GetChan(m_CurPos)->GetInfo(&m_ChanDefaults); }
void CMixer::SetTempo(int ChanIdx, double Tempo) { GetChan(ChanIdx).m_Tempo = Tempo; if (m_IsExclusive) GetChan(ChanIdx).UpdateMetronome(); }
void CMixer::SetTargetOriginY(int ChanIdx, double Pos) { GetChan(ChanIdx).m_TargetOrg.y = CLAMP(Pos, 0, 1); }
void CMixereView::SaveUndoState(CUndoState& State) { if (State.GetCode() < START_UCODE) { // if base class undo code CFormListView::SaveUndoState(State); // defer to base class return; } if (State.GetCode() > END_UCODE) { // if snapshot undo code m_Snapshot->SaveUndoState(State); // defer to snapshot class return; } int Chans = GetItemCount(); UValCurPos(State) = m_CurPos; // do first so handlers can override switch (State.GetCode()) { case UCODE_TRANSPORT: { TRANSPORT_UNDO_STATE *uap; if (State.IsEmpty()) { // if first time AllocUndoArray(uap, State, max(m_Selections, 1)); SetUndoChanIdxs(uap); // set each element's channel index } else GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++, uap++) { CChannel *Chan = GetChan(uap->m_ChanIdx); uap->m_Transport = Chan->GetTransport(); uap->m_Pos = Chan->GetPosition(); } } break; case UCODE_GO: { GO_UNDO_STATE *uap; if (State.IsEmpty()) { // if first time AllocUndoArray(uap, State, max(m_Selections, 1)); SetUndoChanIdxs(uap); // set each element's channel index } else GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++, uap++) { CChannel *Chan = GetChan(uap->m_ChanIdx); uap->m_Transport = Chan->GetTransport(); uap->m_Pos = Chan->GetPosition(); for (int j = 0; j < CChanInfo::AUTOS; j++) { uap->m_Auto[j].m_Transport = Chan->GetAuto(j)->GetTransport(); uap->m_Auto[j].m_Pos = Chan->GetAuto(j)->GetNormPos(); } } } break; case UCODE_LOOP: { bool *uap; AllocUndoArray(uap, State, Chans); for (int i = 0; i < Chans; i++) uap[i] = GetChan(i)->GetLoop(); } break; case UCODE_MUTE: { bool *uap; AllocUndoArray(uap, State, Chans); for (int i = 0; i < Chans; i++) uap[i] = GetChan(i)->GetMute(); } break; case UCODE_SOLO: case UCODE_END_SOLO: { bool *uap; AllocUndoArray(uap, State, Chans); for (int i = 0; i < Chans; i++) uap[i] = GetChan(i)->GetSolo(); } break; case UCODE_KEEP_SOLO: { BYTE *uap; AllocUndoArray(uap, State, Chans); for (int i = 0; i < Chans; i++) uap[i] = GetChan(i)->GetMute() + (GetChan(i)->GetSolo() << 1); } break; case UCODE_LOAD_AUDIO: case UCODE_INSERT_AUDIO: if (!UValFlags(State)) { // override current position with pre-insert position UValCurPos(State) = m_PrevPos; CChanInfo *uap; AllocUndoArray(uap, State, 1); GetChan(m_CurPos)->GetInfo(uap); UValFlags(State) = UFLAG_DEL; // first restore will delete } else UValFlags(State) ^= UFLAG_DIR; // reverse direction break; case UCODE_SHOW_VOLUME: case UCODE_SHOW_SNAPSHOT: case UCODE_SHOW_MS_FADE: case UCODE_SHOW_TEMPO: if (!UValBarNum(State)) // if first time (zero bar number) // assume m_UndoIdx contains notifier's dialog bar index UValBarNum(State) = m_UndoIdx + 1; // zero is reserved for first time UValShowBar(State) = IsDlgBarVisible(UValBarNum(State) - 1); break; case UCODE_SET_DEFAULTS: { CChanInfo *uap; AllocUndoArray(uap, State, 1); *uap = m_ChanDefaults; } break; case UCODE_EDIT_AUTO: { CEditAutoUndoState *uap; if (State.IsEmpty()) { // if first time AllocUndoArray(uap, State, max(m_Selections, 1)); SetUndoChanIdxs(uap); // set each element's channel index // assume m_UndoIdx contains notifier's auto slider index UValAutoIdx(State) = m_UndoIdx; } else GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++, uap++) { CChannel *Chan = GetChan(uap->m_ChanIdx); CAutoSliderCtrl *Auto = Chan->GetAuto(UValAutoIdx(State)); Auto->GetInfo(*uap); uap->m_ChanTransport = Chan->GetTransport(); uap->m_ChanLoop = Chan->GetLoop(); uap->m_ChanPos = Chan->GetPosition(); } } break; default: NODEFAULTCASE; } }
void CMixereView::RestoreUndoState(const CUndoState& State) { if (State.GetCode() < START_UCODE) { // if base class undo code CFormListView::RestoreUndoState(State); // defer to base class return; } if (State.GetCode() > END_UCODE) { // if snapshot undo code m_Snapshot->RestoreUndoState(State); // defer to snapshot class return; } CWaitCursor wc; switch (State.GetCode()) { case UCODE_TRANSPORT: { TRANSPORT_UNDO_STATE *uap; GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++, uap++) { CChannel *Chan = GetChan(uap->m_ChanIdx); Chan->SetTransportAndPos(uap->m_Transport, uap->m_Pos); } } break; case UCODE_GO: { GO_UNDO_STATE *uap; GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++, uap++) { CChannel *Chan = GetChan(uap->m_ChanIdx); for (int j = 0; j < CChanInfo::AUTOS; j++) { Chan->GetAuto(j)->SetTransport(uap->m_Auto[j].m_Transport); Chan->GetAuto(j)->SetNormPos(uap->m_Auto[j].m_Pos); } Chan->SetTransportAndPos(uap->m_Transport, uap->m_Pos); } } break; case UCODE_LOOP: { bool *uap; GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++) GetChan(i)->SetLoop(uap[i]); } break; case UCODE_MUTE: { bool *uap; GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++) GetChan(i)->SetMute(uap[i]); } break; case UCODE_SOLO: case UCODE_END_SOLO: { bool *uap; GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++) GetChan(i)->SetSolo(uap[i]); } break; case UCODE_KEEP_SOLO: { BYTE *uap; GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++) { GetChan(i)->SetMute((uap[i] & 0x1) != 0); GetChan(i)->SetSolo((uap[i] & 0x2) != 0); } } break; case UCODE_LOAD_AUDIO: { CChanInfo *uap; GetUndoArray(uap, State); if ((UValFlags(State) & UFLAG_DIR) == UFLAG_INS) { GetChan(uap->m_Index)->OpenItem(uap); GetChan(uap->m_Index)->SetInfo(uap); } else GetChan(uap->m_Index)->Reset(); } break; case UCODE_INSERT_AUDIO: RestoreUndoItems(State); break; case UCODE_SHOW_VOLUME: case UCODE_SHOW_SNAPSHOT: case UCODE_SHOW_MS_FADE: case UCODE_SHOW_TEMPO: ShowDlgBar(UValBarNum(State) - 1, UValShowBar(State) != 0); break; case UCODE_SET_DEFAULTS: { CChanInfo *uap; GetUndoArray(uap, State); m_ChanDefaults = *uap; } break; case UCODE_EDIT_AUTO: { CEditAutoUndoState *uap; GetUndoArray(uap, State); for (int i = 0; i < UValItems(State); i++, uap++) { CChannel *Chan = GetChan(uap->m_ChanIdx); CAutoSliderCtrl *Auto = Chan->GetAuto(UValAutoIdx(State)); Auto->SetInfoNotify(*uap); // calls OnNewPos and OnSelection Chan->SetLoop(uap->m_ChanLoop != 0); // if channel transport changed, restore it and audio position if (uap->m_ChanTransport != Chan->GetTransport()) Chan->SetTransportAndPos(uap->m_ChanTransport, uap->m_ChanPos); } } break; default: NODEFAULTCASE; } SetCurPos(UValCurPos(State)); }
void CMixer::SetTargetOrigin(int ChanIdx, const DPoint& Origin) { GetChan(ChanIdx).m_TargetOrg.x = CLAMP(Origin.x, 0, 1); GetChan(ChanIdx).m_TargetOrg.y = CLAMP(Origin.y, 0, 1); }