Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.7KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008 Jonathan Moore Liles */
  3. /* */
  4. /* This program is free software; you can redistribute it and/or modify it */
  5. /* under the terms of the GNU General Public License as published by the */
  6. /* Free Software Foundation; either version 2 of the License, or (at your */
  7. /* option) any later version. */
  8. /* */
  9. /* This program is distributed in the hope that it will be useful, but WITHOUT */
  10. /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
  11. /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
  12. /* more details. */
  13. /* */
  14. /* You should have received a copy of the GNU General Public License along */
  15. /* with This program; see the file COPYING. If not,write to the Free Software */
  16. /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /*******************************************************************************/
  18. #include "Audio_File.H"
  19. #include "Audio_File_SF.H"
  20. #include "Audio_File_Dummy.H"
  21. #include "util/debug.h"
  22. #include <string.h>
  23. std::map <std::string, Audio_File*> Audio_File::_open_files;
  24. Audio_File::~Audio_File ( )
  25. {
  26. _open_files[ std::string( _filename ) ] = NULL;
  27. if ( _filename )
  28. free( _filename );
  29. }
  30. const Audio_File::format_desc *
  31. Audio_File::find_format ( const format_desc *fd, const char *name )
  32. {
  33. for ( ; fd->name; ++fd )
  34. if ( ! strcmp( fd->name, name ) )
  35. return fd;
  36. return NULL;
  37. }
  38. void
  39. Audio_File::all_supported_formats ( std::list <const char *> &formats )
  40. {
  41. const format_desc *fd;
  42. fd = Audio_File_SF::supported_formats;
  43. for ( ; fd->name; ++fd )
  44. formats.push_back( fd->name );
  45. }
  46. static bool
  47. is_absolute ( const char *name )
  48. {
  49. return *name == '/';
  50. }
  51. /** return a static pointer to /name/ corrected for relative path. */
  52. const char *Audio_File::realname ( const char *name )
  53. {
  54. static char rname[512];
  55. if ( is_absolute( name ) )
  56. strncpy( rname, name, sizeof( rname ) );
  57. else
  58. snprintf( rname, sizeof( rname ), "sources/%s", name );
  59. return rname;
  60. }
  61. const char *
  62. Audio_File::filename ( void ) const
  63. {
  64. return realname( _filename );
  65. }
  66. /** attmpet to open any supported filetype */
  67. Audio_File *
  68. Audio_File::from_file ( const char * filename )
  69. {
  70. Audio_File *a;
  71. if ( ( a = _open_files[ std::string( filename ) ] ) )
  72. return a;
  73. if ( ( a = Audio_File_SF::from_file( filename ) ) )
  74. goto done;
  75. // TODO: other formats
  76. DWARNING( "creating dummy source for \"%s\"", filename );
  77. /* FIXME: wrong place for this? */
  78. if ( ( a = Audio_File_Dummy::from_file( filename ) ) )
  79. goto done;
  80. return NULL;
  81. done:
  82. _open_files[ std::string( filename ) ] = a;
  83. return a;
  84. }
  85. bool
  86. Audio_File::read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, Peak **pbuf, int *channels )
  87. {
  88. // Peaks pk;
  89. if ( dummy() )
  90. {
  91. *peaks = (end - start) / fpp;
  92. *channels = 0;
  93. *pbuf = NULL;
  94. return false;
  95. }
  96. else
  97. {
  98. *peaks = 0;
  99. *channels = 0;
  100. *pbuf = NULL;
  101. *peaks = _peaks.fill_buffer( fpp, start, end );
  102. *channels = this->channels();
  103. *pbuf = _peaks.peakbuf();
  104. return true;
  105. }
  106. }