ardour
sndfilesource.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 Paul Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #ifndef __sndfile_source_h__
21 #define __sndfile_source_h__
22 
23 #include <sndfile.h>
24 
25 #include "ardour/audiofilesource.h"
26 #include "ardour/broadcast_info.h"
27 
28 namespace ARDOUR {
29 
31  public:
33  SndFileSource (Session&, const std::string& path, int chn, Flag flags);
34 
35  /* Constructor to be called for new in-session files */
36  SndFileSource (Session&, const std::string& path, const std::string& origin,
37  SampleFormat samp_format, HeaderFormat hdr_format, framecnt_t rate,
39 
40  /* Constructor to be called for recovering files being used for
41  * capture. They are in-session, they already exist, they should not
42  * be writable. They are an odd hybrid (from a constructor point of
43  * view) of the previous two constructors.
44  */
45  SndFileSource (Session&, const std::string& path, int chn);
46 
50  SndFileSource (Session&, const XMLNode&);
51 
52  ~SndFileSource ();
53 
54  float sample_rate () const;
55  int update_header (framepos_t when, struct tm&, time_t);
56  int flush_header ();
57  void flush ();
58 
59  framepos_t natural_position () const;
60 
61  framepos_t last_capture_start_frame() const;
62  void mark_capture_start (framepos_t);
63  void mark_capture_end ();
64  void clear_capture_marks();
65 
66  bool set_destructive (bool yn);
67 
68  bool one_of_several_channels () const;
69 
70  bool clamped_at_unity () const;
71 
72  static void setup_standard_crossfades (Session const &, framecnt_t sample_rate);
74 
75  static int get_soundfile_info (const std::string& path, SoundFileInfo& _info, std::string& error_msg);
76 
77  protected:
78  void close ();
79 
80  void set_path (const std::string& p);
81  void set_header_timeline_position ();
82 
83  framecnt_t read_unlocked (Sample *dst, framepos_t start, framecnt_t cnt) const;
84  framecnt_t write_unlocked (Sample *dst, framecnt_t cnt);
85  framecnt_t write_float (Sample* data, framepos_t pos, framecnt_t cnt);
86 
87  private:
88  SNDFILE* _sndfile;
89  SF_INFO _info;
91 
92  void init_sndfile ();
93  int open();
94  int setup_broadcast_info (framepos_t when, struct tm&, time_t);
95  void file_closed ();
96 
97  /* destructive */
98 
102 
106  framepos_t file_pos; // unit is frames
108 
109  framecnt_t crossfade (Sample* data, framecnt_t cnt, int dir);
110  void set_timeline_position (framepos_t);
111  framecnt_t destructive_write_unlocked (Sample *dst, framecnt_t cnt);
112  framecnt_t nondestructive_write_unlocked (Sample *dst, framecnt_t cnt);
113  void handle_header_position_change ();
115 };
116 
117 } // namespace ARDOUR
118 
119 #endif /* __sndfile_source_h__ */
120 
HeaderFormat
Definition: types.h:475
static gain_t * out_coefficient
static framecnt_t xfade_frames
Definition: sndfilesource.h:99
float gain_t
Definition: types.h:58
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
#define origin
static gain_t * in_coefficient
int64_t framecnt_t
Definition: types.h:76
float Sample
Definition: types.h:54
static const Source::Flag default_writable_flags
Definition: sndfilesource.h:73
Definition: amp.h:29
framepos_t capture_start_frame
int64_t framepos_t
Definition: types.h:66
#define LIBARDOUR_API
SampleFormat
Definition: types.h:460
Definition: xml++.h:95
BroadcastInfo * _broadcast_info
Definition: sndfilesource.h:90
PBD::ScopedConnection header_position_connection