Exemple #1
0
    def test_strings_to_be_played_bad_input(self):
        freqs_in_recording = [-1, -1]

        timing_list = [-1, -1]
        bpm = 95
        notation = Notation(freqs_in_recording, timing_list, bpm)

        strings_to_be_played = notation.get_strings_to_be_played()

        assert len(strings_to_be_played) == 0
Exemple #2
0
    def test_note_durations(self):
        freqs_in_recording = [110.0, 130.81, 146.83, 164.81, 196.0, 220.0]

        timing_list = [2.488072633743286, 3.783242702484131,
                       4.996575832366943, 6.3053059577941895,
                       7.550408363342285, 8.852245330810547]
        bpm = 95
        notation = Notation(freqs_in_recording, timing_list, bpm)
        padded_duration_list = notation.get_padded_duration_list()

        expected_output = ['half', 'half', 'half', 'half', 'half', 'half']
        assert padded_duration_list == expected_output
Exemple #3
0
    def test_strings_to_be_played(self):
        freqs_in_recording = [110.0, 130.81, 146.83, 164.81, 196.0, 220.0]

        timing_list = [2.4904987812042236, 3.736825466156006, 4.915533065795898,
                       4.999251842498779, 6.24546480178833, 6.309228897094727,
                       7.552244663238525, 8.79773235321045, 8.856847763061523]
        bpm = 95
        notation = Notation(freqs_in_recording, timing_list, bpm)

        expected_strings = ["E", "E", "A", "A", "D", "D"]
        strings_to_be_played = notation.get_strings_to_be_played()

        assert expected_strings == strings_to_be_played
Exemple #4
0
    def test_padding_durations(self):
        """
        Six Quarter Notes so it should be padded
        :return:
        """
        freq_list = [110.0, 130.81, 146.83, 164.81, 196.0, 220.0]
        timing_list = [2.511587381362915,
                       3.0793650150299072,
                       3.7543764114379883,
                       4.387029647827148,
                       5.066054344177246,
                       5.673401355743408]

        bpm = 95
        notation = Notation(freq_list, timing_list, bpm)
        padded_duration_list = notation.get_padded_duration_list()

        # 6 quarter notes is six beats. The next bar would be 8 beats so add two beats(half)
        expected_output = ['quarter', 'quarter', 'quarter', 'quarter', 'quarter', 'quarter', 'half']
        assert padded_duration_list == expected_output
Exemple #5
0
def get_lesson_notation(topic, lesson):
    print("Test notation")
    topic_path = "topics/"
    topic += "/"
    file_manager = FileManager(topic_path + topic)

    bpm = file_manager.get_tempo_from_file_name(lesson)

    lesson_file_path = file_manager.get_lesson_path("/" + lesson)

    lesson_analysis = AudioAnalysis(lesson_file_path)

    lesson_note_list, lesson_freq_list = lesson_analysis.analyse_notes()
    lesson_timing_list = lesson_analysis.analyse_timing()

    if int(bpm) < 0:
        return "Error: No tempo present in filename"
    else:

        lesson_notation_creator = Notation(lesson_freq_list, lesson_timing_list, bpm)

        lesson_string_list = lesson_notation_creator.get_strings_to_be_played()
        lesson_fret_list = lesson_notation_creator.get_frets_to_be_played()
        padded_duration_list = lesson_notation_creator.get_padded_duration_list()

        total_beats = lesson_notation_creator.calculate_total_beats(padded_duration_list)

        d = app_utils.create_dictionary(lesson_string_list=lesson_string_list, lesson_fret_list=lesson_fret_list,
                                        padded_duration_list=padded_duration_list, total_beats=total_beats, bpm=bpm)
        return jsonify(d)
Exemple #6
0
 def _4dom_createNotation(self, publicId, systemId, name):
     from Notation import Notation
     return Notation(self, publicId, systemId, name)
Exemple #7
0
def analyse_user_recording(dirone, dirtwo, lesson):
    """
    Pattern taken from http://flask.pocoo.org/docs/1.0/patterns/fileuploads/
    The route contains the path to the lesson the user is attempting. This is needed to get the lesson and analyse it.
    :return:
    """

    if request.method == 'POST':
        if 'file' not in request.files:
            print("no file uploaded")
            return "Error: No File uploaded"

        # Users attempt
        file = request.files['file']

        # Path to where the lesson the user attempted is stored
        lesson_path = "{}/{}".format(dirone, dirtwo)

        file_manager = FileManager(lesson_path)
        lesson_file_path = file_manager.get_lesson_path("/" + lesson)
        bpm = file_manager.get_tempo_from_file_name(lesson)

        # There is a file, it has the right extension and it has a tempo
        if file and app_utils.allowed_file(file.filename) and int(bpm) > 0:
            filename = secure_filename(file.filename)
            # Save user file to be analysed
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            uploaded_file_path = app.config['UPLOAD_FOLDER'] + "/" + filename

            user_audio_analysis = AudioAnalysis(uploaded_file_path)

            # Analyse the lesson and the users attempt
            lesson_analysis = AudioAnalysis(lesson_file_path)

            user_note_list, user_freq_list = user_audio_analysis.analyse_notes()
            user_timing_list = user_audio_analysis.analyse_timing()

            lesson_note_list, lesson_freq_list = lesson_analysis.analyse_notes()
            lesson_timing_list = lesson_analysis.analyse_timing()

            print("Lessons_freq_list" + str(lesson_freq_list))

            print("user_freq_list" + str(user_freq_list))

            # Generate the Notation Infromation
            user_notation_creator = Notation(user_freq_list, user_timing_list, bpm)

            user_string_list = user_notation_creator.get_strings_to_be_played()
            user_fret_list = user_notation_creator.get_frets_to_be_played()
            user_duration_list = user_notation_creator.get_padded_duration_list()
            total_beats = user_notation_creator.calculate_total_beats(user_duration_list)

            # Compare the lesson and the users attempt
            audio_comparison = AudioComparison(lesson, lesson_note_list, lesson_timing_list, user_note_list,
                                               user_timing_list, bpm, user_string_list, user_fret_list,
                                               user_duration_list, total_beats)

            return jsonify(audio_comparison.get_comparision_dict())
        else:
            return "Wrong File type: Must be wav and contain tempo"