Credit ffmpeg team with upgrade to 6.1
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / channeldb.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program 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  * This program 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 this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "channel.h"
23 #include "channeldb.h"
24 #include "file.h"
25 #include "filesystem.h"
26 #include "filexml.h"
27 #include "preferences.inc"
28
29
30 #include <stdio.h>
31
32 ChannelDB::ChannelDB()
33 {
34 }
35
36 ChannelDB::~ChannelDB()
37 {
38         channels.remove_all_objects();
39 }
40
41 char* ChannelDB::prefix_to_path(char *path, const char *filename)
42 {
43         FileSystem fs;
44         char directory[BCTEXTLEN];
45         sprintf(directory, "%s/", File::get_config_path());
46         fs.complete_path(directory);
47         fs.join_names(path, directory, filename);
48         return path;
49 }
50
51 void ChannelDB::load(const char *filename)
52 {
53         if( !filename ) return;
54
55         FileXML file;
56         char path[BCTEXTLEN];
57
58         prefix_to_path(path, filename);
59         channels.remove_all_objects();
60
61         int done = file.read_from_file(path, 1);
62
63         channels.remove_all_objects();
64 // Load channels
65         while(!done)
66         {
67                 Channel *channel = new Channel;
68                 if(!(done = channel->load(&file)))
69                         channels.append(channel);
70                 else
71                 {
72                         delete channel;
73                 }
74         }
75 }
76
77 void ChannelDB::save(const char *filename)
78 {
79         if( !filename ) return;
80         char path[BCTEXTLEN];
81         FileXML file;
82
83         prefix_to_path(path, filename);
84
85         if(channels.total)
86         {
87                 for(int i = 0; i < channels.total; i++)
88                 {
89 // Save channel here
90                         channels.values[i]->save(&file);
91                 }
92                 file.terminate_string();
93                 file.write_to_file(path);
94         }
95 }
96
97 Channel* ChannelDB::get(int number)
98 {
99         if(number >= 0 && number < channels.total)
100                 return channels.values[number];
101         else
102                 return 0;
103 }
104
105 void ChannelDB::copy_from(ChannelDB *src)
106 {
107         clear();
108         for(int i = 0; i < src->size(); i++)
109         {
110                 Channel *dst = new Channel;
111                 channels.append(dst);
112                 dst->copy_settings(src->get(i));
113         }
114 }
115
116 int ChannelDB::number_of(Channel *channel)
117 {
118         return channels.number_of(channel);
119 }
120
121 int ChannelDB::size()
122 {
123         return channels.total;
124 }
125
126 void ChannelDB::clear()
127 {
128         channels.remove_all_objects();
129 }
130
131 void ChannelDB::append(Channel *channel)
132 {
133         channels.append(channel);
134 }
135
136 void ChannelDB::remove_number(int number)
137 {
138         channels.remove_number(number);
139 }
140
141 void ChannelDB::set(int number, Channel *ptr)
142 {
143         channels.values[number] = ptr;
144 }