def startScoreFollower(self):
        environLocal.printDebug("startScoreFollower starting")
        self.button2 = tkinter.Button(self.master,
                                      text="START SF",
                                      width=self.sizeButton,
                                      command=self.startScoreFollower,
                                      state='disable',
                                      bg='green')
        self.button2.grid(row=5, column=3)
        scNotes = self.scorePart.flat.notesAndRests
        ScF = scoreFollower.ScoreFollower(scoreStream=scNotes)
        ScF.show = False
        ScF.plot = False
        ScF.useMic = True
        ScF.seconds_recording = 6.0
        ScF.useScale = scale.ChromaticScale('C4')
        ScF.begins = True
        ScF.countdown = 0
        self.firstTimeSF = True
        self.stop = False

        # decision of lastNotePosition taking into account the beginning of the first displayed page
        ScF.lastNotePosition = self.beginningPages[self.currentLeftPage - 1]
        ScF.startSearchAtSlot = self.beginningPages[self.currentLeftPage - 1]
        ScF.result = False
        self.textVar3.set('Start playing!')

        self.scoreFollower = ScF
        #parameters for the thread 2
        self.dummyQueue = queue.Queue()
        self.sampleQueue = queue.Queue()
        self.dummyQueue2 = queue.Queue()
        self.sampleQueue2 = queue.Queue()
        self.firstAnalysis = True
        self.continueScoreFollower()
Esempio n. 2
0
    def runScoreFollower(
        self,
        plot=False,
        useMic=False,
        seconds=15.0,
        useScale=None,
    ):
        '''
        The main program. It runs the 'repeatTranscription' until the
        performance ends.

        If `useScale` is none, then it uses a scale.ChromaticScale
        '''
        if useScale is None:
            useScale = scale.ChromaticScale('C4')
        self.seconds_recording = seconds
        self.useMic = useMic
        self.useScale = useScale

        self.result = False
        while self.result is False:
            self.result = self.repeatTranscription()

#        if plot is True:
#            try:
#                import matplotlib.pyplot # for find
#            except ImportError:
#                raise AudioSearchException('Cannot plot without matplotlib installed.')
#
#            matplotlib.pyplot.plot(listplot)
#            matplotlib.pyplot.show()
        environLocal.printDebug('* END')
Esempio n. 3
0
def runTranscribe(show=True, plot=True, useMic=True,
                  seconds=20.0, useScale=None, saveFile=True):
    '''
    runs all the methods to record from audio for `seconds` length (default 10.0)
    and transcribe the resulting melody returning a music21.Score object
    
    if `show` is True, show the stream.  
    
    if `plot` is True then a Tk graph of the frequencies will be displayed.
    
    if `useMic` is True then use the microphone.  If False it will load the file of `saveFile`
    or the default temp file to run transcriptions from.
        
    a different scale besides the chromatic scale can be specified by setting `useScale`.
    See :ref:`moduleScale` for a list of allowable scales. (or a custom one can be given).
    Microtonal scales are totally accepted, as are retuned scales where A != 440hz.

    if `saveFile` is False then then the recorded audio is saved to disk.  If
    set to `True` then `environLocal.getRootTempDir() + os.path.sep + 'ex.wav'` is
    used as the filename.  If set to anything else then it will use that as the
    filename. 
    '''
    from music21 import audioSearch as audioSearchBase

    if useScale is None:
        useScale = scale.ChromaticScale('C4')
    #beginning - recording or not
    if saveFile != False:
        if saveFile == True:
            WAVE_FILENAME = environLocal.getRootTempDir() + os.path.sep + 'ex.wav'
        else:
            WAVE_FILENAME = saveFile
    else:
        WAVE_FILENAME = False
    
    # the rest of the score
    if useMic is True:
        freqFromAQList = audioSearchBase.getFrequenciesFromMicrophone(length=seconds, storeWaveFilename=WAVE_FILENAME)
    else:
        freqFromAQList = audioSearchBase.getFrequenciesFromAudioFile(waveFilename=WAVE_FILENAME)
        
    detectedPitchesFreq = audioSearchBase.detectPitchFrequencies(freqFromAQList, useScale)
    detectedPitchesFreq = audioSearchBase.smoothFrequencies(detectedPitchesFreq)
    (detectedPitchObjects, listplot) = audioSearchBase.pitchFrequenciesToObjects(detectedPitchesFreq, useScale)
    (notesList, durationList) = audioSearchBase.joinConsecutiveIdenticalPitches(detectedPitchObjects)
    myScore, unused_length_part = audioSearchBase.notesAndDurationsToStream(notesList, durationList, removeRestsAtBeginning=True)    

    if show == True:
        myScore.show()        
    
    if plot == True:
        try:
            import matplotlib.pyplot # for find
        except ImportError:
            raise audioSearchBase.AudioSearchException("Cannot plot without matplotlib installed.")
        matplotlib.pyplot.plot(listplot)
        matplotlib.pyplot.show()
    environLocal.printDebug("* END")    
        
    return myScore
Esempio n. 4
0
def scalar_inversion(
    original_stream: stream.Stream,
    inversion_axis: Union[str, pitch.Pitch],
    reference_scale: scale.ConcreteScale = scale.ChromaticScale("C"),
    in_place: bool = False,
) -> stream.Stream:
    """Performs a scale-space inversion on a stream.

    Args:
        original_stream: The stream to process.
        inversion_axis: The pitch around which to execute the inversion.
        reference_scale: Optional; The scale to use as reference. By default, the chromatic scale is
          used.
        in_place: Optional; If true, the operation is done in place on the original stream. By
          default, a new Stream object is returned.

    Returns:
        The inverted stream.
    """
    # Check if stream is to be processed in place
    post_stream = original_stream if in_place else copy.deepcopy(
        original_stream)

    # Check if inversion_axis is Pitch
    if isinstance(inversion_axis, str):
        inversion_axis = pitch.Pitch(inversion_axis)

    # Invert all individual pitches
    for pitch_ in post_stream.pitches:
        distance_from_axis = _get_scale_distance(inversion_axis, pitch_,
                                                 reference_scale)
        _transpose_pitch_in_scale_space(pitch_, distance_from_axis * -2,
                                        reference_scale)

    return post_stream
Esempio n. 5
0
def scalar_transposition(
    original_stream: stream.Stream,
    steps: int,
    reference_scale: scale.ConcreteScale = scale.ChromaticScale("C"),
    in_place: bool = False,
) -> stream.Stream:
    """Performs scale-space transpotition on a stream.

    Transposes all notes in a stream by a specified amount of scale steps in a specific scale space.

    Args:
        original_stream: The stream to process.
        steps: The amount of steps to transpose. Positive values transpose up, negative values
          transpose down.
        reference_scale: Optional; The scale to use as reference. By default, the chromatic scale
          is used.
        in_place: Optional; If true, the operation is done in place on the original stream. By
          default, a new Stream object is returned.

    Returns:
        The transposed stream.
    """
    # Check if stream is to be processed in place
    post_stream = original_stream if in_place else copy.deepcopy(
        original_stream)

    # Transpose all individual pitches
    for pitch_ in post_stream.pitches:
        _transpose_pitch_in_scale_space(pitch_, steps, reference_scale)

    return post_stream
Esempio n. 6
0
 def run(self):
     self.myScore = transcriber.runTranscribe(
         show=self.show,
         plot=False,
         useMic=True,
         seconds=self.seconds,
         useScale=scale.ChromaticScale('C4'),
         saveFile=self.saveFile)
     self.queue.put(1)
Esempio n. 7
0
def get_all_scales():
    pitches = scale.ChromaticScale('A').pitches
    major_scales = [scale.MajorScale(pitch) for pitch in pitches]
    minor_scales = [scale.MinorScale(pitch) for pitch in pitches]

    scales = parse_and_format_scales(major_scales)
    scales.extend(parse_and_format_scales(minor_scales))

    return scales
Esempio n. 8
0
def runGame():
    useScale = scale.ChromaticScale('C4')
    roundNumber = 0
    good = True
    gameNotes = []

    print("Welcome to the music21 game!")
    print("Rules:")
    print(
        "The computer generates a note (and it will play them in the future).")
    print("The player has to play all the notes from the beginning.")
    time.sleep(2)
    print("3, 2, 1 GO!")
    nameNotes = ["A", "B", "C", "D", "E", "F", "G"]
    while (good == True):
        randomNumber = random.randint(0, 6)
        octaveNumber = 4  # I can put a random number here...
        fullNameNote = "%s%d" % (nameNotes[randomNumber], octaveNumber)
        gameNotes.append(note.Note(fullNameNote))

        roundNumber = roundNumber + 1
        print("ROUND %d" % roundNumber)
        print("NOTES UNTIL NOW: (this will not be shown in the final version)")
        for k in range(len(gameNotes)):
            print(gameNotes[k].fullName)

        seconds = 2 * roundNumber + 2
        freqFromAQList = base.getFrequenciesFromMicrophone(
            length=seconds, storeWaveFilename=None)
        detectedPitchesFreq = base.detectPitchFrequencies(
            freqFromAQList, useScale)
        detectedPitchesFreq = base.smoothFrequencies(detectedPitchesFreq)
        (detectedPitchObjects,
         unused_listplot) = base.pitchFrequenciesToObjects(
             detectedPitchesFreq, useScale)
        (notesList, unused_durationList
         ) = base.joinConsecutiveIdenticalPitches(detectedPitchObjects)
        j = 0
        i = 0
        while i < len(notesList) and j < len(gameNotes) and good == True:
            if notesList[i].name == "rest":
                i = i + 1
            elif notesList[i].name == gameNotes[j].name:
                i = i + 1
                j = j + 1
            else:
                print("WRONG NOTE! You played", notesList[i].fullName,
                      "and should have been", gameNotes[j].fullName)
                good = False

        if good == True and j != len(gameNotes):
            good = False
            print("YOU ARE VERY SLOW!!! PLAY FASTER NEXT TIME!")

        if good == False:
            print("GAME OVER! TOTAL ROUNDS: %d" % roundNumber)
Esempio n. 9
0
    def __init__(self):
        self.useScale = scale.ChromaticScale('C4')
        self.round = 0
        self.good = True
        self.gameNotes = []        
        print "Welcome to the music21 game!"
        print "Rules:"
        print "Two players: the first one plays a note. \nThe second one has to play the first note and a new one."
        print "Continue doing the same until one fails."
#        time.sleep(2)
        print "3, 2, 1 GO!"    
Esempio n. 10
0
def prepareThresholds(useScale=None):
    # noinspection PyShadowingNames
    '''
    returns two elements.  The first is a list of threshold values
    for one octave of a given scale, `useScale`,
    (including the octave repetition) (Default is a ChromaticScale).
    The second is the pitches of the scale.

    A threshold value is the fractional part of the log-base-2 value of the
    frequency.

    For instance if A = 440 and B-flat = 460, then the threshold between
    A and B-flat will be 450.  Notes below 450 should be considered As and those
    above 450 should be considered B-flats.

    Thus the list returned has one less element than the number of notes in the
    scale + octave repetition.  If useScale is a ChromaticScale, `prepareThresholds`
    will return a 12 element list.  If it's a diatonic scale, it'll have 7 elements.


    >>> pitchThresholds, pitches = audioSearch.prepareThresholds(scale.MajorScale('A3'))
    >>> for i in range(len(pitchThresholds)):
    ...    print(f'{pitches[i]} < {pitchThresholds[i]:.2f} < {pitches[i + 1]}')
    A3 < 0.86 < B3
    B3 < 0.53 < C#4
    C#4 < 0.16 < D4
    D4 < 0.28 < E4
    E4 < 0.45 < F#4
    F#4 < 0.61 < G#4
    G#4 < 1.24 < A4
    '''
    if useScale is None:
        useScale = scale.ChromaticScale('C4')

    scPitches = useScale.pitches
    scPitchesRemainder = []

    for p in scPitches:
        pLog2 = math.log2(p.frequency)
        scPitchesRemainder.append(math.modf(pLog2)[0])
    scPitchesRemainder[-1] += 1

    scPitchesThreshold = []
    for i in range(len(scPitchesRemainder) - 1):
        scPitchesThreshold.append(
            (scPitchesRemainder[i] + scPitchesRemainder[i + 1]) / 2)

    return scPitchesThreshold, scPitches
Esempio n. 11
0
 def testChromaticScaleA(self):
     cs = scale.ChromaticScale('c4')
     self.assertEqual(
         self.pitchOut(cs.pitches),
         '[C4, C#4, D4, E-4, E4, F4, F#4, G4, A-4, A4, B-4, B4, C5]')