<commit_before># -*- coding: utf-8 -*-
#
# Copyright (c) 2017 <NAME> <<EMAIL>>

# This file is part of TimeSide.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Author: <NAME> <<EMAIL>>

from timeside.core import implements, interfacedoc
from timeside.core.analyzer import Analyzer
from timeside.core.api import IAnalyzer
from timeside.core.tools.parameters import HasTraits, List
from timeside.core.preprocessors import downmix_to_mono, frames_adapter

import numpy as np
from timeside.core.tools.parameters import store_parameters

import vamp
import vampyhost


class VampTuning(Analyzer):

    """Tuning from NNLS Chroma vamp plugins"""

    implements(IAnalyzer)

    class _Param(HasTraits):
        plugin_list = List

    _schema = {'$schema': 'http://json-schema.org/schema#',
               'properties': {},
               'type': 'object'}

    @store_parameters
    def __init__(self):
        super(VampTuning, self).__init__()

    @interfacedoc
    def setup(self, channels=None, samplerate=None,
              blocksize=None, totalframes=None):
        super(VampTuning, self).setup(
            channels, samplerate, blocksize, totalframes)

        self.plugin_key = 'nnls-chroma:tuning'
        self.plugin_output = 'tuning'
        
        self.plugin = vampyhost.load_plugin(self.plugin_key, float(self.input_samplerate),
                                   vampyhost.ADAPT_INPUT_DOMAIN +
                                   vampyhost.ADAPT_BUFFER_SIZE +
                                   vampyhost.ADAPT_CHANNEL_COUNT)

        self.frame_index = 0
        self.out_index = self.plugin.get_output(self.plugin_output)["output_index"]

        if not self.plugin.initialise(self.input_channels, self.input_stepsize, self.input_blocksize):
            raise "Failed to initialise plugin"

    @staticmethod
    @interfacedoc
    def id():
        return "vamp_tuning"

    @staticmethod
    @interfacedoc
    def name():
        return "Tuning from NNLS Chroma Vamp plugin"

    @staticmethod
    @interfacedoc
    def unit():
        return ""

    @frames_adapter
    def process(self, frames, eod=False):
        timestamp = vampyhost.frame_to_realtime(self.frame_index, self.input_samplerate)
        
        self.plugin.process_block(frames.T, timestamp)
        # results is a dict mapping output number -> list of feature dicts
        #if out_index in results:
        #    for r in results[out_index]:
                
        self.frame_index += self.input_stepsize
        return frames, eod

    def post_process(self):
        results = self.plugin.get_remaining_features()[self.out_index][0]
        self.plugin.unload()
        tuning = self.new_result(data_mode='value', time_mode='global')
        tuning.data_object.value = results['values'][0]
        self.add_result(tuning)

        <commit_msg>Clean-up vamp_tuning.py<commit_after># -*- coding: utf-8 -*-
#
# Copyright (c) 2017 <NAME> <<EMAIL>>

# This file is part of TimeSide.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Author: <NAME> <<EMAIL>>

from timeside.core import implements, interfacedoc
from timeside.core.analyzer import Analyzer
from timeside.core.api import IAnalyzer
from timeside.core.tools.parameters import HasTraits, List
from timeside.core.preprocessors import downmix_to_mono, frames_adapter

import numpy as np
from timeside.core.tools.parameters import store_parameters

import vamp
import vampyhost


class VampTuning(Analyzer):

    """Tuning from NNLS Chroma vamp plugins"""

    implements(IAnalyzer)

    class _Param(HasTraits):
        plugin_list = List

    _schema = {'$schema': 'http://json-schema.org/schema#',
               'properties': {},
               'type': 'object'}

    @store_parameters
    def __init__(self):
        super(VampTuning, self).__init__()

    @interfacedoc
    def setup(self, channels=None, samplerate=None,
              blocksize=None, totalframes=None):
        super(VampTuning, self).setup(
            channels, samplerate, blocksize, totalframes)

        self.plugin_key = 'nnls-chroma:tuning'
        self.plugin_output = 'tuning'
        
        self.plugin = vampyhost.load_plugin(self.plugin_key, float(self.input_samplerate),
                                   vampyhost.ADAPT_INPUT_DOMAIN +
                                   vampyhost.ADAPT_BUFFER_SIZE +
                                   vampyhost.ADAPT_CHANNEL_COUNT)

        self.frame_index = 0
        self.out_index = self.plugin.get_output(self.plugin_output)["output_index"]

        if not self.plugin.initialise(self.input_channels, self.input_stepsize, self.input_blocksize):
            raise "Failed to initialise plugin"

    @staticmethod
    @interfacedoc
    def id():
        return "vamp_tuning"

    @staticmethod
    @interfacedoc
    def name():
        return "Vamp Tuning from NNLS Chroma Vamp plugin"

    @staticmethod
    @interfacedoc
    def unit():
        return ""

    @frames_adapter
    def process(self, frames, eod=False):
        timestamp = vampyhost.frame_to_realtime(self.frame_index, self.input_samplerate)
        
        self.plugin.process_block(frames.T, timestamp)
        # results is a dict mapping output number -> list of feature dicts
        #if out_index in results:
        #    for r in results[out_index]:
                
        self.frame_index += self.input_stepsize
        return frames, eod

    def post_process(self):
        results = self.plugin.get_remaining_features()[self.out_index][0]
        self.plugin.unload()
        tuning = self.new_result(data_mode='value', time_mode='global')
        tuning.data_object.value = results['values'][0]
        self.add_result(tuning)

        
{'fraction_non_alphanumeric': 0.08744751701172723, 'fraction_numerical': 0.002606051831475315, 'mean_word_length': 2.7810618500273674, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '820645', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1962, 'n_words': 566}