示例#1
0
    def draw_grid(self):
        """ draw a grid at each integer x and y value """
        for x in range(tools.floor(self.lo_x), tools.ceil(self.hi_x)):
            bot, top = (x, self.lo_y), (x, self.hi_y)
            pgdraw.line(self.screen, clrs['lgrey'], self.to_screen(bot),
                        self.to_screen(top))

        for y in range(tools.floor(self.lo_y), tools.ceil(self.hi_y)):
            lft, rgt = (self.lo_x, y), (self.hi_x, y)
            #print(lft, rgt)
            pgdraw.line(self.screen, clrs['lgrey'], self.to_screen(lft),
                        self.to_screen(rgt))
示例#2
0
    def draw_axis(self, draw_x=True, draw_y=True):
        """ draw x and y axis, and keep them on screen always
        with a distance of opts.aw

        plot.draw_axis() -> None
        """
        def limit(ar1, ar2, func):
            " limit the values of ar1 by values of ar2 by func "
            for c, _unused in enumerate(ar1):
                if not ar2[c]:
                    continue
                if func(ar1[c], ar2[c]):
                    ar1[c] = ar2[c]
            return ar1

        if draw_x:
            x_ax1 = self.to_screen(self.lo_x, 0)
            x_ax2 = self.to_screen(self.hi_x, 0)

            x_ax1 = limit(x_ax1, (None, opts.aw), lambda x, y: x < y)
            x_ax1 = limit(x_ax1, (None, opts.sh - opts.aw), lambda x, y: x > y)
            x_ax2 = limit(x_ax2, (None, opts.aw), lambda x, y: x < y)
            x_ax2 = limit(x_ax2, (None, opts.sh - opts.aw), lambda x, y: x > y)

            pgdraw.line(self.screen, clrs['black'], x_ax1,
                        x_ax2)  # draw the axis

            for x in range(tools.floor(self.lo_x),
                           tools.ceil(self.hi_x)):  # draw ticks
                pos = self.to_screen(x, 0)

                pos = limit(pos, (None, opts.aw), lambda x, y: x < y)
                pos = limit(pos, (None, opts.sh - opts.aw), lambda x, y: x > y)

                pos1, pos2 = (pos - np.array((0, 10))), (pos + np.array(
                    (0, 10)))

                pgdraw.line(self.screen, clrs['black'], pos1, pos2)
                self.center_text(x, pos + np.array((10, -10)), self.axis_font)

        if draw_y:
            y_ax1 = self.to_screen(0, self.lo_y)
            y_ax2 = self.to_screen(0, self.hi_y)

            y_ax1 = limit(y_ax1, (opts.aw, None), lambda x, y: x < y)
            y_ax1 = limit(y_ax1, (opts.sw - opts.aw, None), lambda x, y: x > y)
            y_ax2 = limit(y_ax2, (opts.aw, None), lambda x, y: x < y)
            y_ax2 = limit(y_ax2, (opts.sw - opts.aw, None), lambda x, y: x > y)

            pgdraw.line(self.screen, clrs['black'], y_ax1, y_ax2)  # draw axis

            for y in range(tools.floor(self.lo_y),
                           tools.ceil(self.hi_y)):  # draw ticks
                pos = self.to_screen(0, y)

                pos = limit(pos, (opts.aw, None), lambda x, y: x < y)
                pos = limit(pos, (opts.sw - opts.aw, None), lambda x, y: x > y)

                pos1, pos2 = (pos - np.array((10, 0))), (pos + np.array(
                    (10, 0)))

                pgdraw.line(self.screen, clrs['black'], pos1, pos2)
                self.center_text(y, pos + np.array((10, -10)), self.axis_font)
示例#3
0
    def readMIDIData(self, data):
        corpus = dict()
        # de-interlacing information
        fgMatrix, bgMatrix = tools.splitMatrixByChannel(
            data, self.fgChannels, self.bgChannels)
        corpus["name"] = self.corpus_name  # a changer
        corpus["typeID"] = 'MIDI'
        corpus[
            "type"] = 3  # TODO: What is this '3'? Change to named, static variable
        corpus["size"] = 1
        corpus["data"] = []

        # creating a first state, not really used except for
        corpus["data"].append({
            "state":
            0,
            "time": [0, 0],
            "seg": [1, 0],
            "beat": [0.0, 0.0, 0, 0],
            "extras":
            [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            "slice": [140, 0.0],
            "notes":
            dict()
        })

        current_phrase = 1
        pitchesInState = []

        if len(bgMatrix) != 0:
            hCtxt, tRef = tools.computePitchClassVector(bgMatrix, self.tStep)
        else:
            print(
                "Warning: no notes in background channels. Computing harmonic context with foreground channels"
            )
            hCtxt, tRef = tools.computePitchClassVector(fgMatrix, self.tStep)

        lastNoteOnset = -1 - self.tolerance
        lastSliceOnset = lastNoteOnset
        next_state_idx = 0
        globalTime = 0
        nextState = dict()

        for i in range(len(fgMatrix)):
            # The note is not a part of the current slice: create a new state
            if fgMatrix[i][MatrixIdx.POSITION_MS] > (lastSliceOnset +
                                                     self.tolerance):
                if next_state_idx > 0:
                    # get content of the previous state
                    pitchesInState = tools.getPitchContent(
                        corpus["data"], next_state_idx, self.legato)
                    num_pitches = len(pitchesInState)

                    if num_pitches == 0:
                        # Note: 0-127 are note values, 128-139 virtual fundamentals and 140 denotes 'no value')
                        slice_value = 140
                    elif num_pitches == 1:
                        slice_value = int(pitchesInState[0])
                    else:
                        virtualfunTmp = virfun.virfun(pitchesInState, 0.293)
                        slice_value = int(128 + virtualfunTmp % 12)

                    if self.mod12:
                        slice_value %= 12

                    corpus["data"][next_state_idx]["slice"][0] = slice_value

                # Old debug statement: too much output to be meaningful
                # self.logger.debug(''.join([str(row) + '\n' for row in corpus["data"]]))

                # create new state
                next_state_idx += 1
                globalTime = float(fgMatrix[i][MatrixIdx.POSITION_MS])
                nextState = dict()
                nextState["state"] = int(next_state_idx)
                nextState["time"] = list(
                    [globalTime, fgMatrix[i][MatrixIdx.DUR_MS]])
                nextState["seg"] = list(
                    [bisect_left(self.file_inds, i), current_phrase])
                nextState["beat"] = list([
                    fgMatrix[i][MatrixIdx.POSITION_TICK],
                    fgMatrix[i][MatrixIdx.TEMPO], 0, 0
                ])
                frameNbTmp = tools.ceil(
                    (fgMatrix[i][MatrixIdx.POSITION_MS] + self.tDelay - tRef) /
                    self.tStep)
                if frameNbTmp <= 0:
                    nextState["extras"] = [
                        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
                    ]
                else:
                    nextState["extras"] = hCtxt[:,
                                                min(int(frameNbTmp
                                                        ), hCtxt.shape[1] -
                                                    1)].tolist()
                nextState["slice"] = [0, 0.0]
                nextState["notes"] = []

                previousSliceDuration = fgMatrix[i][
                    MatrixIdx.POSITION_MS] - lastSliceOnset
                corpus["data"][next_state_idx -
                               1]["time"][1] = previousSliceDuration

                numNotesInPreviousSlice = len(corpus["data"][next_state_idx -
                                                             1]["notes"])
                for k in range(0, numNotesInPreviousSlice):
                    # note-off went off during the previous slice
                    timePrevSlice = corpus["data"][next_state_idx -
                                                   1]["notes"][k]["time"]
                    if ((timePrevSlice[0] + timePrevSlice[1]) <=
                            previousSliceDuration):
                        if timePrevSlice[0] < 0:
                            corpus["data"][next_state_idx -
                                           1]["notes"][k]["note"][1] = 0
                            corpus["data"][next_state_idx - 1]["notes"][k]["time"][0] = \
                                float(timePrevSlice[1]) + float(timePrevSlice[0])
                    # note continues; if still in current slice, add it to the current slice and modify the previous one
                    else:
                        # add it
                        numNotesInSlice = len(nextState["notes"])
                        nextState["notes"].append(dict())
                        nextState["notes"][numNotesInSlice]["note"] = \
                            list(corpus["data"][next_state_idx - 1]["notes"][k]["note"])
                        nextState["notes"][numNotesInSlice]["time"] = \
                            list(corpus["data"][next_state_idx - 1]["notes"][k]["time"])
                        nextState["notes"][numNotesInSlice]["time"][
                            0] -= previousSliceDuration

                        # modify it
                        corpus["data"][next_state_idx -
                                       1]["notes"][k]["time"][1] = 0

                # add the new note
                numNotesInSlice = len(nextState["notes"])
                nextState["notes"].append(dict())
                nextState["notes"][numNotesInSlice]["note"] = [
                    fgMatrix[i][MatrixIdx.NOTE], fgMatrix[i][MatrixIdx.VEL],
                    fgMatrix[i][MatrixIdx.CHANNEL]
                ]
                nextState["notes"][numNotesInSlice]["time"] = [
                    0, fgMatrix[i][MatrixIdx.DUR_MS]
                ]
                corpus["data"].append(dict(nextState))

                # update variables used during the slicing process
                lastNoteOnset = array(fgMatrix[i][MatrixIdx.POSITION_MS])
                lastSliceOnset = array(fgMatrix[i][MatrixIdx.POSITION_MS])

            # note in current slice; updates current slice
            else:
                numNotesInSlice = len(corpus["data"][next_state_idx]["notes"])
                offset = fgMatrix[i][MatrixIdx.POSITION_MS] - corpus["data"][
                    next_state_idx]["time"][0]
                nextState = dict()
                nextState["note"] = [
                    fgMatrix[i][MatrixIdx.NOTE], fgMatrix[i][MatrixIdx.VEL],
                    fgMatrix[i][MatrixIdx.CHANNEL]
                ]
                nextState["time"] = [offset, fgMatrix[i][MatrixIdx.DUR_MS]]

                corpus["data"][next_state_idx]["notes"].append(nextState)

                if ((fgMatrix[i][6] + offset) >
                        corpus["data"][next_state_idx]["time"][1]):
                    corpus["data"][next_state_idx]["time"][
                        1] = fgMatrix[i][6] + int(offset)

                lastNoteOnset = array(fgMatrix[i][MatrixIdx.POSITION_MS])

        # Finalize the current slice
        globalTime = fgMatrix[i][MatrixIdx.POSITION_MS]
        lastSliceDuration = corpus["data"][next_state_idx]["time"][1]
        numNotesInLastSlice = len(corpus["data"][next_state_idx]["notes"])
        for k in range(0, numNotesInLastSlice):
            timeCurrentSlice = corpus["data"][next_state_idx]["notes"][k][
                "time"]
            if (timeCurrentSlice[0] +
                    timeCurrentSlice[1]) <= lastSliceDuration:
                if timeCurrentSlice[0] < 0:
                    corpus["data"][next_state_idx]["notes"][k]["note"][1] = 0
                    # self.logger.debug("Setting velocity of note {0} of state {1} to 0".format(k, next_state_idx))
                    corpus["data"][next_state_idx]["notes"][k]["time"][0] = \
                        int(corpus["data"][next_state_idx]["notes"][k]["time"][1]) \
                        + int(corpus["data"][next_state_idx]["notes"][k]["time"][0])
        pitchesInState = tools.getPitchContent(corpus["data"], next_state_idx,
                                               self.legato)
        if len(pitchesInState) == 0:
            corpus["data"][next_state_idx]["slice"][0] = 140
        elif len(pitchesInState) == 1:
            corpus["data"][next_state_idx]["slice"][0] = int(pitchesInState[0])
        else:
            virtualFunTmp = virfun.virfun(pitchesInState, 0.293)
            corpus["data"][next_state_idx]["slice"][0] = int(128 +
                                                             virtualFunTmp %
                                                             12)

        frameNbTmp = tools.ceil(
            (fgMatrix[i][5] + self.tDelay - tRef) / self.tStep)
        if (frameNbTmp <= 0):
            corpus["data"][next_state_idx]["extras"] = [
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
            ]
        else:
            corpus["data"][next_state_idx][
                "extras"] = hCtxt[:,
                                  min(int(frameNbTmp), hCtxt.shape[1]) -
                                  1].tolist()

        corpus["size"] = next_state_idx + 1

        return dict(corpus)
示例#4
0
    def readMIDIData(self, data):
        corpus = dict()
        fgMatrix, bgMatrix = tools.splitMatrixByChannel(
            data, self.fgChannels,
            self.bgChannels)  # de-interlacing information
        corpus["name"] = self.corpus_name  # a changer
        corpus["typeID"] = 'MIDI'
        corpus["type"] = 3
        corpus["size"] = 1
        corpus["data"] = []
        corpus["data"].append({"state": 0, "time": [0, 0], "seg": [1, 0], "beat": [0.0, 0.0, 0, 0], \
                               "extras": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
                               "slice": [140, 0.0], "notes": dict()})
        globalTime = 0
        current_phrase = 1

        fgMatrix = array(fgMatrix)
        cd = arange(floor(min(fgMatrix[:, 0])), ceil(max(fgMatrix[:, 0])))

        matrix = zeros((cd.size, 10))
        matrix[:, 0] = cd
        matrix[:, 1] = 1.0
        matrix[:, 2] = 1
        matrix[:, 3] = 60
        matrix[:, 4] = 100

        for k in range(0, cd.size):
            beatPosTemp = matrix[k, 0]
            indTmp = min(argwhere(fgMatrix[:, 0] > beatPosTemp))
            if indTmp == []:
                indTmp = fgMatrix.shape[0]
            if (indTmp > 1) and (abs(fgMatrix[indTmp, 0] - beatPosTemp) >
                                 abs(fgMatrix[indTmp - 1, 0] - beatPosTemp)):
                indTmp -= 1
            # print indTmp
            bpmTmp = fgMatrix[indTmp, 7]
            matrix[k, 5] = fgMatrix[indTmp, 5] + round(
                (beatPosTemp - fgMatrix[indTmp, 0]) * 60000 / bpmTmp)
            matrix[k, 6] = 1.0 * round(60000.0 / bpmTmp)
            matrix[k, 7] = bpmTmp
            matrix[k, 8] = 2
            matrix[k, 9] = 2

        # print matrix

        if (len(bgMatrix) != 0):
            hCtxt, tRef = tools.computePitchClassVector(bgMatrix, self.tStep)
        else:
            print(
                "Warning: no notes in background channels. Computing harmonic context with foreground channels"
            )
            hCtxt, tRef = tools.computePitchClassVector(fgMatrix, self.tStep)

        lastNoteOnset = -1 - self.tolerance
        lastSliceOnset = lastNoteOnset
        stateIdx = 0
        nbNotes = cd.size
        globalTime = 0
        nextState = dict()
        matrix = asarray(matrix)
        for i in range(0,
                       matrix.shape[0]):  # on parcourt les notes de la matrice
            if (matrix[i][5] > lastSliceOnset + self.tolerance
                ):  # la note n'est pas consideree dans la slice courante

                if stateIdx > 0:
                    tmpListOfPitches = tools.getPitchContent(
                        corpus["data"], stateIdx, self.legato
                    )  # on obtient l'etiquette de la slice precedente
                    l = len(tmpListOfPitches)
                    if l == 0:
                        corpus["data"][stateIdx]["slice"][0] = 140  # repos
                    if l == 1:
                        corpus["data"][stateIdx]["slice"][0] = int(
                            tmpListOfPitches[0])
                    else:
                        virtualfunTmp = virfun.virfun(tmpListOfPitches, 0.293)
                        corpus["data"][stateIdx]["slice"][0] = int(
                            128 + virtualfunTmp % 12)
                if self.verbose:
                    print "slice is over, finalizing it"
                    for k in range(0, len(corpus["data"])):
                        print corpus["data"][k]
                        print ""
                        print "----------------------------------------"
                        print ""

                # create new state
                stateIdx += 1
                nextState = dict()
                globalTime = matrix[i][5]
                nextState["state"] = int(stateIdx)
                nextState["time"] = [globalTime, matrix[i][6]]
                nextState["seg"] = [
                    bisect_left(self.file_inds, i), current_phrase
                ]
                nextState["beat"] = [matrix[i][0], matrix[i][7], 0, 0]
                frameNbTmp = tools.ceil(
                    (matrix[i][5] + self.tDelay - tRef) / self.tStep)
                if frameNbTmp <= 0:
                    nextState["extras"] = [
                        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
                    ]
                else:
                    nextState["extras"] = hCtxt[:,
                                                min(int(frameNbTmp
                                                        ), hCtxt.shape[1] -
                                                    1)].tolist()
                nextState["slice"] = [0, 0.0]
                nextState["notes"] = []
                previousSliceDuration = matrix[i][5] - lastSliceOnset
                numNotesInPreviousSlice = len(corpus["data"][stateIdx -
                                                             1]["notes"])
                # TODO: Code duplication from OpSomaxStandard. Refactor
                for k in range(0, numNotesInPreviousSlice):
                    if ((corpus["data"][stateIdx - 1]["notes"][k]["time"][0] +
                         corpus["data"][stateIdx - 1]["notes"][k]["time"][1]) \
                            <= previousSliceDuration):  # note-off went off during the previous slice
                        if (corpus["data"][stateIdx - 1]["notes"][k]["time"][0]
                                < 0):
                            corpus["data"][stateIdx -
                                           1]["notes"][k]["note"][1] = 0

                            # self.logger.debug("Setting velocity of note {0} of state {1} to 0.".format(k, stateIdx - 1))
                            corpus["data"][stateIdx -
                                           1]["notes"][k]["time"][0] = int(
                                               corpus["data"][stateIdx - 1]
                                               ["notes"][k]["time"][1]) + int(
                                                   corpus["data"][stateIdx - 1]
                                                   ["notes"][k]["time"][0])
                    else:  # note continues ; if still in current slice, add it to the current slice and modify the previous one
                        # add it
                        numNotesInSlice = len(nextState["notes"])
                        nextState["notes"].append(dict())
                        # (2019-09-09) Removed dict instruction from previous implementation
                        nextState["notes"][numNotesInSlice]["note"] = corpus[
                            "data"][stateIdx - 1]["notes"][k]["note"]
                        nextState["notes"][numNotesInSlice]["time"] = corpus[
                            "data"][stateIdx - 1]["notes"][k]["time"]
                        nextState["notes"][numNotesInSlice]["time"][
                            0] -= previousSliceDuration

                        # modify it
                        corpus["data"][stateIdx - 1]["notes"][k]["time"][1] = 0

                # add the new note
                numNotesInSlice = len(nextState["notes"])
                nextState["notes"].append(dict())
                nextState["notes"][numNotesInSlice]["note"] = [
                    matrix[i][3], matrix[i][4], matrix[i][2]
                ]
                nextState["notes"][numNotesInSlice]["time"] = [0, matrix[i][6]]
                corpus["data"].append(dict(nextState))

                # update variables used during the slicing process
                lastNoteOnset = matrix[i][5]
                lastSliceOnset = matrix[i][5]

            # note in current slice ; updates current slice
            else:
                numNotesInSlice = len(corpus["data"][stateIdx]["notes"])
                offset = matrix[i][5] - corpus["data"][stateIdx]["time"][0]
                nextState = dict()
                nextState["note"] = [matrix[i][3], matrix[i][4], matrix[i][2]]
                nextState["time"] = [offset, matrix[i][6]]

                corpus["data"][stateIdx]["notes"].append(nextState)

                if ((matrix[i][6] + offset) >
                        corpus["data"][stateIdx]["time"][1]):
                    corpus["data"][stateIdx]["time"][1] = matrix[i][6] + offset
                lastNoteOnset = matrix[i][5]

        # on finalise la slice courante
        globalTime = matrix[i][5]
        lastSliceDuration = float(corpus["data"][stateIdx]["time"][1])
        nbNotesInLastSlice = len(corpus["data"][stateIdx]["notes"])
        for k in range(0, nbNotesInLastSlice):
            if ((corpus["data"][stateIdx]["notes"][k]["time"][0] +
                 corpus["data"][stateIdx]["notes"][k]["time"][1]) <=
                    lastSliceDuration):
                if (corpus["data"][stateIdx]["notes"][k]["time"][0] < 0):
                    corpus["data"][stateIdx]["notes"][k]["note"][1] = 0
                    # self.logger.debug("Setting velocity of note", k, "of state", stateIdx, "to 0"
                    corpus["data"][stateIdx]["notes"][k]["time"][0] = int(
                        corpus["data"][stateIdx]["notes"][k]["time"][1]) + int(
                            corpus["data"][stateIdx]["notes"][k]["time"][0])
        tmpListOfPitches = tools.getPitchContent(corpus["data"], stateIdx,
                                                 self.legato)
        if len(tmpListOfPitches) == 0:
            corpus["data"][stateIdx]["slice"][0] = 140
        elif len(tmpListOfPitches) == 1:
            corpus["data"][stateIdx]["slice"][0] = int(tmpListOfPitches[0])
        else:
            virtualFunTmp = virfun.virfun(tmpListOfPitches, 0.293)
            corpus["data"][stateIdx]["slice"][0] = int(128 +
                                                       virtualFunTmp % 12)

        frameNbTmp = tools.ceil(
            (matrix[i][5] + self.tDelay - tRef) / self.tStep)
        if (frameNbTmp <= 0):
            corpus["data"][stateIdx]["extras"] = [
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
            ]
        else:
            corpus["data"][stateIdx][
                "extras"] = hCtxt[:,
                                  min(int(frameNbTmp), hCtxt.shape[1] -
                                      1)].tolist()

        corpus["size"] = stateIdx + 1
        return dict(corpus)
示例#5
0
文件: ops.py 项目: DYCI2/Somax
    def readMIDIData(self, data):
        corpus = dict()
        fgMatrix, bgMatrix = tools.splitMatrixByChannel(
            data, self.fgChannels,
            self.bgChannels)  #de-interlacing information
        corpus["name"] = self.corpus_name  # a changer
        corpus["typeID"] = 'MIDI'
        corpus["type"] = 3
        corpus["size"] = 1
        corpus["data"] = []

        # creating a first state, not really used except for
        corpus["data"].append({"state": 0, "time": [0,0], "seg": [1,0], "beat":[0.0, 0.0, 0, 0], \
         "extras": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], "slice":[140, 0.0], "notes":dict()})

        current_phrase = 1
        tmpListOfPitches = []

        if (len(bgMatrix) != 0):
            hCtxt, tRef = tools.computePitchClassVector(bgMatrix, self.tStep)
        else:
            print(
                "Warning: no notes in background channels. Computing harmonic context with foreground channels"
            )
            hCtxt, tRef = tools.computePitchClassVector(fgMatrix, self.tStep)

        lastNoteOnset = -1 - self.tolerance
        lastSliceOnset = lastNoteOnset
        stateNb = 0
        globalTime = 0
        tmp = dict()

        for i in range(0,
                       len(fgMatrix)):  # on parcourt les notes de la matrice
            if (fgMatrix[i][5] > (lastSliceOnset + self.tolerance)
                ):  # la note n'est pas consideree dans la slice courante
                if stateNb > 0:
                    tmpListOfPitches = tools.getPitchContent(
                        corpus["data"], stateNb, self.legato
                    )  # on obtient l'etiquette de la slice precedente
                    l = len(tmpListOfPitches)
                    if l == 0:
                        corpus["data"][stateNb]["slice"][0] = 140  # repos
                    if l == 1:
                        corpus["data"][stateNb]["slice"][0] = int(
                            tmpListOfPitches[0])
                    else:
                        virtualfunTmp = virfun.virfun(tmpListOfPitches, 0.293)
                        corpus["data"][stateNb]["slice"][0] = int(
                            128 + virtualfunTmp % 12)

                    if self.mod12:
                        corpus["data"][stateNb]["slice"][0] %= 12
                if self.verbose:
                    print "slice is over, finalizing it"
                    for k in range(0, len(corpus["data"])):
                        print corpus["data"][k]
                        print ""
                        print "----------------------------------------"
                        print ""

                #create new state
                stateNb += 1
                globalTime = float(fgMatrix[i][5])
                tmp = dict()
                tmp["state"] = int(stateNb)
                tmp["time"] = list([globalTime, fgMatrix[i][6]])
                tmp["seg"] = list(
                    [bisect_left(self.file_inds, i), current_phrase])
                tmp["beat"] = list([fgMatrix[i][0], fgMatrix[i][7], 0, 0])
                frameNbTmp = tools.ceil(
                    (fgMatrix[i][5] + self.tDelay - tRef) / self.tStep)
                if frameNbTmp <= 0:
                    tmp["extras"] = [
                        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
                    ]
                else:
                    tmp["extras"] = hCtxt[:,
                                          min(int(frameNbTmp), hCtxt.shape[1]
                                              )].tolist()
                tmp["slice"] = [0, 0.0]
                tmp["notes"] = []

                previousSliceDuration = fgMatrix[i][5] - lastSliceOnset
                corpus["data"][stateNb - 1]["time"][1] = previousSliceDuration

                nbNotesInPreviousSlice = len(corpus["data"][stateNb -
                                                            1]["notes"])
                for k in range(0, nbNotesInPreviousSlice):
                    if ((corpus["data"][stateNb-1]["notes"][k]["time"][0]+corpus["data"][stateNb-1]["notes"][k]["time"][1])\
                                 <=previousSliceDuration): # note-off went off during the previous slice
                        if (corpus["data"][stateNb - 1]["notes"][k]["time"][0]
                                < 0):
                            corpus["data"][stateNb -
                                           1]["notes"][k]["note"][1] = 0
                            #print "setting velocity of note", k, "of state", stateNb, "to 0"
                            corpus["data"][
                                stateNb - 1]["notes"][k]["time"][0] = float(
                                    corpus["data"][stateNb - 1]["notes"][k]
                                    ["time"][1]) + float(corpus["data"][
                                        stateNb - 1]["notes"][k]["time"][0])
                    else:  #note continues ; if still in current slice, add it to the current slice and modify the previous one
                        #add it
                        nbNotesInSlice = len(tmp["notes"])
                        tmp["notes"].append(dict())
                        tmp["notes"][nbNotesInSlice]["note"] = list(
                            corpus["data"][stateNb - 1]["notes"][k]["note"])
                        tmp["notes"][nbNotesInSlice]["time"] = list(
                            corpus["data"][stateNb - 1]["notes"][k]["time"])
                        tmp["notes"][nbNotesInSlice]["time"][
                            0] -= previousSliceDuration

                        #modify it
                        corpus["data"][stateNb - 1]["notes"][k]["time"][1] = 0

                #add the new note
                nbNotesInSlice = len(tmp["notes"])
                tmp["notes"].append(dict())
                tmp["notes"][nbNotesInSlice]["note"] = [
                    fgMatrix[i][3], fgMatrix[i][4], fgMatrix[i][2]
                ]
                tmp["notes"][nbNotesInSlice]["time"] = [0, fgMatrix[i][6]]
                corpus["data"].append(dict(tmp))

                #update variables used during the slicing process
                lastNoteOnset = array(fgMatrix[i][5])
                lastSliceOnset = array(fgMatrix[i][5])

            # note in current slice ; updates current slice
            else:
                nbNotesInSlice = len(corpus["data"][stateNb]["notes"])
                offset = fgMatrix[i][5] - corpus["data"][stateNb]["time"][0]
                tmp = dict()
                tmp["note"] = [fgMatrix[i][3], fgMatrix[i][4], fgMatrix[i][2]]
                tmp["time"] = [offset, fgMatrix[i][6]]

                corpus["data"][stateNb]["notes"].append(tmp)

                if ((fgMatrix[i][6] + offset) >
                        corpus["data"][stateNb]["time"][1]):
                    corpus["data"][stateNb]["time"][1] = fgMatrix[i][6] + int(
                        offset)

                lastNoteOnset = array(fgMatrix[i][5])

        # on finalise la slice courante
        globalTime = fgMatrix[i][5]
        lastSliceDuration = corpus["data"][stateNb]["time"][1]
        nbNotesInLastSlice = len(corpus["data"][stateNb]["notes"])
        for k in range(0, nbNotesInLastSlice):
            if ((corpus["data"][stateNb]["notes"][k]["time"][0] +
                 corpus["data"][stateNb]["notes"][k]["time"][1]) <=
                    lastSliceDuration):
                if (corpus["data"][stateNb]["notes"][k]["time"][0] < 0):
                    corpus["data"][stateNb]["notes"][k]["note"][1] = 0
                    print "setting velocity of note", k, "of state", stateNb, "to 0"
                    corpus["data"][stateNb]["notes"][k]["time"][0] = int(
                        corpus["data"][stateNb]["notes"][k]["time"][1]) + int(
                            corpus["data"][stateNb]["notes"][k]["time"][0])
        tmpListOfPitches = tools.getPitchContent(corpus["data"], stateNb,
                                                 self.legato)
        if len(tmpListOfPitches) == 0:
            corpus["data"][stateNb]["slice"][0] = 140
        elif len(tmpListOfPitches) == 1:
            corpus["data"][stateNb]["slice"][0] = int(tmpListOfPitches[0])
        else:
            virtualFunTmp = virfun.virfun(tmpListOfPitches, 0.293)
            corpus["data"][stateNb]["slice"][0] = int(128 + virtualFunTmp % 12)

        frameNbTmp = tools.ceil(
            (fgMatrix[i][5] + self.tDelay - tRef) / self.tStep)
        if (frameNbTmp <= 0):
            corpus["data"][stateNb]["extras"] = [
                0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
            ]
        else:
            corpus["data"][stateNb][
                "extras"] = hCtxt[:,
                                  min(int(frameNbTmp), hCtxt.shape[1])].tolist(
                                  )

        corpus["size"] = stateNb + 1

        return dict(corpus)