Credit Andrew fix Alpha Bug of BT558 + small cleanup
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / atrack.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 "aedit.h"
23 #include "aedits.h"
24 #include "amodule.h"
25 #include "apluginset.h"
26 #include "atrack.h"
27 #include "autoconf.h"
28 #include "aautomation.h"
29 #include "edit.h"
30 #include "edl.h"
31 #include "edlsession.h"
32 #include "cache.h"
33 #include "clip.h"
34 #include "datatype.h"
35 #include "file.h"
36 #include "filexml.h"
37 #include "floatautos.h"
38 #include "language.h"
39 #include "localsession.h"
40 #include "mainsession.h"
41 #include "panautos.h"
42 #include "theme.h"
43 #include "trackcanvas.h"
44 #include "tracks.h"
45
46 #include <string.h>
47
48
49
50 ATrack::ATrack(EDL *edl, Tracks *tracks)
51  : Track(edl, tracks)
52 {
53         data_type = TRACK_AUDIO;
54         data_h = edl->local_session->zoom_atrack;
55 }
56
57 ATrack::~ATrack()
58 {
59 }
60
61 // Used by PlaybackEngine
62 void ATrack::synchronize_params(Track *track)
63 {
64         Track::synchronize_params(track);
65         //ATrack *atrack = (ATrack*)track;
66 }
67
68 int ATrack::copy_settings(Track *track)
69 {
70         Track::copy_settings(track);
71         //ATrack *atrack = (ATrack*)track;
72         return 0;
73 }
74
75
76 int ATrack::save_header(FileXML *file)
77 {
78         file->tag.set_property("TYPE", "AUDIO");
79         return 0;
80 }
81
82 int ATrack::save_derived(FileXML *file)
83 {
84         file->append_newline();
85         return 0;
86 }
87
88 int ATrack::load_header(FileXML *file, uint32_t load_flags)
89 {
90         return 0;
91 }
92
93
94 int ATrack::load_derived(FileXML *file, uint32_t load_flags)
95 {
96         return 0;
97 }
98
99 void ATrack::create_objects()
100 {
101         Track::create_objects();
102         automation = new AAutomation(edl, this);
103         automation->create_objects();
104         edits = new AEdits(edl, this);
105 }
106
107 int ATrack::vertical_span(Theme *theme)
108 {
109         int track_h = Track::vertical_span(theme);
110         int patch_h = theme->title_h;
111         if( expand_view )
112                 patch_h += theme->play_h + theme->fade_h + theme->meter_h + theme->pan_h;
113         return MAX(track_h, patch_h);
114 }
115
116 PluginSet* ATrack::new_plugins()
117 {
118         return new APluginSet(edl, this);
119 }
120
121 int ATrack::load_defaults(BC_Hash *defaults)
122 {
123         Track::load_defaults(defaults);
124         return 0;
125 }
126
127 void ATrack::set_default_title()
128 {
129         Track *current = ListItem<Track>::list->first;
130         int i;
131         for(i = 0; current; current = NEXT)
132         {
133                 if(current->data_type == TRACK_AUDIO) i++;
134         }
135         sprintf(title, _("Audio %d"), i);
136         BC_Resources::encode_to_utf8(title, BCTEXTLEN);
137 }
138
139 int64_t ATrack::to_units(double position, int round)
140 {
141         return round ? Units::round(position * edl->session->sample_rate) :
142                 Units::to_int64(position * edl->session->sample_rate + 1e-6);
143 }
144
145 double ATrack::to_doubleunits(double position)
146 {
147         return position * edl->session->sample_rate;
148 }
149
150 double ATrack::from_units(int64_t position)
151 {
152         return (double)position / edl->session->sample_rate;
153 }
154
155 int ATrack::identical(int64_t sample1, int64_t sample2)
156 {
157 // Units of samples
158         if(labs(sample1 - sample2) <= 1) return 1; else return 0;
159 }
160
161 int64_t ATrack::length()
162 {
163         return edits->length();
164 }
165
166 int ATrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int &current_channel)
167 {
168         if(!strcmp(xml->tag.get_title(), "PANAUTOS"))
169         {
170                 current_channel = xml->tag.get_property("CHANNEL", current_channel);
171 //              pan_autos->paste(start, end, total_length, xml, "/PANAUTOS", mwindow->session->autos_follow_edits);
172                 return 1;
173         }
174         return 0;
175 }
176