1 /*
2  * Copyright (C) 2002 2003 2004 2005, Magnus Hjorth
3  *
4  * This file is part of mhWaveEdit.
5  *
6  * mhWaveEdit is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * mhWaveEdit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mhWaveEdit; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 
22 #ifndef TEMPFILE_H_INCLUDED
23 #define TEMPFILE_H_INCLUDED
24 
25 #include <gtk/gtk.h>
26 #include "chunk.h"
27 #include "datasource.h"
28 
29 
30 /* This type identifies the temporary file during creation */
31 typedef gpointer TempFile;
32 
33 /* Start creating a temporary file. Returns a handle to the temporary file or
34  * NULL on failure. The handle must later be destroyed using either
35  * tempfile_finished or tempfile_abort.
36  *
37  * The realtime argument should be used when recording or performing
38  * other timing-sensitive tasks. Files in each temporary directory will
39  * then be opened right away to avoid delays later. Also, memory
40  * buffering is disabled and data goes directly to file.
41  */
42 
43 TempFile tempfile_init(Dataformat *format, gboolean realtime);
44 
45 
46 
47 /* Write data into the temporary file.
48  *
49  * temp - Handle to the temporary file.
50  * data - The data to output
51  * length - Length of the data
52  *
53  * return value - TRUE on failure, FALSE on success
54  */
55 
56 gboolean tempfile_write(TempFile temp, gpointer data, guint length);
57 
58 
59 
60 /* Abort creating the temporary file.
61  *   temp - Handle to the temporary file.
62  */
63 
64 void tempfile_abort(TempFile temp);
65 
66 
67 
68 /* End the temporary file.
69  *   temp - Handle to the temporary file.
70  *   format - The PCM format the written data was in.
71  *   fake_pcm - If the written data was really raw sample_t values
72  *   return value - A Chunk containing the temporary data or NULL on
73  *                  failure.
74  */
75 
76 Chunk *tempfile_finished(TempFile temp);
77 
78 void set_temp_directories(GList *dirs);
79 
80 gchar *get_temp_directory(guint num);
81 
82 gchar *get_temp_filename(guint dirnum);
83 gchar *get_temp_filename_d(gchar *dir);
84 
85 
86 /* Creates a wav file header for the specified sample format and size and
87  * puts it in the supplied buffer.
88  * Returns size of the header, always 44 or 58 bytes. */
89 
90 guint get_wav_header(Dataformat *format, off_t datasize, void *buffer);
91 
92 gboolean write_wav_header(EFILE *f, Dataformat *format, off_t datasize);
93 
94 #endif
95