4 #include "filesystem.h"
10 #include "mainindexes.h"
11 #include "mainprogress.h"
13 #include "mwindowgui.h"
18 MainIndexes::MainIndexes(MWindow *mwindow)
22 this->mwindow = mwindow;
23 input_lock = new Condition(0, "MainIndexes::input_lock");
24 next_lock = new Mutex("MainIndexes::next_lock");
25 interrupt_lock = new Condition(1, "MainIndexes::interrupt_lock");
28 indexfile = new IndexFile(mwindow);
31 MainIndexes::~MainIndexes()
33 mwindow->mainprogress->cancelled = 1;
38 delete interrupt_lock;
41 void MainIndexes::add_next_asset(Asset *asset)
43 next_lock->lock("MainIndexes::add_next_asset");
46 IndexFile indexfile(mwindow);
48 //printf("MainIndexes::add_next_asset 1 %s\n", asset->path);
49 if(!indexfile.open_index(asset))
51 //printf("MainIndexes::add_next_asset 2\n");
52 asset->index_status = INDEX_READY;
53 indexfile.close_index();
56 // Put copy of asset in stack, not the real thing.
58 //printf("MainIndexes::add_next_asset 3\n");
59 Asset *new_asset = new Asset;
61 // If the asset existed and was overwritten, the status will be READY.
62 new_asset->index_status = INDEX_NOTTESTED;
63 next_assets.append(new_asset);
69 void MainIndexes::delete_current_assets()
71 current_assets.remove_all_objects();
74 void MainIndexes::start_loop()
80 void MainIndexes::stop_loop()
85 interrupt_lock->unlock();
90 void MainIndexes::start_build()
92 //printf("MainIndexes::start_build 1\n");
94 // Locked up when indexes were already being built and an asset was
96 // interrupt_lock.lock();
100 void MainIndexes::interrupt_build()
102 //printf("MainIndexes::interrupt_build 1\n");
104 indexfile->interrupt_index();
105 //printf("MainIndexes::interrupt_build 2\n");
106 interrupt_lock->lock("MainIndexes::interrupt_build");
107 //printf("MainIndexes::interrupt_build 3\n");
108 interrupt_lock->unlock();
109 //printf("MainIndexes::interrupt_build 4\n");
112 void MainIndexes::load_next_assets()
114 delete_current_assets();
116 // Transfer from new list
117 next_lock->lock("MainIndexes::load_next_assets");
118 for(int i = 0; i < next_assets.total; i++)
119 current_assets.append(next_assets.values[i]);
121 // Clear pointers from new list only
122 next_assets.remove_all();
127 void MainIndexes::run()
131 // Wait for new assets to be released
132 input_lock->lock("MainIndexes::run 1");
134 interrupt_lock->lock("MainIndexes::run 2");
143 // test index of each asset
144 MainProgressBar *progress = 0;
145 for(int i = 0; i < current_assets.total && !interrupt_flag; i++)
147 Asset *current_asset = current_assets.values[i];
148 //printf("MainIndexes::run 3 %s %d %d\n", current_asset->path, current_asset->index_status, current_asset->audio_data);
150 if(current_asset->index_status == INDEX_NOTTESTED &&
151 current_asset->audio_data)
153 //printf("MainIndexes::run 4\n");
157 // Try to create index now.
158 if(indexfile->open_index(current_asset))
160 //printf("MainIndexes::run 5 %p %s %p %p\n", current_asset, current_asset->path, mwindow, mwindow->mainprogress);
163 if(mwindow->gui) mwindow->gui->lock_window("MainIndexes::run 1");
164 progress = mwindow->mainprogress->start_progress(_("Building Indexes..."), 1);
165 if(mwindow->gui) mwindow->gui->unlock_window();
168 //printf("MainIndexes::run 5 %p %s\n", current_asset, current_asset->path);
170 indexfile->create_index(current_asset, progress);
171 //printf("MainIndexes::run 6 %p %s\n", current_asset, current_asset->path);
172 if(progress->is_cancelled()) interrupt_flag = 1;
173 //printf("MainIndexes::run 7 %p %s\n", current_asset, current_asset->path);
176 // Exists. Update real thing.
178 //printf("MainIndexes::run 8\n");
179 if(current_asset->index_status == INDEX_NOTTESTED)
181 current_asset->index_status = INDEX_READY;
182 if(mwindow->gui) mwindow->gui->lock_window("MainIndexes::run 2");
183 mwindow->edl->set_index_file(current_asset);
184 if(mwindow->gui) mwindow->gui->unlock_window();
186 indexfile->close_index();
190 //printf("MainIndexes::run 8\n");
192 //printf("MainIndexes::run 9\n");
195 if(progress) // progress box is only created when an index is built
197 if(mwindow->gui) mwindow->gui->lock_window("MainIndexes::run 3");
198 progress->stop_progress();
200 if(mwindow->gui) mwindow->gui->unlock_window();
209 interrupt_lock->unlock();