4 #include "filesystem.h"
9 #include "mainindexes.h"
10 #include "mainprogress.h"
12 #include "mwindowgui.h"
17 #define _(String) gettext(String)
18 #define gettext_noop(String) String
19 #define N_(String) gettext_noop (String)
21 MainIndexes::MainIndexes(MWindow *mwindow)
25 this->mwindow = mwindow;
26 input_lock = new Condition(0, "MainIndexes::input_lock");
27 next_lock = new Mutex("MainIndexes::next_lock");
28 interrupt_lock = new Condition(1, "MainIndexes::interrupt_lock");
31 indexfile = new IndexFile(mwindow);
34 MainIndexes::~MainIndexes()
36 mwindow->mainprogress->cancelled = 1;
41 delete interrupt_lock;
44 void MainIndexes::add_next_asset(Asset *asset)
46 next_lock->lock("MainIndexes::add_next_asset");
49 IndexFile indexfile(mwindow);
51 //printf("MainIndexes::add_next_asset 1 %s\n", asset->path);
52 if(!indexfile.open_index(asset))
54 //printf("MainIndexes::add_next_asset 2\n");
55 asset->index_status = INDEX_READY;
56 indexfile.close_index();
59 // Put copy of asset in stack, not the real thing.
61 //printf("MainIndexes::add_next_asset 3\n");
62 Asset *new_asset = new Asset;
64 // If the asset existed and was overwritten, the status will be READY.
65 new_asset->index_status = INDEX_NOTTESTED;
66 next_assets.append(new_asset);
72 void MainIndexes::delete_current_assets()
74 current_assets.remove_all_objects();
77 void MainIndexes::start_loop()
83 void MainIndexes::stop_loop()
88 interrupt_lock->unlock();
93 void MainIndexes::start_build()
95 //printf("MainIndexes::start_build 1\n");
97 // Locked up when indexes were already being built and an asset was
99 // interrupt_lock.lock();
100 input_lock->unlock();
103 void MainIndexes::interrupt_build()
105 //printf("MainIndexes::interrupt_build 1\n");
107 indexfile->interrupt_index();
108 //printf("MainIndexes::interrupt_build 2\n");
109 interrupt_lock->lock("MainIndexes::interrupt_build");
110 //printf("MainIndexes::interrupt_build 3\n");
111 interrupt_lock->unlock();
112 //printf("MainIndexes::interrupt_build 4\n");
115 void MainIndexes::load_next_assets()
117 delete_current_assets();
119 // Transfer from new list
120 next_lock->lock("MainIndexes::load_next_assets");
121 for(int i = 0; i < next_assets.total; i++)
122 current_assets.append(next_assets.values[i]);
124 // Clear pointers from new list only
125 next_assets.remove_all();
130 void MainIndexes::run()
134 // Wait for new assets to be released
135 input_lock->lock("MainIndexes::run 1");
138 interrupt_lock->lock("MainIndexes::run 2");
139 //printf("MainIndexes::run 1 %d\n", next_assets.total);
142 //printf("MainIndexes::run 2 %d\n", current_assets.total);
149 // test index of each asset
150 MainProgressBar *progress = 0;
151 for(int i = 0; i < current_assets.total && !interrupt_flag; i++)
153 Asset *current_asset = current_assets.values[i];
154 //printf("MainIndexes::run 3 %s %d %d\n", current_asset->path, current_asset->index_status, current_asset->audio_data);
156 if(current_asset->index_status == INDEX_NOTTESTED &&
157 current_asset->audio_data)
159 //printf("MainIndexes::run 4\n");
163 // Try to create index now.
164 if(indexfile->open_index(current_asset))
166 //printf("MainIndexes::run 5 %p %s %p %p\n", current_asset, current_asset->path, mwindow, mwindow->mainprogress);
169 if(mwindow->gui) mwindow->gui->lock_window("MainIndexes::run 1");
170 progress = mwindow->mainprogress->start_progress("Building Indexes...", 1);
171 if(mwindow->gui) mwindow->gui->unlock_window();
174 //printf("MainIndexes::run 5 %p %s\n", current_asset, current_asset->path);
176 indexfile->create_index(current_asset, progress);
177 //printf("MainIndexes::run 6 %p %s\n", current_asset, current_asset->path);
178 if(progress->is_cancelled()) interrupt_flag = 1;
179 //printf("MainIndexes::run 7 %p %s\n", current_asset, current_asset->path);
182 // Exists. Update real thing.
184 //printf("MainIndexes::run 8\n");
185 if(current_asset->index_status == INDEX_NOTTESTED)
187 current_asset->index_status = INDEX_READY;
188 if(mwindow->gui) mwindow->gui->lock_window("MainIndexes::run 2");
189 mwindow->edl->set_index_file(current_asset);
190 if(mwindow->gui) mwindow->gui->unlock_window();
192 indexfile->close_index();
196 //printf("MainIndexes::run 8\n");
198 //printf("MainIndexes::run 9\n");
200 //printf("MainIndexes::run 10\n");
202 if(progress) // progress box is only created when an index is built
204 if(mwindow->gui) mwindow->gui->lock_window("MainIndexes::run 3");
205 progress->stop_progress();
207 if(mwindow->gui) mwindow->gui->unlock_window();
215 //printf("MainIndexes::run 11\n");
217 interrupt_lock->unlock();