boblsturm@0: function controller(action, handles) boblsturm@0: boblsturm@0: switch action boblsturm@0: case 'openTarget' boblsturm@0: [filename pathname] = uigetfile({'*.wav;*.mp3;'}, 'File Selector'); boblsturm@0: targetpathname= strcat(pathname, filename); boblsturm@0: handles.Sound_target = Sound(targetpathname); boblsturm@0: set(handles.txt_targetfile, 'String', filename); boblsturm@0: set(handles.txt_targetfile,'TooltipString',filename); boblsturm@0: case 'openSource' boblsturm@0: [filenames pathname]= uigetfile({'*.wav;*.mp3;'}, 'File Selector', 'MultiSelect','on'); boblsturm@0: boblsturm@0: if( iscell( filenames ) ) boblsturm@0: for i = 1:length( filenames ) boblsturm@0: sourcepathname = strcat(pathname, filenames{i}); boblsturm@0: tmp_snd = Sound(sourcepathname); boblsturm@0: if isfield(handles, 'Sound_corpus') boblsturm@0: handles.Sound_corpus = handles.Sound_corpus.concat( tmp_snd ); boblsturm@0: else boblsturm@0: handles.Sound_corpus = tmp_snd; boblsturm@0: end boblsturm@0: end boblsturm@0: boblsturm@0: cat_files = strjoin(filenames,'\n'); boblsturm@0: set(handles.txt_corpusfile, 'String', cat_files); boblsturm@0: set(handles.txt_corpusfile,'TooltipString', char(cat_files)); boblsturm@0: else boblsturm@0: sourcepathname = strcat(pathname, filenames); boblsturm@0: handles.Sound_corpus = Sound(sourcepathname); boblsturm@0: set(handles.txt_corpusfile, 'String', filenames); boblsturm@0: set(handles.txt_corpusfile,'TooltipString', filenames); boblsturm@0: end boblsturm@0: boblsturm@0: case 'swapSourceAndTarget' boblsturm@0: tmp = handles.Sound_target; boblsturm@0: handles.Sound_target = handles.Sound_corpus; boblsturm@0: handles.Sound_corpus = tmp; boblsturm@0: boblsturm@0: corpus_displayName = get( handles.txt_corpusfile, 'String' ); boblsturm@0: corpus_tooltip = get( handles.txt_corpusfile, 'TooltipString' ); boblsturm@0: target_displayName = get( handles.txt_targetfile, 'String' ); boblsturm@0: target_tooltip = get( handles.txt_targetfile, 'TooltipString' ); boblsturm@0: boblsturm@0: set(handles.txt_targetfile, 'String', corpus_displayName); boblsturm@0: set(handles.txt_targetfile,'TooltipString', corpus_tooltip); boblsturm@0: set(handles.txt_corpusfile, 'String', target_displayName); boblsturm@0: set(handles.txt_corpusfile,'TooltipString', target_tooltip); boblsturm@0: case 'playTarget' boblsturm@0: handles.Sound_target.control_audio('play'); boblsturm@0: case 'stopTarget' boblsturm@0: handles.Sound_target.control_audio('stop'); boblsturm@0: case 'playSynthesis' boblsturm@0: handles.Sound_synthesis.control_audio('play'); boblsturm@0: case 'stopSynthesis' boblsturm@0: handles.Sound_synthesis.control_audio('stop'); boblsturm@0: case 'runAnalysis' boblsturm@0: waitbarHandle = waitbar(0.15, 'Verifying parameters...'); boblsturm@0: spectTypeSelected=get(handles.pop_specttype, 'Value'); boblsturm@0: spectTypes=get(handles.pop_specttype, 'String'); boblsturm@0: boblsturm@0: winTypeSelected=get(handles.pop_wintype, 'Value'); boblsturm@0: winTypes=get(handles.pop_wintype, 'String'); boblsturm@0: boblsturm@0: win.Length = str2num(get(handles.edt_winlen, 'String'))*44100/1000; boblsturm@0: win.Hop = str2num(get(handles.edt_overlap, 'String'))*44100/1000; boblsturm@0: win.Type = cell2mat(winTypes(winTypeSelected)); boblsturm@0: boblsturm@0: CacheObj = AnalysisCache(handles.Sound_corpus.Signal, handles.Sound_target.Signal, ... boblsturm@0: winTypeSelected, win.Length, win.Hop); boblsturm@0: handles.CurrentAnalysisCache = CacheObj; boblsturm@0: if( strcmp(get(handles.tool_menu_dev_cacheEnable, 'Checked'), 'on') ) boblsturm@0: waitbar(0.33, waitbarHandle,'Checking cache...'); boblsturm@0: boblsturm@0: GenerateHash(CacheObj); boblsturm@0: Cached = ExistsInCache(CacheObj.Hash, handles, 'Analysis'); boblsturm@0: boblsturm@0: if( ~Cached ) boblsturm@0: waitbar(0.66, waitbarHandle, 'Analyzing corpus...') boblsturm@0: handles.Sound_corpus.computeFeatures(win, spectTypes(spectTypeSelected)); boblsturm@0: boblsturm@0: waitbar(0.95, waitbarHandle, 'Analyzing target...') boblsturm@0: handles.Sound_target.computeFeatures(win, spectTypes(spectTypeSelected)); boblsturm@0: boblsturm@0: waitbar(0.98, waitbarHandle, 'Saving in cache...') boblsturm@0: boblsturm@0: DataToCache = struct( ... boblsturm@0: 'Corpus', handles.Sound_corpus, ... boblsturm@0: 'Target', handles.Sound_target ... boblsturm@0: ); boblsturm@0: handles.Cache = SaveInCache( CacheObj, handles, 'Analysis', DataToCache ); boblsturm@0: else boblsturm@0: waitbar(0.75, waitbarHandle, 'Hooray, exists in cache! Loading...') boblsturm@0: FromCache = LoadFromCache( CacheObj.Hash, 'Analysis' ); boblsturm@0: handles.Sound_corpus = FromCache.Corpus; boblsturm@0: handles.Sound_target = FromCache.Target; boblsturm@0: end boblsturm@0: else boblsturm@0: waitbar(0.66, waitbarHandle, 'Analyzing corpus...') boblsturm@0: handles.Sound_corpus.computeFeatures(win, spectTypes(spectTypeSelected)); boblsturm@0: boblsturm@0: waitbar(0.95, waitbarHandle, 'Analyzing target...') boblsturm@0: handles.Sound_target.computeFeatures(win, spectTypes(spectTypeSelected)); boblsturm@0: end boblsturm@0: close(waitbarHandle); boblsturm@0: case 'runSynthesis' boblsturm@0: waitbarHandle = waitbar(0.15, 'Checking cache...'); boblsturm@0: costMetricSelected=get(handles.pop_cost, 'Value'); boblsturm@0: costMetrics=get(handles.pop_cost, 'String'); boblsturm@0: boblsturm@0: actPatternSelected=get(handles.pop_pattern, 'Value'); boblsturm@0: actPatterns=get(handles.pop_pattern, 'String'); boblsturm@0: boblsturm@0: nmf_params.Algorithm = cell2mat(costMetrics(costMetricSelected)); boblsturm@0: nmf_params.Iterations = str2num(get(handles.edt_iter, 'String')); boblsturm@0: nmf_params.Convergence_criteria = str2double(get(handles.edt_conv, 'String')); boblsturm@0: nmf_params.Repition_restriction = str2double(get(handles.edt_mod_rep, 'String')); boblsturm@0: nmf_params.Polyphony_restriction = str2double(get(handles.edt_mod_poly, 'String')); boblsturm@0: nmf_params.Continuity_enhancement = str2double(get(handles.edt_mod_cont, 'String')); boblsturm@0: nmf_params.Continuity_enhancement_rot = str2double(get(handles.edt_mod_cont_rot, 'String')); boblsturm@0: nmf_params.Diagonal_pattern = cell2mat(actPatterns(actPatternSelected)); boblsturm@0: nmf_params.Modification_application = get(handles.chk_endtime, 'Value'); boblsturm@0: nmf_params.Random_seed = str2double(get(handles.edt_rand, 'String')); boblsturm@0: nmf_params.Lambda = str2double(get(handles.edt_sparse_lambda, 'String')); boblsturm@0: boblsturm@0: resynthMethodSelected=get(handles.pop_synthmethod, 'Value'); boblsturm@0: resynthMethods=get(handles.pop_synthmethod, 'String'); boblsturm@0: boblsturm@0: pct_prune = ( 100 - str2double(get(handles.edt_prune, 'String')) )/100; boblsturm@0: synth = CSS(nmf_params, cell2mat(resynthMethods(resynthMethodSelected))); boblsturm@0: boblsturm@0: % Cache related operations boblsturm@0: % if( strcmp(get(handles.tool_menu_dev_cacheEnable, 'Checked'), 'on') ) boblsturm@0: GenerateHash(handles.CurrentAnalysisCache); boblsturm@0: CacheObj = SynthesisCache( ... boblsturm@0: nmf_params.Iterations, nmf_params.Random_seed, nmf_params.Convergence_criteria, ... boblsturm@0: costMetricSelected, nmf_params.Repition_restriction, nmf_params.Polyphony_restriction, ... boblsturm@0: nmf_params.Continuity_enhancement, actPatternSelected, nmf_params.Continuity_enhancement_rot, ... boblsturm@0: nmf_params.Modification_application, nmf_params.Lambda, pct_prune, handles.CurrentAnalysisCache.Hash ); boblsturm@0: boblsturm@0: GenerateHash(CacheObj); boblsturm@0: Cached = ExistsInCache(CacheObj.Hash, handles, 'Synthesis'); boblsturm@0: disp( CacheObj.Hash ); boblsturm@0: boblsturm@0: if( ~Cached ) boblsturm@0: waitbar(0.5, waitbarHandle, 'Not found in cache. Running NMF...') boblsturm@0: synth.nmf(handles.Sound_corpus, handles.Sound_target, pct_prune); boblsturm@0: boblsturm@0: waitbar(0.75, waitbarHandle, 'Saving in cache...') boblsturm@0: DataToCache = struct( ... boblsturm@0: 'Activations', synth.Activations, ... boblsturm@0: 'Cost', synth.Cost ... boblsturm@0: ); boblsturm@0: boblsturm@0: handles.Cache = SaveInCache( CacheObj, handles, 'Synthesis', DataToCache ); boblsturm@0: else boblsturm@0: waitbar(0.75, waitbarHandle, 'Hooray, exists in cache! Loading...') boblsturm@0: FromCache = LoadFromCache( CacheObj.Hash, 'Synthesis' ); boblsturm@0: synth.Activations = FromCache.Activations; boblsturm@0: synth.Cost = FromCache.Cost; boblsturm@0: end boblsturm@0: % else boblsturm@0: % synth.nmf(handles.Sound_corpus, handles.Sound_target); boblsturm@0: % end boblsturm@0: boblsturm@0: synth.synthesize(handles.Sound_corpus); boblsturm@0: boblsturm@0: winTypeSelected=get(handles.pop_wintype, 'Value'); boblsturm@0: winTypes=get(handles.pop_wintype, 'String'); boblsturm@0: boblsturm@0: win.Length = str2num(get(handles.edt_winlen, 'String'))*44100/1000; boblsturm@0: win.Hop = str2num(get(handles.edt_overlap, 'String'))*44100/1000; boblsturm@0: win.Type = cell2mat(winTypes(winTypeSelected)); boblsturm@0: boblsturm@0: spectTypeSelected=get(handles.pop_specttype, 'Value'); boblsturm@0: spectTypes=get(handles.pop_specttype, 'String'); boblsturm@0: boblsturm@0: handles.SynthesisObject = synth; boblsturm@0: handles.Sound_synthesis = Sound(synth.Synthesis, handles.Sound_corpus.Sampling_rate); boblsturm@0: handles.Sound_synthesis.computeFeatures(win, spectTypes(spectTypeSelected)); boblsturm@0: boblsturm@0: close(waitbarHandle); boblsturm@0: case 'savePlot' boblsturm@0: case 'exportResynth' boblsturm@0: case 'switchPlot' boblsturm@0: selectedPlot=get(handles.pop_plot, 'Value'); boblsturm@0: plotOptions=get(handles.pop_plot, 'String'); boblsturm@0: delete(handles.axes2.Children); boblsturm@0: cla(gca,'reset') boblsturm@0: plotRequest = plotOptions(selectedPlot); boblsturm@0: switch(plotRequest{1}) boblsturm@0: case 'Synthesis Plot' boblsturm@0: view(gca, 2); boblsturm@0: handles.Sound_synthesis.plot_signal; boblsturm@0: set(handles.tbl_plotdata, 'Data', handles.Sound_synthesis.Signal'); boblsturm@0: case 'Cost' boblsturm@0: view(gca, 2); boblsturm@0: handles.SynthesisObject.plot_cost; boblsturm@0: set(handles.tbl_plotdata, 'Data', handles.SynthesisObject.Cost'); boblsturm@0: case 'Activations' boblsturm@0: view(gca, 2); boblsturm@0: handles.SynthesisObject.plot_activations(get(handles.sld_maxdb, 'Value')); boblsturm@0: set(handles.tbl_plotdata, 'Data', handles.SynthesisObject.Activations); boblsturm@0: case 'Corpus Spectrogram' boblsturm@0: view(gca, 2); boblsturm@0: handles.Sound_corpus.plot_spectrogram; boblsturm@0: set(handles.tbl_plotdata, 'Data', abs(handles.Sound_corpus.Features.STFT.S)); boblsturm@0: case 'Target Spectrogram' boblsturm@0: view(gca, 2); boblsturm@0: handles.Sound_target.plot_spectrogram; boblsturm@0: set(handles.tbl_plotdata, 'Data', abs(handles.Sound_target.Features.STFT.S)); boblsturm@0: case 'Synthesis Spectrogram' boblsturm@0: view(gca, 2); boblsturm@0: handles.Sound_synthesis.plot_spectrogram; boblsturm@0: set(handles.tbl_plotdata, 'Data', abs(handles.Sound_synthesis.Features.STFT.S)); boblsturm@0: case 'Templates' boblsturm@0: view(gca, 3); boblsturm@0: handles.Sound_corpus.plot_templates; boblsturm@0: set(handles.tbl_plotdata, 'Data', abs(handles.Sound_corpus.Features.STFT.S)); boblsturm@0: end boblsturm@0: case 'resynthesize' boblsturm@0: synth = handles.SynthesisObject; boblsturm@0: synth.synthesize(handles.Sound_corpus); boblsturm@0: handles.SynthesisObject = synth; boblsturm@0: handles.Sound_synthesis.Audioplayer = audioplayer(handles.SynthesisObject.Synthesis, handles.Sound_corpus.Sampling_rate); boblsturm@0: case 'rerun' boblsturm@0: resynthMethodSelected=get(handles.pop_synthmethod, 'Value'); boblsturm@0: resynthMethods=get(handles.pop_synthmethod, 'String'); boblsturm@0: nmf_params = handles.SynthesisObject.NMF_features; boblsturm@0: boblsturm@0: pct_prune = ( 100 - str2double(get(handles.edt_prune, 'String')) )/100; boblsturm@0: synth = CSS(nmf_params, cell2mat(resynthMethods(resynthMethodSelected))); boblsturm@0: synth.nmf(handles.Sound_corpus, handles.Sound_target, pct_prune); boblsturm@0: synth.synthesize(handles.Sound_corpus); boblsturm@0: boblsturm@0: handles.SynthesisObject = synth; boblsturm@0: end boblsturm@0: boblsturm@0: guidata(handles.figure1, handles); boblsturm@0: end