proxy cpus usage, unlock win before render_proxy, snap tweaks
[goodguy/history.git] / cinelerra-5.1 / cinelerra / recordlabel.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 "clip.h"
23 #include "file.h"
24 #include "labels.h"
25 #include "recordlabel.h"
26
27
28 RecordLabel::RecordLabel(double position)
29  : ListItem<RecordLabel>()
30 {
31         this->position = position;
32 }
33
34 RecordLabel::~RecordLabel()
35 {
36 }
37
38
39 RecordLabels::RecordLabels()
40  : List<RecordLabel>()
41 {
42 }
43
44 RecordLabels::RecordLabels(File *file)
45  : List<RecordLabel>()
46 {
47         int cell_no = 0;
48         double last_position = -1.;
49         double position;
50         while( !file->get_cell_time(++cell_no, position) ) {
51                 if( position > last_position )
52                         append(new RecordLabel(last_position=position));
53         }
54 }
55
56 RecordLabels::~RecordLabels()
57 {
58         delete_labels();
59 }
60
61 int RecordLabels::delete_labels()
62 {
63         RecordLabel *current, *next_;
64         for(current = first; current; current = next_)
65         {
66                 next_ = NEXT;
67                 remove(current);
68         }
69         return 0;
70 }
71
72 int RecordLabels::toggle_label(double position)
73 {
74         RecordLabel *current;
75 // find label the position is after
76         for(current = first;
77                 current && current->position < position;
78                 current = NEXT)
79         {
80                 ;
81         }
82
83         if(current)
84         {
85 //printf("position %ld current->position %ld current->original %d\n", position, current->position,  current->original);
86                 if(EQUIV(current->position, position))
87                 {
88 // remove it
89                         remove(current);
90                 }
91                 else
92                 {
93 // insert before it
94                         current = insert_before(current);
95                         current->position = position;
96                 }
97         }
98         else
99         {           // insert after last
100 //printf("position %ld\n", position);
101                 append(new RecordLabel(position));
102         }
103         return 0;
104 }
105
106 double RecordLabels::get_prev_label(double position)
107 {
108         RecordLabel *current;
109
110         for(current = last;
111                 current && current->position > position;
112                 current = PREVIOUS)
113         {
114                 ;
115         }
116 //printf("%ld\n", current->position);
117         if(current && current->position <= position)
118                 return current->position;
119         else
120                 return -1;
121 }
122
123 double RecordLabels::get_next_label(double position)
124 {
125         RecordLabel *current;
126
127         for(current = first;
128                 current && current->position <= position;
129                 current = NEXT)
130         {
131                 ;
132         }
133         if(current && current->position >= position) return current->position;
134         return -1;
135 }
136
137 double RecordLabels::goto_prev_label(double position)
138 {
139         RecordLabel *current;
140
141         for(current = last;
142                 current && current->position >= position;
143                 current = PREVIOUS)
144         {
145                 ;
146         }
147 //printf("%ld\n", current->position);
148         if(current && current->position <= position) return current->position;
149         return -1;
150 }
151
152 double RecordLabels::goto_next_label(double position)
153 {
154         RecordLabel *current;
155
156         for(current = first;
157                 current && current->position <= position;
158                 current = NEXT)
159         {
160                 ;
161         }
162         if(current && current->position >= position) return current->position;
163         return -1;
164 }
165