@@ -62,45 +62,18 @@ void PlaylistCWrapper::OnPresetSwitchFailed(const char* presetFilename, const ch
6262 }
6363
6464 auto * playlist = reinterpret_cast <PlaylistCWrapper*>(userData);
65+
66+ playlist->m_lastPresetSwitchFailed = true ;
67+ playlist->m_lastFailedPresetFileName = presetFilename;
68+ playlist->m_lastFailedPresetError = message;
69+
6570 auto lastDirection = playlist->GetLastNavigationDirection ();
6671
6772 if (lastDirection != NavigationDirection::Last)
6873 {
6974 // Don't let the user go back to a broken preset.
7075 playlist->RemoveLastHistoryEntry ();
7176 }
72-
73- // Preset switch may fail due to broken presets, retry a few times before giving up.
74- if (playlist->m_presetSwitchFailedCount >= playlist->m_presetSwitchRetryCount )
75- {
76- if (playlist->m_presetSwitchFailedEventCallback != nullptr )
77- {
78- playlist->m_presetSwitchFailedEventCallback (presetFilename, message,
79- playlist->m_presetSwitchFailedEventUserData );
80- }
81-
82- return ;
83- }
84-
85- playlist->m_presetSwitchFailedCount ++;
86-
87- uint32_t playlistIndex{};
88- switch (lastDirection)
89- {
90- case NavigationDirection::Previous:
91- playlistIndex = playlist->PreviousPresetIndex ();
92- break ;
93-
94- case NavigationDirection::Next:
95- playlistIndex = playlist->NextPresetIndex ();
96- break ;
97-
98- case NavigationDirection::Last:
99- playlistIndex = playlist->LastPresetIndex ();
100- break ;
101- }
102-
103- playlist->PlayPresetIndex (playlistIndex, playlist->m_hardCutRequested , false );
10477}
10578
10679
@@ -132,22 +105,64 @@ void PlaylistCWrapper::SetPresetSwitchFailedCallback(projectm_playlist_preset_sw
132105
133106void PlaylistCWrapper::PlayPresetIndex (uint32_t index, bool hardCut, bool resetFailureCount)
134107{
135- if (resetFailureCount)
136- {
137- m_presetSwitchFailedCount = 0 ;
138- }
139-
140108 m_hardCutRequested = hardCut;
141109
142- const auto & playlistItems = Items ();
110+ auto & playlistItems = Items ();
143111
144- if (playlistItems.size () <= index)
112+ uint32_t failedCount = 0 ;
113+ while (true )
145114 {
146- return ;
147- }
115+ if (playlistItems.size () <= index)
116+ {
117+ return ;
118+ }
119+
120+ projectm_load_preset_file (m_projectMInstance,
121+ playlistItems.at (index).Filename ().c_str (), !hardCut);
148122
149- projectm_load_preset_file (m_projectMInstance,
150- playlistItems.at (index).Filename ().c_str (), !hardCut);
123+ if (!m_lastPresetSwitchFailed)
124+ {
125+ break ;
126+ }
127+
128+ failedCount++;
129+
130+ if (failedCount >= m_presetSwitchRetryCount)
131+ {
132+ if (m_presetSwitchFailedEventCallback != nullptr )
133+ {
134+ m_presetSwitchFailedEventCallback (m_lastFailedPresetFileName.c_str (),
135+ m_lastFailedPresetError.c_str (),
136+ m_presetSwitchFailedEventUserData);
137+ }
138+
139+ return ;
140+ }
141+
142+ m_lastPresetSwitchFailed = false ;
143+
144+ // Remove failed preset from playlist
145+ RemoveItem (index);
146+
147+ if (playlistItems.empty ())
148+ {
149+ return ;
150+ }
151+
152+ // Set next index to proper value depending on navigation
153+ switch (GetLastNavigationDirection ())
154+ {
155+ case NavigationDirection::Last:
156+ index = LastPresetIndex ();
157+ break ;
158+ case NavigationDirection::Next:
159+ index = NextPresetIndex ();
160+ break ;
161+ case NavigationDirection::Previous:
162+ index = PreviousPresetIndex ();
163+ break ;
164+ }
165+ }
151166
152167 if (m_presetSwitchedEventCallback != nullptr )
153168 {
@@ -156,13 +171,13 @@ void PlaylistCWrapper::PlayPresetIndex(uint32_t index, bool hardCut, bool resetF
156171}
157172
158173
159- void PlaylistCWrapper::SetLastNavigationDirection (PlaylistCWrapper:: NavigationDirection direction)
174+ void PlaylistCWrapper::SetLastNavigationDirection (NavigationDirection direction)
160175{
161176 m_lastNavigationDirection = direction;
162177}
163178
164179
165- auto PlaylistCWrapper::GetLastNavigationDirection () const -> PlaylistCWrapper:: NavigationDirection
180+ auto PlaylistCWrapper::GetLastNavigationDirection () const -> NavigationDirection
166181{
167182 return m_lastNavigationDirection;
168183}
@@ -263,7 +278,7 @@ auto projectm_playlist_items(projectm_playlist_handle instance, uint32_t start,
263278
264279 if (start >= items.size ())
265280 {
266- auto * array = new char * [1 ] {};
281+ auto * array = new char *[1 ]{};
267282 return array;
268283 }
269284
0 commit comments