void CManipulator::CreateManipulator(dWorldID world,dSpaceID space) { if(baseManipulator.paraBase.typeJoint=CYLINDER) baseManipulator.geomBase=dCreateCylinder(space,baseManipulator.paraBase.paraManipulatorCylinder.r,baseManipulator.paraBase.paraManipulatorCylinder.length); else baseManipulator.geomBase=dCreateBox(space,baseManipulator.paraBase.paraManipulatorBox.x,baseManipulator.paraBase.paraManipulatorBox.y,baseManipulator.paraBase.paraManipulatorBox.z); if(baseManipulator.paraBase.typeJoint=CYLINDER) dGeomSetPosition(baseManipulator.geomBase,0,0,baseManipulator.paraBase.paraManipulatorCylinder.length/2.0); else dGeomSetPosition(baseManipulator.geomBase,0,0,baseManipulator.paraBase.paraManipulatorBox.z/2.0); int i; SPoint tempptAnchor; dBodyID tempbodyLast=NULL; tempptAnchor.x=tempptAnchor.y=0; if(baseManipulator.paraBase.typeJoint=CYLINDER) tempptAnchor.z=baseManipulator.paraBase.paraManipulatorCylinder.length; else tempptAnchor.z=baseManipulator.paraBase.paraManipulatorBox.z; //创建第一轴 CreateJoint(tempptAnchor,jointManipulator[0].paraJoint,BORDER,tempbodyLast, jointManipulator[0].bodyJoint,jointManipulator[0].geomJoint,jointManipulator[0].joint,world,space); SetStop(jointManipulator[0].joint,stopparaJoint[0]); //创建第二轴 if(jointManipulator[0].paraJoint.typeJoint==CYLINDER) { tempptAnchor.x=tempptAnchor.x; tempptAnchor.z=tempptAnchor.z; tempptAnchor.y=tempptAnchor.y+jointManipulator[0].paraJoint.paraManipulatorCylinder.r; } else { tempptAnchor.x=tempptAnchor.x; tempptAnchor.z=tempptAnchor.z; tempptAnchor.y=tempptAnchor.y+jointManipulator[0].paraJoint.paraManipulatorBox.y/2; } CreateJoint(tempptAnchor,jointManipulator[1].paraJoint,BORDER,tempbodyLast, jointManipulator[1].bodyJoint,jointManipulator[1].geomJoint,jointManipulator[1].joint,world,space); SetStop(jointManipulator[1].joint,stopparaJoint[1]); //创建其他轴 for( i=2;i<NUMOFLEGJOINTS;i++) { CreateJoint(tempptAnchor, jointManipulator[i].paraJoint,BORDER, tempbodyLast, jointManipulator[i].bodyJoint, jointManipulator[i].geomJoint, jointManipulator[i].joint, world,space); SetStop(jointManipulator[i].joint,stopparaJoint[i]); } return; }
void CRole::SetDst(Pos pos) { m_bBeginFindPath = false; m_fdst = m_dst = pos; ComputeDir(); int x = (int)(m_fdst.x/m_pMap->m_tileWidth); int y = (int)(m_fdst.y/m_pMap->m_tileHeight); if(!m_pMap->Passable(x, y))//如果目标不可到达 { int bestx;int besty; m_bestPosFinder->FindBestPos(x, y, &bestx, &besty, m_pMap->m_map);//寻找最近可走点 m_fdst.x = (float)bestx*m_pMap->m_tileWidth; m_fdst.y = (float)besty*m_pMap->m_tileHeight; //printf("%d %d\n", bestx, besty); } ClearPath(); //int t=timeGetTime(); //计算寻路时间 FindPath(&m_pos, &m_fdst); //printf("寻路消耗时间: %d\n",timeGetTime()-t); // if(GetNextPos(&m_dst, (float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2)) ComputeDir(); else SetStop(); }
void ControlToolBar::StopPlaying(bool stopStream /* = true*/) { mStop->PushDown(); SetStop(false); if(stopStream) gAudioIO->StopStream(); SetPlay(false); SetRecord(false); #ifdef AUTOMATED_INPUT_LEVEL_ADJUSTMENT gAudioIO->AILADisable(); #endif mPause->PopUp(); mPaused=false; //Make sure you tell gAudioIO to unpause gAudioIO->SetPaused(mPaused); ClearCutPreviewTracks(); mBusyProject = NULL; // So that we continue monitoring after playing or recording. // also clean the MeterQueues AudacityProject *project = GetActiveProject(); if( project ) { project->MayStartMonitoring(); project->GetMeterToolBar()->Clear(); } }
//exists gracefully void CApp::HandlerSIGTERM(int) { LOG("Signal to stop set: max %d sec", m_nStopTimeout ); SetStop(); int timeLeft = alarm(0); alarm( _Min(timeLeft,m_nStopTimeout-1) ); AlarmEx( SIGKILL, m_nStopTimeout ); //set watchdog }
void APalette::OnKeyEvent(wxKeyEvent & event) { if (event.ControlDown()) { event.Skip(); return; } if (event.KeyCode() == WXK_SPACE) { if (gAudioIO->IsBusy()) { SetPlay(false); SetStop(true); OnStop(); } else { OnPlay(); SetPlay(true); SetStop(false); } } }
void ControlToolBar::StopPlaying(bool stopStream /* = true*/) { StopScrolling(); AudacityProject *project = GetActiveProject(); if(project) { // Let scrubbing code do some appearance change project->GetScrubber().StopScrubbing(); } if (!CanStopAudioStream()) return; mStop->PushDown(); SetStop(false); if(stopStream) gAudioIO->StopStream(); SetPlay(false); SetRecord(false); #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT gAudioIO->AILADisable(); #endif mPause->PopUp(); mPaused=false; //Make sure you tell gAudioIO to unpause gAudioIO->SetPaused(mPaused); ClearCutPreviewTracks(); mBusyProject = NULL; // So that we continue monitoring after playing or recording. // also clean the MeterQueues if( project ) { project->MayStartMonitoring(); Meter *meter = project->GetPlaybackMeter(); if( meter ) { meter->Clear(); } meter = project->GetCaptureMeter(); if( meter ) { meter->Clear(); } } const auto toolbar = project->GetToolManager()->GetToolBar(ScrubbingBarID); toolbar->EnableDisableButtons(); }
void ControlToolBar::OnKeyEvent(wxKeyEvent & event) { if (event.ControlDown() || event.AltDown()) { event.Skip(); return; } if (event.GetKeyCode() == WXK_SPACE) { if (gAudioIO->IsStreamActive(GetActiveProject()->GetAudioIOToken())) { SetPlay(false); SetStop(true); StopPlaying(); } else if (!gAudioIO->IsBusy()) { //SetPlay(true);// Not needed as done in PlayPlayRegion SetStop(false); PlayCurrentRegion(); } return; } event.Skip(); }
void ControlToolBar::OnKeyEvent(wxKeyEvent & event) { if (event.ControlDown() || event.AltDown()) { event.Skip(); return; } // Does not appear to be needed on Linux. Perhaps on some other platform? // If so, "!CanStopAudioStream()" should probably apply. if (event.GetKeyCode() == WXK_SPACE) { if (gAudioIO->IsStreamActive(GetActiveProject()->GetAudioIOToken())) { SetPlay(false); SetStop(true); StopPlaying(); } else if (!gAudioIO->IsBusy()) { //SetPlay(true);// Not needed as done in PlayPlayRegion SetStop(false); PlayCurrentRegion(); } return; } event.Skip(); }
void APalette::OnRecord() { if (gAudioIO->IsBusy()) return; AudacityProject *p = GetActiveProject(); if (p) { TrackList *t = p->GetTracks(); bool success = gAudioIO->StartRecord(p, t); if (!success) { SetPlay(false); SetStop(false); SetRecord(false); } } }
void APalette::OnRecord() { if (gAudioIO->IsBusy()) return; AudacityProject *p = GetActiveProject(); if (p) { TrackList *t = p->GetTracks(); double t0 = p->GetSel0(); double t1 = p->GetSel1(); if (t1 == t0) t1 = 1000000000.0; // record for a long, long time (tens of years) bool success = gAudioIO->StartRecord(p, t, t0, t1); if (!success) { SetPlay(false); SetStop(false); SetRecord(false); } } }
void ControlToolBar::StopPlaying() { mStop->PushDown(); SetStop(false); gAudioIO->StopStream(); SetPlay(false); SetRecord(false); #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) this->SetBackgroundColour(*wxBLUE); // blue for Ready this->Refresh(); #endif mPause->PopUp(); mPaused=false; //Make sure you tell gAudioIO to unpause gAudioIO->SetPaused(mPaused); mBusyProject = NULL; }
void APalette::OnPlay() { if (gAudioIO->IsBusy()) return; AudacityProject *p = GetActiveProject(); if (p) { TrackList *t = p->GetTracks(); double t0 = p->GetSel0(); double t1 = p->GetSel1(); if (t1 == t0) t1 = t->GetMaxLen(); bool success = gAudioIO->StartPlay(p, t, t0, t1); if (!success) { SetPlay(false); SetStop(false); SetRecord(false); } } }
void ControlToolBar::StopPlaying() { mStop->PushDown(); SetStop(false); gAudioIO->StopStream(); SetPlay(false); SetRecord(false); mPause->PopUp(); mPaused=false; //Make sure you tell gAudioIO to unpause gAudioIO->SetPaused(mPaused); ClearCutPreviewTracks(); mBusyProject = NULL; // So that we continue monitoring after playing or recording. AudacityProject *project = GetActiveProject(); if( project ) project->MayStartMonitoring(); }
void ControlToolBar::OnRecord(wxCommandEvent &evt) { if (gAudioIO->IsBusy()) { mRecord->PopUp(); return; } AudacityProject *p = GetActiveProject(); if( evt.GetInt() == 1 ) // used when called by keyboard shortcut. Default (0) ignored. mRecord->SetShift(true); if( evt.GetInt() == 2 ) mRecord->SetShift(false); SetRecord(true, mRecord->WasShiftDown()); if (p) { TrackList *t = p->GetTracks(); TrackListIterator it(t); if(it.First() == NULL) mRecord->SetShift(false); double t0 = p->GetSel0(); double t1 = p->GetSel1(); if (t1 == t0) t1 = 1000000000.0; // record for a long, long time (tens of years) /* TODO: set up stereo tracks if that is how the user has set up * their preferences, and choose sample format based on prefs */ WaveTrackArray newRecordingTracks, playbackTracks; #ifdef EXPERIMENTAL_MIDI_OUT NoteTrackArray midiTracks; #endif bool duplex; gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex, true); if(duplex){ playbackTracks = t->GetWaveTrackArray(false); #ifdef EXPERIMENTAL_MIDI_OUT midiTracks = t->GetNoteTrackArray(false); #endif } else { playbackTracks = WaveTrackArray(); #ifdef EXPERIMENTAL_MIDI_OUT midiTracks = NoteTrackArray(); #endif } // If SHIFT key was down, the user wants append to tracks int recordingChannels = 0; bool shifted = mRecord->WasShiftDown(); if (shifted) { bool sel = false; double allt0 = t0; // Find the maximum end time of selected and all wave tracks // Find whether any tracks were selected. (If any are selected, // record only into them; else if tracks exist, record into all.) for (Track *tt = it.First(); tt; tt = it.Next()) { if (tt->GetKind() == Track::Wave) { WaveTrack *wt = static_cast<WaveTrack *>(tt); if (wt->GetEndTime() > allt0) { allt0 = wt->GetEndTime(); } if (tt->GetSelected()) { sel = true; if (wt->GetEndTime() > t0) { t0 = wt->GetEndTime(); } } } } // Use end time of all wave tracks if none selected if (!sel) { t0 = allt0; } // Pad selected/all wave tracks to make them all the same length // Remove recording tracks from the list of tracks for duplex ("overdub") // playback. for (Track *tt = it.First(); tt; tt = it.Next()) { if (tt->GetKind() == Track::Wave && (tt->GetSelected() || !sel)) { WaveTrack *wt = static_cast<WaveTrack *>(tt); if (duplex) playbackTracks.Remove(wt); t1 = wt->GetEndTime(); if (t1 < t0) { WaveTrack *newTrack = p->GetTrackFactory()->NewWaveTrack(); newTrack->InsertSilence(0.0, t0 - t1); newTrack->Flush(); wt->Clear(t1, t0); bool bResult = wt->Paste(t1, newTrack); wxASSERT(bResult); // TO DO: Actually handle this. delete newTrack; } newRecordingTracks.Add(wt); } } t1 = 1000000000.0; // record for a long, long time (tens of years) } else { recordingChannels = gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2); for (int c = 0; c < recordingChannels; c++) { WaveTrack *newTrack = p->GetTrackFactory()->NewWaveTrack(); newTrack->SetOffset(t0); if (recordingChannels > 2) newTrack->SetMinimized(true); if (recordingChannels == 2) { if (c == 0) { newTrack->SetChannel(Track::LeftChannel); newTrack->SetLinked(true); } else { newTrack->SetChannel(Track::RightChannel); } } else { newTrack->SetChannel( Track::MonoChannel ); } newRecordingTracks.Add(newTrack); } // msmeyer: StartStream calls a callback which triggers auto-save, so // we add the tracks where recording is done into now. We remove them // later if starting the stream fails for (unsigned int i = 0; i < newRecordingTracks.GetCount(); i++) t->Add(newRecordingTracks[i]); } //Automated Input Level Adjustment Initialization #ifdef AUTOMATED_INPUT_LEVEL_ADJUSTMENT gAudioIO->AILAInitialize(); #endif int token = gAudioIO->StartStream(playbackTracks, newRecordingTracks, #ifdef EXPERIMENTAL_MIDI_OUT midiTracks, #endif t->GetTimeTrack(), p->GetRate(), t0, t1, p); bool success = (token != 0); if (success) { p->SetAudioIOToken(token); mBusyProject = p; } else { // msmeyer: Delete recently added tracks if opening stream fails if (!shifted) { for (unsigned int i = 0; i < newRecordingTracks.GetCount(); i++) { t->Remove(newRecordingTracks[i]); delete newRecordingTracks[i]; } } // msmeyer: Show error message if stream could not be opened wxMessageBox(_("Error while opening sound device. Please check the recording device settings and the project sample rate."), _("Error"), wxOK | wxICON_EXCLAMATION, this); SetPlay(false); SetStop(false); SetRecord(false); } } }
void ControlToolBar::PlayPlayRegion(double t0, double t1, bool looped /* = false */, bool cutpreview /* = false */, TimeTrack *timetrack /* = NULL */, const double *pStartTime /* = NULL */) { SetPlay(true, looped, cutpreview); if (gAudioIO->IsBusy()) { SetPlay(false); return; } if (cutpreview && t0==t1) { SetPlay(false); return; /* msmeyer: makes no sense */ } AudacityProject *p = GetActiveProject(); if (!p) { SetPlay(false); return; // Should never happen, but... } TrackList *t = p->GetTracks(); if (!t) { mPlay->PopUp(); return; // Should never happen, but... } bool hasaudio = false; TrackListIterator iter(t); for (Track *trk = iter.First(); trk; trk = iter.Next()) { if (trk->GetKind() == Track::Wave #ifdef EXPERIMENTAL_MIDI_OUT || trk->GetKind() == Track::Note #endif ) { hasaudio = true; break; } } if (!hasaudio) { SetPlay(false); return; // No need to continue without audio tracks } double maxofmins,minofmaxs; #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR) double init_seek = 0.0; #endif // JS: clarified how the final play region is computed; if (t1 == t0) { // msmeyer: When playing looped, we play the whole file, if // no range is selected. Otherwise, we play from t0 to end if (looped) { // msmeyer: always play from start t0 = t->GetStartTime(); } else { // move t0 to valid range if (t0 < 0) { t0 = t->GetStartTime(); } else if (t0 > t->GetEndTime()) { t0 = t->GetEndTime(); } #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR) else { init_seek = t0; //AC: init_seek is where playback will 'start' t0 = t->GetStartTime(); } #endif } // always play to end t1 = t->GetEndTime(); } else { // always t0 < t1 right? // the set intersection between the play region and the // valid range maximum of lower bounds if (t0 < t->GetStartTime()) maxofmins = t->GetStartTime(); else maxofmins = t0; // minimum of upper bounds if (t1 > t->GetEndTime()) minofmaxs = t->GetEndTime(); else minofmaxs = t1; // we test if the intersection has no volume if (minofmaxs <= maxofmins) { // no volume; play nothing return; } else { t0 = maxofmins; t1 = minofmaxs; } } // Can't play before 0...either shifted or latencey corrected tracks if (t0 < 0.0) { t0 = 0.0; } bool success = false; if (t1 > t0) { int token; if (cutpreview) { double beforeLen, afterLen; gPrefs->Read(wxT("/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0); gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0); double tcp0 = t0-beforeLen; double tcp1 = (t1+afterLen) - (t1-t0); SetupCutPreviewTracks(tcp0, t0, t1, tcp1); if (mCutPreviewTracks) { token = gAudioIO->StartStream( mCutPreviewTracks->GetWaveTrackArray(false), WaveTrackArray(), #ifdef EXPERIMENTAL_MIDI_OUT NoteTrackArray(), #endif timetrack, p->GetRate(), tcp0, tcp1, p, false, t0, t1-t0, pStartTime); } else { // Cannot create cut preview tracks, clean up and exit SetPlay(false); SetStop(false); SetRecord(false); return; } } else { if (!timetrack) { timetrack = t->GetTimeTrack(); } token = gAudioIO->StartStream(t->GetWaveTrackArray(false), WaveTrackArray(), #ifdef EXPERIMENTAL_MIDI_OUT t->GetNoteTrackArray(false), #endif timetrack, p->GetRate(), t0, t1, p, looped, 0, 0, pStartTime); } if (token != 0) { success = true; p->SetAudioIOToken(token); mBusyProject = p; #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR) //AC: If init_seek was set, now's the time to make it happen. gAudioIO->SeekStream(init_seek); #endif } else { // msmeyer: Show error message if stream could not be opened wxMessageBox( #if wxCHECK_VERSION(3,0,0) _("Error while opening sound device. " "Please check the playback device settings and the project sample rate."), #else _("Error while opening sound device. " wxT("Please check the playback device settings and the project sample rate.")), #endif _("Error"), wxOK | wxICON_EXCLAMATION, this); } } if (!success) { SetPlay(false); SetStop(false); SetRecord(false); } }
void ControlToolBar::OnRecord(wxCommandEvent &evt) { if (gAudioIO->IsBusy()) { #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) if (mIsLocked) // Stop only if in locked mode. { this->StopPlaying(); // Stop recording. mRecord->PopUp(); } else { //v evt.GetClassInfo(); } #else mRecord->PopUp(); #endif return; } mPlay->Disable(); #if (AUDACITY_BRANDING == BRAND_THINKLABS) mLoopPlay->Disable(); #endif #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) mStop->SetEnabled(mIsLocked); #else mStop->Enable(); #endif mRewind->Disable(); mFF->Disable(); #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) mPause->SetEnabled(mIsLocked); this->EnablePauseCommand(mIsLocked); this->SetRecord(mIsLocked); // If locked, push Record down, else up. #else mPause->Enable(); mRecord->PushDown(); #endif AudacityProject *p = GetActiveProject(); if (p) { TrackList *t = p->GetTracks(); // Don't do this for Audiotouch. Not necessary. The performance hit is in the track being recorded, below. #if (AUDACITY_BRANDING == BRAND_THINKLABS) // For versions that default to dual wave/spectrum display, // switch all tracks to WaveformDisplay on Record, for performance. TrackListIterator iter(t); for (Track* pTrack = iter.First(); pTrack; pTrack = iter.Next()) if (pTrack->GetKind() == Track::Wave) ((WaveTrack*)pTrack)->SetDisplay(WaveTrack::WaveformDisplay); #endif double t0 = p->GetSel0(); double t1 = p->GetSel1(); if (t1 == t0) t1 = 1000000000.0; // record for a long, long time (tens of years) #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) if (p->m_bWantAppendRecording) { t0 = t->GetEndTime(); t1 = 1000000000.0; // record for a long, long time (tens of years) } gAudioIO->SetWantLatencyCorrection(!p->m_bWantAppendRecording); #endif /* TODO: set up stereo tracks if that is how the user has set up * their preferences, and choose sample format based on prefs */ WaveTrackArray newRecordingTracks, playbackTracks; bool duplex; gPrefs->Read("/AudioIO/Duplex", &duplex, true); int recordingChannels = gPrefs->Read("/AudioIO/RecordChannels", 1); if( duplex ) playbackTracks = t->GetWaveTrackArray(false); else playbackTracks = WaveTrackArray(); for( int c = 0; c < recordingChannels; c++ ) { WaveTrack *newTrack = p->GetTrackFactory()->NewWaveTrack(); newTrack->SetOffset(t0); newTrack->SetRate(p->GetRate()); //v for performance newTrack->SetDisplay(WaveTrack::WaveformAndSpectrumDisplay); newTrack->SetDisplay(WaveTrack::WaveformDisplay); if( recordingChannels == 2 ) { if( c == 0 ) { newTrack->SetChannel(Track::LeftChannel); newTrack->SetLinked(true); } else newTrack->SetChannel(Track::RightChannel); } else { newTrack->SetChannel( Track::MonoChannel ); } newRecordingTracks.Add(newTrack); } int token = gAudioIO->StartStream(playbackTracks, newRecordingTracks, t->GetTimeTrack(), p->GetRate(), t0, t1); bool success = (token != 0); for( unsigned int i = 0; i < newRecordingTracks.GetCount(); i++ ) if (success) t->Add(newRecordingTracks[i]); else delete newRecordingTracks[i]; if (success) { p->SetAudioIOToken(token); mBusyProject = p; SetVUMeters(p); #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) this->SetBackgroundColour(*wxRED); // red for Recording this->Refresh(); #endif } else { // msmeyer: Show error message if stream could not be opened wxMessageBox(_("Error while opening sound device. Please check the input " "device settings and the project sample rate."), _("Error"), wxOK | wxICON_EXCLAMATION, this); SetPlay(false); #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) mStop->Enable(); // In case it was disabled above, based on mIsLocked. #endif SetStop(false); SetRecord(false); } #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) p->OnZoomFitV(); #endif } }
void ControlToolBar::OnKeyEvent(wxKeyEvent & event) { if (event.ControlDown() || event.AltDown()) { event.Skip(); return; } // Play/Stop #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) if (event.GetKeyCode() == WXK_RETURN) { #else if (event.KeyCode() == WXK_SPACE) { #endif if (gAudioIO->IsStreamActive(GetActiveProject()->GetAudioIOToken())) { SetPlay(false); SetStop(true); StopPlaying(); } else if (!gAudioIO->IsBusy()) { SetPlay(true); SetStop(false); PlayCurrentRegion(); } return; } event.Skip(); } //void ControlToolBar::OnKeyUp(wxKeyEvent & event) //{ // #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) // if ((event.KeyCode() == WXK_SPACE) && // Record // !mIsLocked) // { // StopPlaying(); // // SetPlay(false); // SetRecord(false); // SetStop(true); // mStop->Disable(); // } // #endif // event.Skip(); //} // void ControlToolBar::UpdatePrefs() { gPrefs->Read("/GUI/AlwaysEnablePlay", &mAlwaysEnablePlay, false); #if 0 gPrefs->Read("/GUI/AlwaysEnablePause", &mAlwaysEnablePause, false); if(mAlwaysEnablePause) { mPause->Enable(); this->EnablePauseCommand(true); } else if(!mAlwaysEnablePause && !gAudioIO->IsBusy()) { mPause->PopUp(); mPause->Disable(); this->EnablePauseCommand(false); mPaused = false; gAudioIO->SetPaused(false); } gAudioIO->SetAlwaysEnablePause(mAlwaysEnablePause); #endif }
void ControlToolBar::OnRecord(wxCommandEvent &evt) { auto doubleClicked = mRecord->IsDoubleClicked(); mRecord->ClearDoubleClicked(); if (doubleClicked) { // Display a fixed recording head while scrolling the waves continuously. // If you overdub, you may want to anticipate some context in existing tracks, // so center the head. If not, put it rightmost to display as much wave as we can. const auto project = GetActiveProject(); bool duplex; gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex, true); if (duplex) { // See if there is really anything being overdubbed if (gAudioIO->GetNumPlaybackChannels() == 0) // No. duplex = false; } using Mode = AudacityProject::PlaybackScroller::Mode; project->GetPlaybackScroller().Activate(duplex ? Mode::Centered : Mode::Right); return; } if (gAudioIO->IsBusy()) { if (!CanStopAudioStream() || 0 == gAudioIO->GetNumCaptureChannels()) mRecord->PopUp(); else mRecord->PushDown(); return; } AudacityProject *p = GetActiveProject(); if( evt.GetInt() == 1 ) // used when called by keyboard shortcut. Default (0) ignored. mRecord->SetShift(true); if( evt.GetInt() == 2 ) mRecord->SetShift(false); SetRecord(true, mRecord->WasShiftDown()); if (p) { TrackList *trackList = p->GetTracks(); TrackListIterator it(trackList); if(it.First() == NULL) mRecord->SetShift(false); double t0 = p->GetSel0(); double t1 = p->GetSel1(); if (t1 == t0) t1 = 1000000000.0; // record for a long, long time (tens of years) /* TODO: set up stereo tracks if that is how the user has set up * their preferences, and choose sample format based on prefs */ WaveTrackArray newRecordingTracks, playbackTracks; #ifdef EXPERIMENTAL_MIDI_OUT NoteTrackArray midiTracks; #endif bool duplex; gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex, true); if(duplex){ playbackTracks = trackList->GetWaveTrackArray(false); #ifdef EXPERIMENTAL_MIDI_OUT midiTracks = trackList->GetNoteTrackArray(false); #endif } else { playbackTracks = WaveTrackArray(); #ifdef EXPERIMENTAL_MIDI_OUT midiTracks = NoteTrackArray(); #endif } // If SHIFT key was down, the user wants append to tracks int recordingChannels = 0; TrackList tracksCopy{}; bool tracksCopied = false; bool shifted = mRecord->WasShiftDown(); if (shifted) { bool sel = false; double allt0 = t0; // Find the maximum end time of selected and all wave tracks // Find whether any tracks were selected. (If any are selected, // record only into them; else if tracks exist, record into all.) for (Track *tt = it.First(); tt; tt = it.Next()) { if (tt->GetKind() == Track::Wave) { WaveTrack *wt = static_cast<WaveTrack *>(tt); if (wt->GetEndTime() > allt0) { allt0 = wt->GetEndTime(); } if (tt->GetSelected()) { sel = true; if (wt->GetEndTime() > t0) { t0 = wt->GetEndTime(); } } } } // Use end time of all wave tracks if none selected if (!sel) { t0 = allt0; } // Pad selected/all wave tracks to make them all the same length // Remove recording tracks from the list of tracks for duplex ("overdub") // playback. for (Track *tt = it.First(); tt; tt = it.Next()) { if (tt->GetKind() == Track::Wave && (tt->GetSelected() || !sel)) { WaveTrack *wt = static_cast<WaveTrack *>(tt); if (duplex) { auto end = playbackTracks.end(); auto it = std::find(playbackTracks.begin(), end, wt); if (it != end) playbackTracks.erase(it); } t1 = wt->GetEndTime(); if (t1 < t0) { if (!tracksCopied) { tracksCopied = true; tracksCopy = *trackList; } auto newTrack = p->GetTrackFactory()->NewWaveTrack(); newTrack->InsertSilence(0.0, t0 - t1); newTrack->Flush(); wt->Clear(t1, t0); bool bResult = wt->Paste(t1, newTrack.get()); wxASSERT(bResult); // TO DO: Actually handle this. wxUnusedVar(bResult); } newRecordingTracks.push_back(wt); } } t1 = 1000000000.0; // record for a long, long time (tens of years) } else { bool recordingNameCustom, useTrackNumber, useDateStamp, useTimeStamp; wxString defaultTrackName, defaultRecordingTrackName; int numTracks = 0; for (Track *tt = it.First(); tt; tt = it.Next()) { if (tt->GetKind() == Track::Wave && !tt->GetLinked()) numTracks++; } numTracks++; recordingChannels = gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2); gPrefs->Read(wxT("/GUI/TrackNames/RecordingNameCustom"), &recordingNameCustom, false); gPrefs->Read(wxT("/GUI/TrackNames/TrackNumber"), &useTrackNumber, false); gPrefs->Read(wxT("/GUI/TrackNames/DateStamp"), &useDateStamp, false); gPrefs->Read(wxT("/GUI/TrackNames/TimeStamp"), &useTimeStamp, false); /* i18n-hint: The default name for an audio track. */ gPrefs->Read(wxT("/GUI/TrackNames/DefaultTrackName"),&defaultTrackName, _("Audio Track")); gPrefs->Read(wxT("/GUI/TrackNames/RecodingTrackName"), &defaultRecordingTrackName, defaultTrackName); wxString baseTrackName = recordingNameCustom? defaultRecordingTrackName : defaultTrackName; for (int c = 0; c < recordingChannels; c++) { auto newTrack = p->GetTrackFactory()->NewWaveTrack(); newTrack->SetOffset(t0); wxString nameSuffix = wxString(wxT("")); if (useTrackNumber) { nameSuffix += wxString::Format(wxT("%d"), numTracks + c); } if (useDateStamp) { if (!nameSuffix.IsEmpty()) { nameSuffix += wxT("_"); } nameSuffix += wxDateTime::Now().FormatISODate(); } if (useTimeStamp) { if (!nameSuffix.IsEmpty()) { nameSuffix += wxT("_"); } nameSuffix += wxDateTime::Now().FormatISOTime(); } // ISO standard would be nice, but ":" is unsafe for file name. nameSuffix.Replace(wxT(":"), wxT("-")); if (baseTrackName.IsEmpty()) { newTrack->SetName(nameSuffix); } else if (nameSuffix.IsEmpty()) { newTrack->SetName(baseTrackName); } else { newTrack->SetName(baseTrackName + wxT("_") + nameSuffix); } if (recordingChannels > 2) newTrack->SetMinimized(true); if (recordingChannels == 2) { if (c == 0) { newTrack->SetChannel(Track::LeftChannel); newTrack->SetLinked(true); } else { newTrack->SetChannel(Track::RightChannel); } } else { newTrack->SetChannel( Track::MonoChannel ); } // Let the list hold the track, and keep a pointer to it newRecordingTracks.push_back( static_cast<WaveTrack*>( trackList->Add( std::move(newTrack)))); } } //Automated Input Level Adjustment Initialization #ifdef EXPERIMENTAL_AUTOMATED_INPUT_LEVEL_ADJUSTMENT gAudioIO->AILAInitialize(); #endif AudioIOStartStreamOptions options(p->GetDefaultPlayOptions()); int token = gAudioIO->StartStream(playbackTracks, newRecordingTracks, #ifdef EXPERIMENTAL_MIDI_OUT midiTracks, #endif t0, t1, options); bool success = (token != 0); if (success) { p->SetAudioIOToken(token); mBusyProject = p; } else { if (shifted) { // Restore the tracks to remove any inserted silence if (tracksCopied) *trackList = std::move(tracksCopy); } else { // msmeyer: Delete recently added tracks if opening stream fails for (unsigned int i = 0; i < newRecordingTracks.size(); i++) { trackList->Remove(newRecordingTracks[i]); } } // msmeyer: Show error message if stream could not be opened wxMessageBox(_("Error while opening sound device. Please check the recording device settings and the project sample rate."), _("Error"), wxOK | wxICON_EXCLAMATION, this); SetPlay(false); SetStop(false); SetRecord(false); } } UpdateStatusBar(GetActiveProject()); }
void ControlToolBar::PlayPlayRegion(double t0, double t1, bool looped /* = false */) { if (gAudioIO->IsBusy()) { mPlay->PopUp(); #if (AUDACITY_BRANDING == BRAND_THINKLABS) mLoopPlay->PopUp(); #elif (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) mPlay->Show(); mPause->Hide(); this->EnablePauseCommand(false); #endif return; } mStop->Enable(); mRewind->Disable(); mRecord->Disable(); mFF->Disable(); mPause->Enable(); this->EnablePauseCommand(true); AudacityProject *p = GetActiveProject(); if (p) { TrackList *t = p->GetTracks(); double maxofmins,minofmaxs; // JS: clarified how the final play region is computed; if (t1 == t0) { // msmeyer: When playing looped, we play the whole file, if // no range is selected. Otherwise, we play from t0 to end if (looped) { // msmeyer: always play from start t0 = t->GetStartTime(); } else { // move t0 to valid range if (t0 < 0) t0 = t->GetStartTime(); if (t0 > t->GetEndTime()) t0 = t->GetEndTime(); } // always play to end t1 = t->GetEndTime(); } else { // always t0 < t1 right? // the set intersection between the play region and the // valid range maximum of lower bounds if (t0 < t->GetStartTime()) maxofmins = t->GetStartTime(); else maxofmins = t0; // minimum of upper bounds if (t1 > t->GetEndTime()) minofmaxs = t->GetEndTime(); else minofmaxs = t1; // we test if the intersection has no volume if (minofmaxs <= maxofmins) { // no volume; play nothing return; } else { t0 = maxofmins; t1 = minofmaxs; } } bool success = false; if (t1 > t0) { int token = gAudioIO->StartStream(t->GetWaveTrackArray(false), WaveTrackArray(), t->GetTimeTrack(), p->GetRate(), t0, t1, looped); if (token != 0) { success = true; p->SetAudioIOToken(token); mBusyProject = p; SetVUMeters(p); } else { // msmeyer: Show error message if stream could not be opened wxMessageBox(_("Error while opening sound device. Please check the output " "device settings and the project sample rate."), _("Error"), wxOK | wxICON_EXCLAMATION, this); } } if (!success) { SetPlay(false); SetStop(false); SetRecord(false); } #if (AUDACITY_BRANDING == BRAND_AUDIOTOUCH) if (success) { mPlay->Hide(); mPause->Show(); this->EnablePauseCommand(true); this->SetBackgroundColour(*wxGREEN); // green for Playing this->Refresh(); } #endif } }
int ControlToolBar::PlayPlayRegion(const SelectedRegion &selectedRegion, const AudioIOStartStreamOptions &options, PlayMode mode, PlayAppearance appearance, /* = PlayOption::Straight */ bool backwards, /* = false */ bool playWhiteSpace /* = false */) { if (!CanStopAudioStream()) return -1; // Uncomment this for laughs! // backwards = true; double t0 = selectedRegion.t0(); double t1 = selectedRegion.t1(); // SelectedRegion guarantees t0 <= t1, so we need another boolean argument // to indicate backwards play. const bool looped = options.playLooped; if (backwards) std::swap(t0, t1); SetPlay(true, appearance); if (gAudioIO->IsBusy()) { SetPlay(false); return -1; } const bool cutpreview = appearance == PlayAppearance::CutPreview; if (cutpreview && t0==t1) { SetPlay(false); return -1; /* msmeyer: makes no sense */ } AudacityProject *p = GetActiveProject(); if (!p) { SetPlay(false); return -1; // Should never happen, but... } TrackList *t = p->GetTracks(); if (!t) { mPlay->PopUp(); return -1; // Should never happen, but... } p->mLastPlayMode = mode; bool hasaudio = false; TrackListIterator iter(t); for (Track *trk = iter.First(); trk; trk = iter.Next()) { if (trk->GetKind() == Track::Wave #ifdef EXPERIMENTAL_MIDI_OUT || trk->GetKind() == Track::Note #endif ) { hasaudio = true; break; } } double latestEnd = (playWhiteSpace)? t1 : t->GetEndTime(); if (!hasaudio) { SetPlay(false); return -1; // No need to continue without audio tracks } #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR) double init_seek = 0.0; #endif if (t1 == t0) { if (looped) { // play selection if there is one, otherwise // set start of play region to project start, // and loop the project from current play position. if ((t0 > p->GetSel0()) && (t0 < p->GetSel1())) { t0 = p->GetSel0(); t1 = p->GetSel1(); } else { // loop the entire project t0 = t->GetStartTime(); t1 = t->GetEndTime(); } } else { // move t0 to valid range if (t0 < 0) { t0 = t->GetStartTime(); } else if (t0 > t->GetEndTime()) { t0 = t->GetEndTime(); } #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR) else { init_seek = t0; //AC: init_seek is where playback will 'start' t0 = t->GetStartTime(); } #endif } t1 = t->GetEndTime(); } else { // maybe t1 < t0, with backwards scrubbing for instance if (backwards) std::swap(t0, t1); t0 = std::max(0.0, std::min(t0, latestEnd)); t1 = std::max(0.0, std::min(t1, latestEnd)); if (backwards) std::swap(t0, t1); } int token = -1; bool success = false; if (t1 != t0) { if (cutpreview) { const double tless = std::min(t0, t1); const double tgreater = std::max(t0, t1); double beforeLen, afterLen; gPrefs->Read(wxT("/AudioIO/CutPreviewBeforeLen"), &beforeLen, 2.0); gPrefs->Read(wxT("/AudioIO/CutPreviewAfterLen"), &afterLen, 1.0); double tcp0 = tless-beforeLen; double diff = tgreater - tless; double tcp1 = (tgreater+afterLen) - diff; SetupCutPreviewTracks(tcp0, tless, tgreater, tcp1); if (backwards) std::swap(tcp0, tcp1); if (mCutPreviewTracks) { AudioIOStartStreamOptions myOptions = options; myOptions.cutPreviewGapStart = t0; myOptions.cutPreviewGapLen = t1 - t0; token = gAudioIO->StartStream( mCutPreviewTracks->GetWaveTrackArray(false), WaveTrackArray(), #ifdef EXPERIMENTAL_MIDI_OUT NoteTrackArray(), #endif tcp0, tcp1, myOptions); } else { // Cannot create cut preview tracks, clean up and exit SetPlay(false); SetStop(false); SetRecord(false); return -1; } } else { // Lifted the following into AudacityProject::GetDefaultPlayOptions() /* if (!timetrack) { timetrack = t->GetTimeTrack(); } */ token = gAudioIO->StartStream(t->GetWaveTrackArray(false), WaveTrackArray(), #ifdef EXPERIMENTAL_MIDI_OUT t->GetNoteTrackArray(false), #endif t0, t1, options); } if (token != 0) { success = true; p->SetAudioIOToken(token); mBusyProject = p; #if defined(EXPERIMENTAL_SEEK_BEHIND_CURSOR) //AC: If init_seek was set, now's the time to make it happen. gAudioIO->SeekStream(init_seek); #endif } else { // msmeyer: Show error message if stream could not be opened wxMessageBox( _("Error while opening sound device. " "Please check the playback device settings and the project sample rate."), _("Error"), wxOK | wxICON_EXCLAMATION, this); } } if (!success) { SetPlay(false); SetStop(false); SetRecord(false); return -1; } // Let other UI update appearance if (p) p->GetRulerPanel()->HideQuickPlayIndicator(); return token; }
void EMVideoTransitionClip::SetMarkOutLength(int64 p_vLength) { SetStop(GetMediaLength() - p_vLength); }
void APalette::OnStop() { gAudioIO->Stop(); SetStop(false); }
bool nuiLayoutConstraint::Set(const nglString& rDescription) { int index = 0; nglUChar c = rDescription.GetNextUChar(index); if (c == '[') { // Fix start + ? int pos = index; int end = index; c = rDescription.GetNextUChar(index); while (c != ',' && c != '}') { end = index; c = rDescription.GetNextUChar(index); } nglString anchor1 = rDescription.Extract(pos, index - pos - 1); anchor1.Trim(); if (c == ',') { // Fix stop or fix size int pos = index; int end = index; c = rDescription.GetNextUChar(index); while (c != ']' && c != '}') { end = index; c = rDescription.GetNextUChar(index); } nglString anchor2 = rDescription.Extract(pos, index - pos - 1); anchor2.Trim(); if (c == ']') { // Start and Stop: SetStartAndStop(anchor1, anchor2); return true; } else if (c == '}') { // Start and size: SetStartAndSize(anchor1, anchor2.GetCFloat()); return true; } } else if (c == '}') { // Fix start SetStart(anchor1); return true; } } else if (c == '{') { // Fix end + ? int pos = index; int end = index; c = rDescription.GetNextUChar(index); while (c != ',' && c != '}' && c != ']') { end = index; c = rDescription.GetNextUChar(index); } nglString anchor1 = rDescription.Extract(pos, index - pos - 1); anchor1.Trim(); if (c == ',') { // Fix stop or fix size int pos = index; int end = index; c = rDescription.GetNextUChar(index); while (c != ']' && c != '}' && c != ',') { end = index; c = rDescription.GetNextUChar(index); } nglString anchor2 = rDescription.Extract(pos, index - pos - 1); anchor2.Trim(); if (c == ']') { // size and Stop: SetStopAndSize(anchor2, anchor1.GetCFloat()); return true; } else if (c == '}') { // Midle and size: if (anchor2.IsFloat()) SetMiddleAndSize(anchor1, anchor2.GetCFloat()); else SetMiddle(anchor1, anchor2); return true; } else if (c == ',') { nglString anchor2 = rDescription.Extract(pos, index - pos - 1); anchor2.Trim(); // Fix stop or fix size int pos = index; int end = index; c = rDescription.GetNextUChar(index); while (c != '}') { end = index; c = rDescription.GetNextUChar(index); } nglString anchor3 = rDescription.Extract(pos, index - pos - 1); anchor3.Trim(); SetMiddleAndSize(anchor1, anchor2, anchor3.GetCFloat()); return true; } } else if (c == '}') { // Fix middle if (anchor1.IsFloat()) SetMiddleAndSize(nglString::Null, anchor1.GetCFloat()); else SetMiddle(anchor1); return true; } else if (c == ']') { // Fix stop SetStop(anchor1); return true; } } else { SetSize(rDescription.GetCFloat()); return true; } return false; }
void ControlToolBar::OnRecord(wxCommandEvent &evt) { if (gAudioIO->IsBusy()) { mRecord->PopUp(); return; } AudacityProject *p = GetActiveProject(); if (p && p->GetCleanSpeechMode()) { size_t numProjects = gAudacityProjects.Count(); bool tracks = (p && !p->GetTracks()->IsEmpty()); if (tracks || (numProjects > 1)) { wxMessageBox(_("Recording in CleanSpeech mode is not possible when a track, or more than one project, is already open."), _("Recording not permitted"), wxOK | wxICON_INFORMATION, this); mRecord->PopUp(); mRecord->Disable(); return; } } if( evt.GetInt() == 1 ) // used when called by keyboard shortcut. Default (0) ignored. mRecord->SetShift(true); if( evt.GetInt() == 2 ) mRecord->SetShift(false); SetRecord(true); if (p) { TrackList *t = p->GetTracks(); TrackListIterator it(t); if(it.First() == NULL) mRecord->SetShift(false); double t0 = p->GetSel0(); double t1 = p->GetSel1(); if (t1 == t0) t1 = 1000000000.0; // record for a long, long time (tens of years) /* TODO: set up stereo tracks if that is how the user has set up * their preferences, and choose sample format based on prefs */ WaveTrackArray newRecordingTracks, playbackTracks; /* REQUIRES PORTMIDI */ // NoteTrackArray midiTracks; bool duplex; gPrefs->Read(wxT("/AudioIO/Duplex"), &duplex, true); if(duplex){ playbackTracks = t->GetWaveTrackArray(false); /* REQUIRES PORTMIDI */ // midiTracks = t->GetNoteTrackArray(false); } else { playbackTracks = WaveTrackArray(); /* REQUIRES PORTMIDI */ // midiTracks = NoteTrackArray(); } // If SHIFT key was down, the user wants append to tracks int recordingChannels = 0; bool shifted = mRecord->WasShiftDown(); if (shifted) { TrackListIterator it(t); WaveTrack *wt; bool sel = false; double allt0 = t0; // Find the maximum end time of selected and all wave tracks for (Track *tt = it.First(); tt; tt = it.Next()) { if (tt->GetKind() == Track::Wave) { wt = (WaveTrack *)tt; if (wt->GetEndTime() > allt0) { allt0 = wt->GetEndTime(); } if (tt->GetSelected()) { sel = true; if (duplex) playbackTracks.Remove(wt); if (wt->GetEndTime() > t0) { t0 = wt->GetEndTime(); } } } } // Use end time of all wave tracks if none selected if (!sel) { t0 = allt0; } // Pad selected/all wave tracks to make them all the same length for (Track *tt = it.First(); tt; tt = it.Next()) { if (tt->GetKind() == Track::Wave && (tt->GetSelected() || !sel)) { wt = (WaveTrack *)tt; t1 = wt->GetEndTime(); if (t1 < t0) { WaveTrack *newTrack = p->GetTrackFactory()->NewWaveTrack(); newTrack->InsertSilence(0.0, t0 - t1); newTrack->Flush(); wt->Clear(t1, t0); wt->Paste(t1, newTrack); delete newTrack; } newRecordingTracks.Add(wt); } } t1 = 1000000000.0; // record for a long, long time (tens of years) } else { recordingChannels = gPrefs->Read(wxT("/AudioIO/RecordChannels"), 2); for (int c = 0; c < recordingChannels; c++) { WaveTrack *newTrack = p->GetTrackFactory()->NewWaveTrack(); int initialheight = newTrack->GetHeight(); newTrack->SetOffset(t0); if (recordingChannels <= 2) { newTrack->SetHeight(initialheight/recordingChannels); } else { newTrack->SetMinimized(true); } if (recordingChannels == 2) { if (c == 0) { newTrack->SetChannel(Track::LeftChannel); newTrack->SetLinked(true); } else { newTrack->SetChannel(Track::RightChannel); newTrack->SetTeamed(true); } } else { newTrack->SetChannel( Track::MonoChannel ); } newRecordingTracks.Add(newTrack); } // msmeyer: StartStream calls a callback which triggers auto-save, so // we add the tracks where recording is done into now. We remove them // later if starting the stream fails for (unsigned int i = 0; i < newRecordingTracks.GetCount(); i++) t->Add(newRecordingTracks[i]); } int token = gAudioIO->StartStream(playbackTracks, newRecordingTracks, /* REQUIRES PORTMIDI */ // midiTracks, t->GetTimeTrack(), p->GetRate(), t0, t1, p); bool success = (token != 0); if (success) { p->SetAudioIOToken(token); mBusyProject = p; SetVUMeters(p); } else { // msmeyer: Delete recently added tracks if opening stream fails if (!shifted) { for (unsigned int i = 0; i < newRecordingTracks.GetCount(); i++) { t->Remove(newRecordingTracks[i]); delete newRecordingTracks[i]; } } // msmeyer: Show error message if stream could not be opened wxMessageBox(_("Error while opening sound device. " wxT("Please check the input device settings and the project sample rate.")), _("Error"), wxOK | wxICON_EXCLAMATION, this); SetPlay(false); SetStop(false); SetRecord(false); } } }
void CRole::Update(float dt) { m_oldPos = m_pos; CMoveableObj::Update(dt); /* m_mapPosX = (int)(m_pos.x/m_pMap->m_tileWidth); m_mapPosY = (int)(m_pos.y/m_pMap->m_tileHeight); if(m_mapPosX < 0 || m_mapPosY < 0 || m_pos.x < 0 || m_pos.y < 0 || m_mapPosX >= m_pMap->m_col || m_mapPosY >= m_pMap->m_row) {//阻止角色离开地图 m_pos = m_oldPos; SetStop(); } if(m_pos==m_dst) { if(m_bSwt) { m_dst = m_fdst; ComputeDir(); m_bSwt = false; } else if(m_bBeginFindPath) { Pos next; if(GetNextPos(&next, (float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2)) { m_dst = next; if(next.x != m_pos.x && next.y != m_pos.y)//转折点 { ComputeDir(); m_bBeginFindPath = false; m_bSwt = true;//打开转折开关 ClearPath(); } }else { Stop(); m_bBeginFindPath = false; } }else { Stop(); m_bBeginFindPath = false; } } else { if(!m_pAni[m_dir]->IsPlaying()) { m_pAni[m_dir]->Play(); m_pAni[m_dir]->SetFrame(1); } m_bMoving = true; } if(CollideMap() && !m_bBeginFindPath && m_bMoving && !m_bSwt) { m_bBeginFindPath = true; //m_bSwt = false; m_pos = m_oldPos; int t=timeGetTime(); //计算寻路时间 FindPath(&m_pos, &m_fdst); printf("寻路消耗时间: %d\n",timeGetTime()-t); // if(GetNextPos(&m_dst, (float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2)) ComputeDir(); else { m_bBeginFindPath = false; SetStop(); } }*/ //test if(m_pos==m_dst) { if(GetNextPos(&m_dst, (float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2)) { ComputeDir(); }else { Stop(); m_bBeginFindPath = false; } } else { if(!m_pAni[m_dir]->IsPlaying()) { m_pAni[m_dir]->Play(); m_pAni[m_dir]->SetFrame(1); } m_bMoving = true; } m_rect.x1 = m_pos.x - m_pMap->m_tileWidth/2.f +1; m_rect.y1 = m_pos.y - m_pMap->m_tileHeight/2.f +1; m_rect.x2 = m_pos.x + m_pMap->m_tileWidth/2.f-1; m_rect.y2 = m_pos.y + m_pMap->m_tileHeight/2.f -1; x1 = (int)(m_rect.x1/m_pMap->m_tileWidth); y1 = (int)(m_rect.y1/m_pMap->m_tileHeight); x2 = (int)(m_rect.x2/m_pMap->m_tileWidth); y2 = (int)(m_rect.y1/m_pMap->m_tileHeight); x3 = (int)(m_rect.x1/m_pMap->m_tileWidth); y3 = (int)(m_rect.y2/m_pMap->m_tileHeight); x4 = (int)(m_rect.x2/m_pMap->m_tileWidth); y4 = (int)(m_rect.y2/m_pMap->m_tileHeight); if(IsInMap(x1,y1)) m_mapTile[INDEX(x1,y1)] = false; if(IsInMap(x2,y2)) m_mapTile[INDEX(x2,y2)] = false; if(IsInMap(x3,y3)) m_mapTile[INDEX(x3,y3)] = false; if(IsInMap(x4,y4)) m_mapTile[INDEX(x4,y4)] = false; for(MOBJ_ITR itr = m_mobjs->begin(); itr != m_mobjs->end();itr ++) { hgeRect* rct = (*itr)->GetRect(); if(m_rect.Intersect(rct)) { if((*itr)->GetID() != m_uID) { //m_pos = m_oldPos; //Stop(); //x1 = (int)(m_rect.x1/m_pMap->m_tileWidth); //y1 = (int)(m_rect.y1/m_pMap->m_tileHeight); //x2 = (int)(m_rect.x2/m_pMap->m_tileWidth); //y2 = (int)(m_rect.y1/m_pMap->m_tileHeight); //x3 = (int)(m_rect.x1/m_pMap->m_tileWidth); //y3 = (int)(m_rect.y2/m_pMap->m_tileHeight); //x4 = (int)(m_rect.x2/m_pMap->m_tileWidth); //y4 = (int)(m_rect.y2/m_pMap->m_tileHeight); //if(IsInMap(x1,y1)) // point1 = m_mapTile[INDEX(x1,y1)]; //if(IsInMap(x2,y2)) // point2 = m_mapTile[INDEX(x2,y2)]; //if(IsInMap(x3,y3)) // point3 = m_mapTile[INDEX(x3,y3)]; //if(IsInMap(x4,y4)) // point4 = m_mapTile[INDEX(x4,y4)]; //if(IsInMap(x1,y1)) // m_mapTile[INDEX(x1,y1)] = false; //if(IsInMap(x2,y2)) // m_mapTile[INDEX(x2,y2)] = false; //if(IsInMap(x3,y3)) // m_mapTile[INDEX(x3,y3)] = false; //if(IsInMap(x4,y4)) // m_mapTile[INDEX(x4,y4)] = false; // ////m_bBeginFindPath = true; FindPath(&m_pos, &m_fdst); if(GetNextPos(&m_dst, (float)m_pMap->m_tileWidth/2, (float)m_pMap->m_tileHeight/2)) ComputeDir(); else { //m_bBeginFindPath = false; SetStop(); } //if(IsInMap(x1,y1)) // m_mapTile[INDEX(x1,y1)] = point1; //if(IsInMap(x2,y2)) // m_mapTile[INDEX(x2,y2)] = point2; //if(IsInMap(x3,y3)) // m_mapTile[INDEX(x3,y3)] = point3; //if(IsInMap(x4,y4)) // m_mapTile[INDEX(x4,y4)] = point4; // break; } } } m_pAni[m_dir]->Update(dt); }