Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[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  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include "aedit.h"
24 #include "aedits.h"
25 #include "amodule.h"
26 #include "apluginset.h"
27 #include "atrack.h"
28 #include "autoconf.h"
29 #include "aautomation.h"
30 #include "edit.h"
31 #include "edl.h"
32 #include "edlsession.h"
33 #include "cache.h"
34 #include "clip.h"
35 #include "datatype.h"
36 #include "file.h"
37 #include "filexml.h"
38 #include "floatautos.h"
39 #include "language.h"
40 #include "localsession.h"
41 #include "mainsession.h"
42 #include "panautos.h"
43 #include "theme.h"
44 #include "trackcanvas.h"
45 #include "tracks.h"
46
47 #include <string.h>
48
49
50
51 ATrack::ATrack(EDL *edl, Tracks *tracks)
52  : Track(edl, tracks)
53 {
54         data_type = TRACK_AUDIO;
55         data_h = edl->local_session->zoom_atrack;
56 }
57
58 ATrack::~ATrack()
59 {
60 }
61
62 // Used by PlaybackEngine
63 void ATrack::synchronize_params(Track *track)
64 {
65         Track::synchronize_params(track);
66         //ATrack *atrack = (ATrack*)track;
67 }
68
69 int ATrack::copy_settings(Track *track)
70 {
71         Track::copy_settings(track);
72         //ATrack *atrack = (ATrack*)track;
73         return 0;
74 }
75
76
77 int ATrack::save_header(FileXML *file)
78 {
79         file->tag.set_property("TYPE", "AUDIO");
80         return 0;
81 }
82
83 int ATrack::save_derived(FileXML *file)
84 {
85         file->append_newline();
86         return 0;
87 }
88
89 int ATrack::load_header(FileXML *file, uint32_t load_flags)
90 {
91         return 0;
92 }
93
94
95 int ATrack::load_derived(FileXML *file, uint32_t load_flags)
96 {
97         return 0;
98 }
99
100 void ATrack::create_objects()
101 {
102         Track::create_objects();
103         automation = new AAutomation(edl, this);
104         automation->create_objects();
105         edits = new AEdits(edl, this);
106 }
107
108 int ATrack::vertical_span(Theme *theme)
109 {
110         int track_h = Track::vertical_span(theme);
111         int patch_h = theme->title_h;
112         if( expand_view )
113                 patch_h += theme->play_h + theme->fade_h + theme->meter_h + theme->pan_h;
114         return MAX(track_h, patch_h);
115 }
116
117 PluginSet* ATrack::new_plugins()
118 {
119         return new APluginSet(edl, this);
120 }
121
122 int ATrack::load_defaults(BC_Hash *defaults)
123 {
124         Track::load_defaults(defaults);
125         return 0;
126 }
127
128 void ATrack::set_default_title()
129 {
130         Track *current = ListItem<Track>::list->first;
131         int i;
132         for(i = 0; current; current = NEXT)
133         {
134                 if(current->data_type == TRACK_AUDIO) i++;
135         }
136         sprintf(title, _("Audio %d"), i);
137         BC_Resources::encode_to_utf8(title, BCTEXTLEN);
138 }
139
140 int64_t ATrack::to_units(double position, int round)
141 {
142         return round ? Units::round(position * edl->session->sample_rate) :
143                 Units::to_int64(position * edl->session->sample_rate + 1e-6);
144 }
145
146 double ATrack::to_doubleunits(double position)
147 {
148         return position * edl->session->sample_rate;
149 }
150
151 double ATrack::from_units(int64_t position)
152 {
153         return (double)position / edl->session->sample_rate;
154 }
155
156 int ATrack::identical(int64_t sample1, int64_t sample2)
157 {
158 // Units of samples
159         if(labs(sample1 - sample2) <= 1) return 1; else return 0;
160 }
161
162 int64_t ATrack::length()
163 {
164         return edits->length();
165 }
166
167 int ATrack::paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *xml, int &current_channel)
168 {
169         if(!strcmp(xml->tag.get_title(), "PANAUTOS"))
170         {
171                 current_channel = xml->tag.get_property("CHANNEL", current_channel);
172 //              pan_autos->paste(start, end, total_length, xml, "/PANAUTOS", mwindow->session->autos_follow_edits);
173                 return 1;
174         }
175         return 0;
176 }
177