make kfrm share_lock recursive, dial back sketcher clamps
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / wavecache.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 "cstrdup.h"
23 #include "indexable.h"
24 #include "mutex.h"
25 #include "wavecache.h"
26
27 #include <string.h>
28
29
30 WaveCacheItem::WaveCacheItem()
31  : CacheItemBase()
32 {
33 }
34
35 WaveCacheItem::~WaveCacheItem()
36 {
37 }
38
39 int WaveCacheItem::get_size()
40 {
41         return sizeof(WaveCacheItem) + (path ? strlen(path) : 0);
42 }
43
44
45
46 WaveCache::WaveCache()
47  : CacheBase()
48 {
49 }
50
51 WaveCache::~WaveCache()
52 {
53 }
54
55
56 WaveCacheItem* WaveCache::get_wave(int indexable_id,
57         int channel,
58         int64_t start,
59         int64_t end)
60 {
61         lock->lock("WaveCache::get_wave");
62         WaveCacheItem *result = 0;
63
64         result = (WaveCacheItem*)get_item(start);
65         while(result && result->position == start)
66         {
67                 if(result->indexable_id == indexable_id &&
68                         result->channel == channel &&
69                         result->end == end)
70                 {
71                         result->age = get_age();
72                         return result;
73                 }
74                 else
75                         result = (WaveCacheItem*)result->next;
76         }
77
78         lock->unlock();
79         return 0;
80 }
81
82 void WaveCache::put_wave(Indexable *indexable,
83         int channel,
84         int64_t start,
85         int64_t end,
86         double high,
87         double low)
88 {
89         lock->lock("WaveCache::put_wave");
90         WaveCacheItem *item = new WaveCacheItem;
91         item->indexable_id = indexable->id;
92         item->path = cstrdup(indexable->path);
93         item->channel = channel;
94         item->position = start;
95         item->end = end;
96         item->high = high;
97         item->low = low;
98
99         put_item(item);
100         lock->unlock();
101 }
102
103
104
105
106
107