extensions.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #include "main.h"
  2. #include "resource.h"
  3. #include "config.h"
  4. #include "assert.h"
  5. #include "../Agave/Language/api_language.h"
  6. #include "../nu/AutoWide.h"
  7. #include <strsafe.h>
  8. char defaultExtensions[1024] = {0};
  9. char fileExtensionsString[1200] = {0};
  10. int SizeAvailableTypes()
  11. {
  12. int size = 0;
  13. int numTypes = 0;
  14. sf_command( 0, SFC_GET_FORMAT_MAJOR_COUNT, &numTypes, sizeof( numTypes ) );
  15. SF_FORMAT_INFO info;
  16. for ( int i = 0; i < numTypes; i++ )
  17. {
  18. info.format = i;
  19. sf_command( 0, SFC_GET_FORMAT_MAJOR, &info, sizeof( info ) );
  20. size += lstrlenA( info.extension ) + 1 /* ; or \0 */;
  21. //size+=lstrlen(info.name) + 1 /* \0 */;
  22. }
  23. return size;
  24. }
  25. int ExtensionExists( const char *ext, const char *extensionList )
  26. {
  27. size_t len = lstrlenA( ext );
  28. char temp[ 20 ] = { 0 };
  29. const char *s = extensionList;
  30. while ( s && *s )
  31. {
  32. lstrcpynA( temp, s, 20 );
  33. char *scan = temp;
  34. while ( scan && *scan && *scan != ';' )
  35. scan = CharNextA( scan );
  36. *scan = 0;
  37. if ( !lstrcmpiA( temp, ext ) )
  38. return 1;
  39. s += lstrlenA( temp );
  40. if ( *s == ';' )
  41. s = CharNextA( s );
  42. }
  43. return 0;
  44. }
  45. // TODO: sort default extension list
  46. void BuildDefaultExtensions()
  47. {
  48. // if we want a light extension list, here it is: lstrcpyn(defaultExtensions, "WAV;AIFF;VOC;AU;AIF;AIFC;SND");
  49. int size = SizeAvailableTypes() + 1;
  50. assert( size < 1024 ); // TODO
  51. char *extPtr = defaultExtensions;
  52. size_t extPtrCch = 1023;
  53. extPtr[ 0 ] = 0;
  54. int numTypes = 0;
  55. sf_command( 0, SFC_GET_FORMAT_MAJOR_COUNT, &numTypes, sizeof( numTypes ) );
  56. SF_FORMAT_INFO info = { 0 };
  57. for ( int i = 0; i < numTypes; i++ )
  58. {
  59. info.format = i;
  60. sf_command( 0, SFC_GET_FORMAT_MAJOR, &info, sizeof( info ) );
  61. if ( !_strcmpi( info.extension, "mpc" ) )
  62. continue;
  63. if ( ExtensionExists( info.extension, defaultExtensions ) )
  64. continue;
  65. if ( *CharPrevA( defaultExtensions, extPtr ) )
  66. StringCchCatExA( extPtr, extPtrCch, ";", &extPtr, &extPtrCch, 0 );
  67. StringCchCatExA( extPtr, extPtrCch, info.extension, &extPtr, &extPtrCch, 0 );
  68. }
  69. }
  70. void SetFileExtensions( const char *extList )
  71. {
  72. ZeroMemory( &fileExtensionsString, sizeof( fileExtensionsString ) );
  73. char *end = 0;
  74. StringCchCopyExA( fileExtensionsString, 1200, extList, &end, 0, 0 );
  75. StringCchCopyExA( end + 1, 1200, WASABI_API_LNGSTRING( IDS_SOUND_FILES ), 0, 0, 0 );
  76. plugin.FileExtensions = fileExtensionsString;
  77. }
  78. static const wchar_t *pExtList[]={L"AIFF",L"AIF",L"AU",L"AVR",L"CAF",L"HTK",L"IFF",L"MAT",L"PAF",L"PVF",L"RAW",L"RF64",L"SD2",L"SDS",L"SF",L"VOC",L"W64",L"WAV",L"WVE",L"XI"};
  79. static const int pExtDescIdList[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
  80. static const int pExtDescList[] =
  81. {
  82. IDS_FAMILY_STRING_AAIF,
  83. IDS_FAMILY_STRING_AAIF,
  84. IDS_FAMILY_STRING_AU,
  85. IDS_FAMILY_STRING_AVR,
  86. IDS_FAMILY_STRING_ACA,
  87. IDS_FAMILY_STRING_HMMTS,
  88. IDS_FAMILY_STRING_AAIF,
  89. IDS_FAMILY_STRING_MATLAB,
  90. IDS_FAMILY_STRING_PARIS,
  91. IDS_FAMILY_STRING_PVF,
  92. IDS_FAMILY_STRING_HEADERLESS_RAW,
  93. IDS_FAMILY_STRING_RF64,
  94. IDS_FAMILY_STRING_SDII,
  95. IDS_FAMILY_STRING_RAW_MIDI_SAMPLE_DUMP,
  96. IDS_FAMILY_STRING_IRCAM,
  97. IDS_FAMILY_STRING_CVOC,
  98. IDS_FAMILY_STRING_SFWOW64,
  99. IDS_FAMILY_STRING_MSWAV,
  100. IDS_FAMILY_STRING_MSWAV,
  101. IDS_FAMILY_STRING_FT2WAV,
  102. };
  103. BOOL GetExtensionName( LPCWSTR pszExt, LPWSTR pszDest, INT cchDest )
  104. {
  105. INT maxCount, index;
  106. DWORD lcid;
  107. SF_FORMAT_INFO info;
  108. lcid = MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ), SORT_DEFAULT );
  109. // first scan our list if there is no entry ask libsnd. we do this cause libsnd format description sucks
  110. for ( index = sizeof( pExtList ) / sizeof( wchar_t * ) - 1; index >= 0 && CSTR_EQUAL != CompareStringW( lcid, NORM_IGNORECASE, pszExt, -1, pExtList[ index ], -1 ); index-- );
  111. if ( index >= 0 && S_OK == StringCchCopyW( pszDest, cchDest, WASABI_API_LNGSTRINGW( pExtDescList[ pExtDescIdList[ index ] ] ) ) ) return TRUE;
  112. sf_command( 0, SFC_GET_FORMAT_MAJOR_COUNT, &maxCount, sizeof( maxCount ) );
  113. for ( index = 0; index < maxCount; index++ )
  114. {
  115. info.format = index;
  116. sf_command( 0, SFC_GET_FORMAT_MAJOR, &info, sizeof( info ) );
  117. if ( CSTR_EQUAL == CompareStringW( lcid, NORM_IGNORECASE, pszExt, -1, AutoWide( info.extension ), -1 ) )
  118. {
  119. INT len1, len2;
  120. len1 = lstrlenA( info.extension );
  121. len2 = lstrlenA( info.name );
  122. if ( len2 > len1 )
  123. {
  124. if ( CSTR_EQUAL == CompareStringA( lcid, NORM_IGNORECASE, info.extension, len1, info.name, len1 ) )
  125. {
  126. info.name += len1;
  127. len2 -= len1;
  128. }
  129. if ( len2 > 0 && ' ' == *info.name )
  130. {
  131. info.name++;
  132. len2--;
  133. }
  134. if ( len2 > 0 && '(' == *info.name )
  135. {
  136. info.name++;
  137. len2--;
  138. }
  139. if ( len2 > 0 && ')' == info.name[ len2 - 1 ] )
  140. len2--;
  141. }
  142. return ( S_OK == StringCchCopyNW( pszDest, cchDest, AutoWide( info.name ), len2 ) );
  143. }
  144. }
  145. return FALSE;
  146. }