@ -20,10 +20,13 @@
// You should have received a copy of the GNU General Public License
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
//
# include <circle/logger.h>
# include "performanceconfig.h"
# include "performanceconfig.h"
# include "mididevice.h"
# include "mididevice.h"
# include <cstring>
# include <cstring>
# include <algorithm>
# include <algorithm>
LOGMODULE ( " Performance " ) ;
CPerformanceConfig : : CPerformanceConfig ( FATFS * pFileSystem )
CPerformanceConfig : : CPerformanceConfig ( FATFS * pFileSystem )
: m_Properties ( " performance.ini " , pFileSystem )
: m_Properties ( " performance.ini " , pFileSystem )
@ -747,8 +750,27 @@ bool CPerformanceConfig::GetInternalFolderOk()
return nInternalFolderOk ;
return nInternalFolderOk ;
}
}
bool CPerformanceConfig : : CheckFreePerformanceSlot ( void )
{
if ( nLastPerformance < NUM_PERFORMANCES )
{
// There is a free slot...
return true ;
}
else
{
return false ;
}
}
bool CPerformanceConfig : : CreateNewPerformanceFile ( void )
bool CPerformanceConfig : : CreateNewPerformanceFile ( void )
{
{
if ( nLastPerformance > = NUM_PERFORMANCES ) {
// No space left for new performances
LOGWARN ( " No space left for new performance " ) ;
return false ;
}
std : : string sPerformanceName = NewPerformanceName ;
std : : string sPerformanceName = NewPerformanceName ;
NewPerformanceName = " " ;
NewPerformanceName = " " ;
nActualPerformance = nLastPerformance ;
nActualPerformance = nLastPerformance ;
@ -829,19 +851,23 @@ bool CPerformanceConfig::ListPerformances()
Result = f_findfirst ( & Directory , & FileInfo , " SD:/ " PERFORMANCE_DIR , " *.ini " ) ;
Result = f_findfirst ( & Directory , & FileInfo , " SD:/ " PERFORMANCE_DIR , " *.ini " ) ;
for ( unsigned i = 0 ; Result = = FR_OK & & FileInfo . fname [ 0 ] ; i + + )
for ( unsigned i = 0 ; Result = = FR_OK & & FileInfo . fname [ 0 ] ; i + + )
{
{
if ( ! ( FileInfo . fattrib & ( AM_HID | AM_SYS ) ) )
if ( nLastPerformance > = NUM_PERFORMANCES ) {
{
LOGNOTE ( " Skipping performance %s " , FileInfo . fname ) ;
std : : string FileName = FileInfo . fname ;
} else {
size_t nLen = FileName . length ( ) ;
if ( ! ( FileInfo . fattrib & ( AM_HID | AM_SYS ) ) )
if ( nLen > 8 & & nLen < 26 & & strcmp ( FileName . substr ( 6 , 1 ) . c_str ( ) , " _ " ) = = 0 )
{
{
std : : string FileName = FileInfo . fname ;
nPIndex = stoi ( FileName . substr ( 0 , 6 ) ) ;
size_t nLen = FileName . length ( ) ;
if ( nPIndex > nLastFileIndex )
if ( nLen > 8 & & nLen < 26 & & strcmp ( FileName . substr ( 6 , 1 ) . c_str ( ) , " _ " ) = = 0 )
{
{
nLastFileIndex = nPIndex ;
nPIndex = stoi ( FileName . substr ( 0 , 6 ) ) ;
}
if ( nPIndex > nLastFileIndex )
{
m_nPerformanceFileName [ nLastPerformance + + ] = FileName ;
nLastFileIndex = nPIndex ;
}
m_nPerformanceFileName [ nLastPerformance + + ] = FileName ;
}
}
}
}
}
@ -854,6 +880,8 @@ bool CPerformanceConfig::ListPerformances()
}
}
}
}
LOGNOTE ( " Number of Performances: %d " , nLastPerformance ) ;
return nInternalFolderOk ;
return nInternalFolderOk ;
}
}