wolffd@0: % --- wolffd@0: % This is the class for magnatagatune clips wolffd@0: % --- wolffd@0: wolffd@0: classdef Clip < handle wolffd@0: wolffd@0: % --- wolffd@0: % here come the internal clip properties. wolffd@0: % the database is stored as a global variable wolffd@0: % --- wolffd@0: properties (SetAccess = private) wolffd@0: wolffd@0: % magnatagatune clip id wolffd@0: my_id; wolffd@0: end wolffd@0: wolffd@0: % do not save whole db into mat file wolffd@0: properties (Hidden, Transient) wolffd@0: wolffd@0: my_db; wolffd@0: end wolffd@0: wolffd@0: properties (Hidden) wolffd@0: wolffd@0: my_dbpos; wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % here come the clip functions. wolffd@0: % --- wolffd@0: methods wolffd@0: wolffd@0: % --- wolffd@0: % simple constructor wolffd@0: % --- wolffd@0: function clip = Clip(varargin) wolffd@0: wolffd@0: % usual or empty constructor ? wolffd@0: if (nargin > 0) && isnumeric(varargin{1}) wolffd@0: id = varargin{1}; wolffd@0: db_type = varargin{2}; wolffd@0: wolffd@0: % --- wolffd@0: % check for magnatagatunedatabase wolffd@0: % and load it if not present wolffd@0: % --- wolffd@0: evalc(sprintf('global %s;',db_type)); wolffd@0: evalc(sprintf('thisdb = %s;',db_type)); wolffd@0: wolffd@0: if ~isempty(thisdb)% exist('clip_info_proper') wolffd@0: clip.my_db = thisdb; wolffd@0: else wolffd@0: wolffd@0: error 'db not found'; wolffd@0: % dbload; wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % recursive call for creating multiple clips wolffd@0: % --- wolffd@0: if numel(id) > 1 wolffd@0: wolffd@0: % multi-id case wolffd@0: wolffd@0: % --- wolffd@0: % @todo: use class names as db names wolffd@0: % --- wolffd@0: if strcmp(db_type,'db_MTTClip') wolffd@0: clip = MTTClip(); wolffd@0: for i = 1:numel(id) wolffd@0: clip(i) = MTTClip(id(i)); wolffd@0: end wolffd@0: elseif strcmp(db_type,'db_MSDClip') wolffd@0: clip = MSDClip(); wolffd@0: for i = 1:numel(id) wolffd@0: clip(i) = MSDClip(id(i)); wolffd@0: end wolffd@0: elseif strcmp(db_type,'db_CASIMIRClip') wolffd@0: clip = CASIMIRClip(); wolffd@0: for i = 1:numel(id) wolffd@0: clip(i) = CASIMIRClip(id(i)); wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: wolffd@0: elseif ~isempty(id) wolffd@0: % --- wolffd@0: % actual constructor wolffd@0: % --- wolffd@0: clip.my_id = id; wolffd@0: clip.my_dbpos = clip.dbpos(); wolffd@0: wolffd@0: if isempty(clip.my_dbpos) wolffd@0: error ('Clip %d not found in DB', full(id)) wolffd@0: end wolffd@0: end wolffd@0: else wolffd@0: wolffd@0: % --- wolffd@0: % TODO: deal with empty constructor wolffd@0: % --- wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % member functions wolffd@0: % --- wolffd@0: wolffd@0: % returns the id (function neccessary for wolffd@0: % multi-clip environments) wolffd@0: function out = id(this) wolffd@0: wolffd@0: out = [this.my_id]; wolffd@0: end wolffd@0: wolffd@0: function out = comparison_id(this) wolffd@0: wolffd@0: out = [this(1).my_db.comparison_ids(this)]; wolffd@0: end wolffd@0: wolffd@0: function out = title(this) wolffd@0: % returns name strings for given genre position ids wolffd@0: wolffd@0: out = this.my_db.clip_info_proper{this.my_dbpos,3}; wolffd@0: end wolffd@0: wolffd@0: function out = album(this) wolffd@0: % returns name strings for given genre position ids wolffd@0: wolffd@0: out = this.my_db.clip_info_proper{this.my_dbpos,5}; wolffd@0: end wolffd@0: wolffd@0: function out = artist(this) wolffd@0: % returns name strings for given genre position ids wolffd@0: wolffd@0: out = this(1).my_db.artistdb.annots(this.id); wolffd@0: out = out{1}; wolffd@0: end wolffd@0: wolffd@0: function out = artist_id(this) wolffd@0: % returns name strings for given genre position ids wolffd@0: wolffd@0: out = this(1).my_db.artistdb.annotids_for_owner(this.id); wolffd@0: end wolffd@0: wolffd@0: function my_tag_ids = tag_ids(this) wolffd@0: % returns clip tag posids for given clip id wolffd@0: wolffd@0: my_tag_ids = this.my_db.tagdb.annotids_for_owner(this.id); wolffd@0: end wolffd@0: wolffd@0: function out = tags(this) wolffd@0: % returns name strings for given genre position ids wolffd@0: wolffd@0: out = this.my_db.tagdb.annots(this.id); wolffd@0: end wolffd@0: wolffd@0: wolffd@0: % this is for ocompability with wolffd@0: function out = raw_annots(this) wolffd@0: wolffd@0: out = this.my_db.clip_info_proper(this.my_dbpos,:); wolffd@0: end wolffd@0: wolffd@0: function [out] = isrc(this) wolffd@0: % returns name strings for given genre position ids wolffd@0: out = this(1).my_db.clip_info_proper{this.my_dbpos,11}; wolffd@0: end wolffd@0: wolffd@0: function [out] = artist_mbid(this) wolffd@0: % returns name strings for given genre position ids wolffd@0: out = this(1).my_db.clip_info_proper{this.my_dbpos,12}; wolffd@0: end wolffd@0: wolffd@0: function [out] = mbtags(this) wolffd@0: % returns nmusicbrainz tags for the artist related to this clip wolffd@0: wolffd@0: [out, score] = this(1).my_db.mbtagdb.annots(this(1).artist_id()); wolffd@0: end wolffd@0: wolffd@0: % @todo: generalise mg tags wolffd@0: function [out, score] = mbtag_ids(this) wolffd@0: wolffd@0: [out, score] = this(1).my_db.mbtagdb.annotids_for_owner(this(1).artist_id()); wolffd@0: end wolffd@0: wolffd@0: wolffd@0: function len = play(clips, plen) wolffd@0: % len = play(clips) wolffd@0: % wolffd@0: % plays magnatune clip given by clip id, and wolffd@0: % returns full playback length wolffd@0: wolffd@0: if nargin <2 wolffd@0: plen = 0; %seconds play wolffd@0: end wolffd@0: wolffd@0: len = 0; wolffd@0: for i = 1:numel(clips) wolffd@0: wolffd@0: % get sample rate wolffd@0: [null,sr] = mp3read(clips(i).mp3file_full(),0); wolffd@0: wolffd@0: if plen > 0 wolffd@0: wolffd@0: % read mp3 file wolffd@0: [src,sr,NBITS,OPTS] = mp3read(clips(i).mp3file_full(), plen*sr); wolffd@0: else wolffd@0: % read full mp3 file wolffd@0: [src,sr,NBITS,OPTS] = mp3read(clips(i).mp3file_full()); wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % NOTE: sound() seems to pause the system when trying to wolffd@0: % play a clip while still playing another one wolffd@0: % --- wolffd@0: sound(src,sr); wolffd@0: wolffd@0: fprintf('\n--- now playing ---\n'); wolffd@0: clips(i).print(); wolffd@0: wolffd@0: % add clip lengths wolffd@0: len = len + length(src) / sr; wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: function skip(clips) wolffd@0: % skips through given clips wolffd@0: wolffd@0: clips.play(5); wolffd@0: end wolffd@0: wolffd@0: function out = dbpos(this) wolffd@0: % returns matrix position for given clip id wolffd@0: wolffd@0: out = find(this.my_db.annots_ids == this.id, 1 ,'first'); wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % Generic Features wolffd@0: % --- wolffd@0: function feature = features(clip, type, varargin) wolffd@0: % feature = features(clip, type, varargin) wolffd@0: % wolffd@0: % returns the features of type "type" for given clips and wolffd@0: % parameters wolffd@0: % e.g. feature = clip.features('MTTAudioFeatureRAW') wolffd@0: wolffd@0: db_name = MTTAudioFeatureDBgen.db_name(type); wolffd@0: wolffd@0: % global database wolffd@0: eval( sprintf( 'global %s;', db_name)); wolffd@0: wolffd@0: % create database if neccesary wolffd@0: if eval(sprintf('isempty(%s);', db_name)); wolffd@0: wolffd@0: eval(sprintf('%s = MTTAudioFeatureDBgen(''%s'');', db_name, type)); wolffd@0: end wolffd@0: wolffd@0: % retrieve features from db wolffd@0: feature = eval(sprintf('%s.get_features(clip, varargin{:});', db_name)); wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % Audio Features Section wolffd@0: % --- wolffd@0: function features = audio_features_raw(clip) wolffd@0: % get the features from the global database wolffd@0: wolffd@0: features = clip.features('MTTAudioFeatureRAW'); wolffd@0: end wolffd@0: wolffd@0: function features = audio_features_basicsm(clip, varargin) wolffd@0: % get the features from the global database wolffd@0: wolffd@0: features = clip.features('MTTAudioFeatureBasicSm', varargin{:}); wolffd@0: end wolffd@0: wolffd@0: function features = genre_features_basic(clip, varargin) wolffd@0: % get the features from the global database wolffd@0: wolffd@0: features = clip.features('MTTTagFeatureGenreBasic', varargin{:}); wolffd@0: wolffd@0: end wolffd@0: wolffd@0: function features = mixed_features_genrebasicsm(clip, varargin) wolffd@0: % get the features from the global database wolffd@0: wolffd@0: features = clip.features('MTTMixedFeatureGenreBasicSm', varargin{:}); wolffd@0: end wolffd@0: wolffd@0: function features = mixed_features_genrebasicsm_pca(clip, varargin) wolffd@0: % get the features from the global database wolffd@0: wolffd@0: features = clip.features('MTTMixedFeatureGenreBasicSmPCA', varargin{:}); wolffd@0: end wolffd@0: wolffd@0: function features = random_features(clip, varargin) wolffd@0: % get the features from the global database wolffd@0: wolffd@0: features = clip.features('MTTRandomFeature', varargin{:}); wolffd@0: end wolffd@0: wolffd@0: end wolffd@0: wolffd@0: % --- wolffd@0: % static methods wolffd@0: % --- wolffd@0: methods(Static = true) wolffd@0: wolffd@0: end wolffd@0: end