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.

139 lines
4.0KB

  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. #pragma once
  19. #include <stdlib.h>
  20. #include "types.h"
  21. #include "Peak.H"
  22. #include <stdio.h>
  23. class Audio_File;
  24. class Peaks
  25. {
  26. struct peakdata {
  27. nframes_t chunksize; /* should always be a power of 2 */
  28. Peak data[];
  29. };
  30. struct peakbuffer {
  31. size_t size; /* total allocation size */
  32. size_t len; /* number of peaks */
  33. nframes_t offset; /* starting sample */
  34. peakdata *buf;
  35. peakbuffer ( )
  36. {
  37. size = len = 0;
  38. }
  39. };
  40. class Streamer
  41. {
  42. FILE *_fp;
  43. Peak *_peak;
  44. int _chunksize;
  45. int _channels;
  46. int _index;
  47. /* not permitted */
  48. Streamer ( const Streamer &rhs );
  49. const Streamer &operator= ( const Streamer &rhs );
  50. public:
  51. Streamer ( const char *filename, int channels, nframes_t chunksize );
  52. ~Streamer ( );
  53. void write ( const sample_t *buf, nframes_t nframes );
  54. };
  55. class Builder
  56. {
  57. FILE *fp;
  58. size_t last_block_pos;
  59. const Peaks *_peaks;
  60. void write_block_header ( nframes_t chunksize );
  61. public:
  62. bool make_peaks_mipmap ( void );
  63. bool make_peaks ( void );
  64. Builder ( const Peaks *peaks );
  65. };
  66. static peakbuffer _peakbuf;
  67. Audio_File *_clip;
  68. mutable float _fpp;
  69. int read_peaks ( nframes_t s, int npeaks, nframes_t chunksize ) const;
  70. int read_source_peaks ( Peak *peaks, nframes_t s, int npeaks, nframes_t chunksize ) const;
  71. int read_source_peaks ( Peak *peaks, int npeaks, nframes_t chunksize ) const;
  72. int read_peakfile_peaks ( Peak *peaks, nframes_t s, int npeaks, nframes_t chunksize ) const;
  73. Streamer * volatile _peak_writer; /* exists when streaming peaks to disk */
  74. /* not permitted */
  75. Peaks ( const Peaks &rhs );
  76. const Peaks &operator= ( const Peaks &rhs );
  77. public:
  78. static bool mipmapped_peakfiles;
  79. static const int cache_minimum;
  80. static const int cache_levels;
  81. static const int cache_step;
  82. Peaks ( Audio_File *c );
  83. ~Peaks ( );
  84. Peak *peakbuf ( void ) const { return Peaks::_peakbuf.buf->data; }
  85. void clip ( Audio_File *c ) { _clip = c; }
  86. int fill_buffer ( float fpp, nframes_t s, nframes_t e ) const;
  87. void read ( int X, float *hi, float *lo ) const;
  88. bool ready ( nframes_t s, int npeaks, nframes_t chunksize ) const;
  89. bool current ( void ) const;
  90. bool make_peaks ( void ) const;
  91. bool make_peaks_mipmap ( void ) const;
  92. void prepare_for_writing ( void );
  93. void finish_writing ( void );
  94. void write ( sample_t *buf, nframes_t nframes );
  95. };