Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / channeldb.C
blobce5671551295d68e9a729a6a63f0f6aaf4a01974
1 #include "channel.h"
2 #include "channeldb.h"
3 #include "filesystem.h"
4 #include "filexml.h"
5 #include "preferences.inc"
8 #include <stdio.h>
10 ChannelDB::ChannelDB()
14 ChannelDB::~ChannelDB()
16         channels.remove_all_objects();
19 char* ChannelDB::prefix_to_path(char *path, char *prefix)
21         FileSystem fs;
22         char directory[BCTEXTLEN];
23         sprintf(directory, BCASTDIR);
24         fs.complete_path(directory);
25         fs.join_names(path, directory, prefix);
26         return path;
29 void ChannelDB::load(char *prefix)
31         FileXML file;
32         char path[BCTEXTLEN];
34         prefix_to_path(path, prefix);
35         channels.remove_all_objects();
37         int done = file.read_from_file(path, 1);
39         channels.remove_all_objects();
40 // Load channels
41         while(!done)
42         {
43                 Channel *channel = new Channel;
44                 if(!(done = channel->load(&file)))
45                         channels.append(channel);
46                 else
47                 {
48                         delete channel;
49                 }
50         }
53 void ChannelDB::save(char *prefix)
55         char path[BCTEXTLEN];
56         FileXML file;
58         prefix_to_path(path, prefix);
60         if(channels.total)
61         {
62                 for(int i = 0; i < channels.total; i++)
63                 {
64 // Save channel here
65                         channels.values[i]->save(&file);
66                 }
67                 file.terminate_string();
68                 file.write_to_file(path);
69         }
72 Channel* ChannelDB::get(int number)
74         if(number >= 0 && number < channels.total)
75                 return channels.values[number];
76         else
77                 return 0;
80 void ChannelDB::copy_from(ChannelDB *src)
82         clear();
83         for(int i = 0; i < src->size(); i++)
84         {
85                 Channel *dst = new Channel;
86                 channels.append(dst);
87                 dst->copy_settings(src->get(i));
88         }
91 int ChannelDB::size()
93         return channels.total;
96 void ChannelDB::clear()
98         channels.remove_all_objects();
101 void ChannelDB::append(Channel *channel)
103         channels.append(channel);
106 void ChannelDB::remove_number(int number)
108         channels.remove_number(number);
111 void ChannelDB::set(int number, Channel *ptr)
113         channels.values[number] = ptr;
116 //      Local Variables:
117 //      mode: C++
118 //      c-file-style: "linux"
119 //      End: