Mercurial > hg > camir-aes2014
comparison core/magnatagatune/Clip.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 % --- | |
2 % This is the class for magnatagatune clips | |
3 % --- | |
4 | |
5 classdef Clip < handle | |
6 | |
7 % --- | |
8 % here come the internal clip properties. | |
9 % the database is stored as a global variable | |
10 % --- | |
11 properties (SetAccess = private) | |
12 | |
13 % magnatagatune clip id | |
14 my_id; | |
15 end | |
16 | |
17 % do not save whole db into mat file | |
18 properties (Hidden, Transient) | |
19 | |
20 my_db; | |
21 end | |
22 | |
23 properties (Hidden) | |
24 | |
25 my_dbpos; | |
26 end | |
27 | |
28 % --- | |
29 % here come the clip functions. | |
30 % --- | |
31 methods | |
32 | |
33 % --- | |
34 % simple constructor | |
35 % --- | |
36 function clip = Clip(varargin) | |
37 | |
38 % usual or empty constructor ? | |
39 if (nargin > 0) && isnumeric(varargin{1}) | |
40 id = varargin{1}; | |
41 db_type = varargin{2}; | |
42 | |
43 % --- | |
44 % check for magnatagatunedatabase | |
45 % and load it if not present | |
46 % --- | |
47 evalc(sprintf('global %s;',db_type)); | |
48 evalc(sprintf('thisdb = %s;',db_type)); | |
49 | |
50 if ~isempty(thisdb)% exist('clip_info_proper') | |
51 clip.my_db = thisdb; | |
52 else | |
53 | |
54 error 'db not found'; | |
55 % dbload; | |
56 end | |
57 | |
58 % --- | |
59 % recursive call for creating multiple clips | |
60 % --- | |
61 if numel(id) > 1 | |
62 | |
63 % multi-id case | |
64 | |
65 % --- | |
66 % @todo: use class names as db names | |
67 % --- | |
68 if strcmp(db_type,'db_MTTClip') | |
69 clip = MTTClip(); | |
70 for i = 1:numel(id) | |
71 clip(i) = MTTClip(id(i)); | |
72 end | |
73 elseif strcmp(db_type,'db_MSDClip') | |
74 clip = MSDClip(); | |
75 for i = 1:numel(id) | |
76 clip(i) = MSDClip(id(i)); | |
77 end | |
78 elseif strcmp(db_type,'db_CASIMIRClip') | |
79 clip = CASIMIRClip(); | |
80 for i = 1:numel(id) | |
81 clip(i) = CASIMIRClip(id(i)); | |
82 end | |
83 end | |
84 | |
85 | |
86 elseif ~isempty(id) | |
87 % --- | |
88 % actual constructor | |
89 % --- | |
90 clip.my_id = id; | |
91 clip.my_dbpos = clip.dbpos(); | |
92 | |
93 if isempty(clip.my_dbpos) | |
94 error ('Clip %d not found in DB', full(id)) | |
95 end | |
96 end | |
97 else | |
98 | |
99 % --- | |
100 % TODO: deal with empty constructor | |
101 % --- | |
102 end | |
103 end | |
104 | |
105 % --- | |
106 % member functions | |
107 % --- | |
108 | |
109 % returns the id (function neccessary for | |
110 % multi-clip environments) | |
111 function out = id(this) | |
112 | |
113 out = [this.my_id]; | |
114 end | |
115 | |
116 function out = comparison_id(this) | |
117 | |
118 out = [this(1).my_db.comparison_ids(this)]; | |
119 end | |
120 | |
121 function out = title(this) | |
122 % returns name strings for given genre position ids | |
123 | |
124 out = this.my_db.clip_info_proper{this.my_dbpos,3}; | |
125 end | |
126 | |
127 function out = album(this) | |
128 % returns name strings for given genre position ids | |
129 | |
130 out = this.my_db.clip_info_proper{this.my_dbpos,5}; | |
131 end | |
132 | |
133 function out = artist(this) | |
134 % returns name strings for given genre position ids | |
135 | |
136 out = this(1).my_db.artistdb.annots(this.id); | |
137 out = out{1}; | |
138 end | |
139 | |
140 function out = artist_id(this) | |
141 % returns name strings for given genre position ids | |
142 | |
143 out = this(1).my_db.artistdb.annotids_for_owner(this.id); | |
144 end | |
145 | |
146 function my_tag_ids = tag_ids(this) | |
147 % returns clip tag posids for given clip id | |
148 | |
149 my_tag_ids = this.my_db.tagdb.annotids_for_owner(this.id); | |
150 end | |
151 | |
152 function out = tags(this) | |
153 % returns name strings for given genre position ids | |
154 | |
155 out = this.my_db.tagdb.annots(this.id); | |
156 end | |
157 | |
158 | |
159 % this is for ocompability with | |
160 function out = raw_annots(this) | |
161 | |
162 out = this.my_db.clip_info_proper(this.my_dbpos,:); | |
163 end | |
164 | |
165 function [out] = isrc(this) | |
166 % returns name strings for given genre position ids | |
167 out = this(1).my_db.clip_info_proper{this.my_dbpos,11}; | |
168 end | |
169 | |
170 function [out] = artist_mbid(this) | |
171 % returns name strings for given genre position ids | |
172 out = this(1).my_db.clip_info_proper{this.my_dbpos,12}; | |
173 end | |
174 | |
175 function [out] = mbtags(this) | |
176 % returns nmusicbrainz tags for the artist related to this clip | |
177 | |
178 [out, score] = this(1).my_db.mbtagdb.annots(this(1).artist_id()); | |
179 end | |
180 | |
181 % @todo: generalise mg tags | |
182 function [out, score] = mbtag_ids(this) | |
183 | |
184 [out, score] = this(1).my_db.mbtagdb.annotids_for_owner(this(1).artist_id()); | |
185 end | |
186 | |
187 | |
188 function len = play(clips, plen) | |
189 % len = play(clips) | |
190 % | |
191 % plays magnatune clip given by clip id, and | |
192 % returns full playback length | |
193 | |
194 if nargin <2 | |
195 plen = 0; %seconds play | |
196 end | |
197 | |
198 len = 0; | |
199 for i = 1:numel(clips) | |
200 | |
201 % get sample rate | |
202 [null,sr] = mp3read(clips(i).mp3file_full(),0); | |
203 | |
204 if plen > 0 | |
205 | |
206 % read mp3 file | |
207 [src,sr,NBITS,OPTS] = mp3read(clips(i).mp3file_full(), plen*sr); | |
208 else | |
209 % read full mp3 file | |
210 [src,sr,NBITS,OPTS] = mp3read(clips(i).mp3file_full()); | |
211 end | |
212 | |
213 % --- | |
214 % NOTE: sound() seems to pause the system when trying to | |
215 % play a clip while still playing another one | |
216 % --- | |
217 sound(src,sr); | |
218 | |
219 fprintf('\n--- now playing ---\n'); | |
220 clips(i).print(); | |
221 | |
222 % add clip lengths | |
223 len = len + length(src) / sr; | |
224 end | |
225 end | |
226 | |
227 function skip(clips) | |
228 % skips through given clips | |
229 | |
230 clips.play(5); | |
231 end | |
232 | |
233 function out = dbpos(this) | |
234 % returns matrix position for given clip id | |
235 | |
236 out = find(this.my_db.annots_ids == this.id, 1 ,'first'); | |
237 end | |
238 | |
239 % --- | |
240 % Generic Features | |
241 % --- | |
242 function feature = features(clip, type, varargin) | |
243 % feature = features(clip, type, varargin) | |
244 % | |
245 % returns the features of type "type" for given clips and | |
246 % parameters | |
247 % e.g. feature = clip.features('MTTAudioFeatureRAW') | |
248 | |
249 db_name = MTTAudioFeatureDBgen.db_name(type); | |
250 | |
251 % global database | |
252 eval( sprintf( 'global %s;', db_name)); | |
253 | |
254 % create database if neccesary | |
255 if eval(sprintf('isempty(%s);', db_name)); | |
256 | |
257 eval(sprintf('%s = MTTAudioFeatureDBgen(''%s'');', db_name, type)); | |
258 end | |
259 | |
260 % retrieve features from db | |
261 feature = eval(sprintf('%s.get_features(clip, varargin{:});', db_name)); | |
262 end | |
263 | |
264 % --- | |
265 % Audio Features Section | |
266 % --- | |
267 function features = audio_features_raw(clip) | |
268 % get the features from the global database | |
269 | |
270 features = clip.features('MTTAudioFeatureRAW'); | |
271 end | |
272 | |
273 function features = audio_features_basicsm(clip, varargin) | |
274 % get the features from the global database | |
275 | |
276 features = clip.features('MTTAudioFeatureBasicSm', varargin{:}); | |
277 end | |
278 | |
279 function features = genre_features_basic(clip, varargin) | |
280 % get the features from the global database | |
281 | |
282 features = clip.features('MTTTagFeatureGenreBasic', varargin{:}); | |
283 | |
284 end | |
285 | |
286 function features = mixed_features_genrebasicsm(clip, varargin) | |
287 % get the features from the global database | |
288 | |
289 features = clip.features('MTTMixedFeatureGenreBasicSm', varargin{:}); | |
290 end | |
291 | |
292 function features = mixed_features_genrebasicsm_pca(clip, varargin) | |
293 % get the features from the global database | |
294 | |
295 features = clip.features('MTTMixedFeatureGenreBasicSmPCA', varargin{:}); | |
296 end | |
297 | |
298 function features = random_features(clip, varargin) | |
299 % get the features from the global database | |
300 | |
301 features = clip.features('MTTRandomFeature', varargin{:}); | |
302 end | |
303 | |
304 end | |
305 | |
306 % --- | |
307 % static methods | |
308 % --- | |
309 methods(Static = true) | |
310 | |
311 end | |
312 end |