prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / 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         return 0;
122 }
123
124 double RecordLabels::get_next_label(double position)
125 {
126         RecordLabel *current;
127
128         for(current = first; 
129                 current && current->position <= position; 
130                 current = NEXT)
131         {
132                 ;
133         }
134         if(current && current->position >= position) return current->position; else return -1;
135         return 0;
136 }
137
138 double RecordLabels::goto_prev_label(double position)
139 {
140         RecordLabel *current;
141         
142         for(current = last; 
143                 current && current->position >= position; 
144                 current = PREVIOUS)
145         {
146                 ;
147         }
148 //printf("%ld\n", current->position);
149         if(current && current->position <= position) return current->position; else return -1;
150         return 0;
151 }
152
153 double RecordLabels::goto_next_label(double position)
154 {
155         RecordLabel *current;
156
157         for(current = first; 
158                 current && current->position <= position; 
159                 current = NEXT)
160         {
161                 ;
162         }
163         if(current && current->position >= position) return current->position; else return -1;
164         return 0;
165 }
166