|
32 | 32 | #include "FamiTracker.h" |
33 | 33 | #include "FamiTrackerTypes.h" |
34 | 34 | #include "FTMComponentInterface.h" // // // |
35 | | -#include "ChannelState.h" // // // |
36 | 35 | #include "FamiTrackerDoc.h" |
37 | 36 | #include "FamiTrackerView.h" |
38 | 37 | #include "VisualizerWnd.h" |
@@ -1527,32 +1526,41 @@ void CSoundGen::ApplyGlobalState() // // // |
1527 | 1526 | int Frame = IsPlaying() ? GetPlayerFrame() : m_pTrackerView->GetSelectedFrame(); |
1528 | 1527 | int Row = IsPlaying() ? GetPlayerRow() : m_pTrackerView->GetSelectedRow(); |
1529 | 1528 | if (stFullState *State = m_pDocument->RetrieveSoundState(GetPlayerTrack(), Frame, Row, -1)) { |
1530 | | - if (State->Tempo != -1) |
1531 | | - m_iTempo = State->Tempo; |
1532 | | - if (State->GroovePos >= 0) { |
1533 | | - m_iGroovePosition = State->GroovePos; |
1534 | | - if (State->Speed >= 0) |
1535 | | - m_iGrooveIndex = State->Speed; |
1536 | | - if (m_pDocument->GetGroove(m_iGrooveIndex) != NULL) |
1537 | | - m_iSpeed = m_pDocument->GetGroove(m_iGrooveIndex)->GetEntry(m_iGroovePosition); |
1538 | | - } |
1539 | | - else { |
1540 | | - if (State->Speed >= 0) |
1541 | | - m_iSpeed = State->Speed; |
1542 | | - m_iGrooveIndex = -1; |
1543 | | - } |
| 1529 | + ApplyGlobalTempoState(State); |
1544 | 1530 | m_iLastHighlight = m_pDocument->GetHighlightAt(GetPlayerTrack(), Frame, Row).First; |
1545 | | - SetupSpeed(); |
| 1531 | + |
1546 | 1532 | for (int i = 0; i < m_pDocument->GetChannelCount(); i++) { |
1547 | 1533 | for (int j = 0; j < sizeof(m_pTrackerChannels) / sizeof(CTrackerChannel*); ++j) // // // pick this out later |
1548 | 1534 | if (m_pChannels[j] && m_pTrackerChannels[j]->GetID() == State->State[i].ChannelIndex) { |
1549 | 1535 | m_pChannels[j]->ApplyChannelState(&State->State[i]); break; |
1550 | 1536 | } |
1551 | 1537 | } |
| 1538 | + |
1552 | 1539 | delete State; |
1553 | 1540 | } |
1554 | 1541 | } |
1555 | 1542 |
|
| 1543 | +// Separate updating groove, tempo and speed |
| 1544 | +// to allow ResetTempo() to get the most recent state without updating the channel state |
| 1545 | +void CSoundGen::ApplyGlobalTempoState(stFullState *pState) |
| 1546 | +{ |
| 1547 | + if (pState->Tempo != -1) |
| 1548 | + m_iTempo = pState->Tempo; |
| 1549 | + if (pState->GroovePos >= 0) { |
| 1550 | + m_iGroovePosition = pState->GroovePos; |
| 1551 | + if (pState->Speed >= 0) |
| 1552 | + m_iGrooveIndex = pState->Speed; |
| 1553 | + if (m_pDocument->GetGroove(m_iGrooveIndex) != NULL) |
| 1554 | + m_iSpeed = m_pDocument->GetGroove(m_iGrooveIndex)->GetEntry(m_iGroovePosition); |
| 1555 | + } |
| 1556 | + else { |
| 1557 | + if (pState->Speed >= 0) |
| 1558 | + m_iSpeed = pState->Speed; |
| 1559 | + m_iGrooveIndex = -1; |
| 1560 | + } |
| 1561 | + SetupSpeed(); |
| 1562 | +} |
| 1563 | + |
1556 | 1564 | /*! \brief Obtains a human-readable form of a channel state object. |
1557 | 1565 | \warning The output of this method is neither guaranteed nor required to match that of |
1558 | 1566 | CChannelHandler::GetStateString. |
@@ -1858,10 +1866,20 @@ void CSoundGen::ResetTempo() |
1858 | 1866 |
|
1859 | 1867 | m_iTempoAccum = 0; |
1860 | 1868 |
|
1861 | | - if (theApp.GetSettings()->General.bRetrieveChanState) // // // |
1862 | | - ApplyGlobalState(); |
1863 | | - // Legacy behavior |
| 1869 | + if (theApp.GetSettings()->General.bRetrieveChanState) { // !! !! |
| 1870 | + // Calling on ApplyGlobalState() causes crackly audio on FDS |
| 1871 | + // May have something to do with conflicting stFullState pointers? haven't investigated |
| 1872 | + // So we do a reduced version here where we don't update the channel handlers. |
| 1873 | + int Frame = IsPlaying() ? GetPlayerFrame() : m_pTrackerView->GetSelectedFrame(); |
| 1874 | + int Row = IsPlaying() ? GetPlayerRow() : m_pTrackerView->GetSelectedRow(); |
| 1875 | + if (stFullState *State = m_pDocument->RetrieveSoundState(GetPlayerTrack(), Frame, Row, -1)) { |
| 1876 | + ApplyGlobalTempoState(State); |
| 1877 | + m_iLastHighlight = m_pDocument->GetHighlightAt(GetPlayerTrack(), Frame, Row).First; |
| 1878 | + delete State; |
| 1879 | + } |
| 1880 | + } |
1864 | 1881 | else { |
| 1882 | + // Legacy behavior |
1865 | 1883 | if (m_pDocument->GetSongGroove(m_iPlayTrack) && m_pDocument->GetGroove(m_iSpeed) != NULL) { // // // |
1866 | 1884 | m_iGrooveIndex = m_iSpeed; |
1867 | 1885 | m_iGroovePosition = 0; |
|
0 commit comments