示例#1
0
    def parseFile(self, filename, name="database", augment=False):
        """Construct the database of tuples from an existing midi database.

		:param path: The path to the folder to load (must contain midi files).
		:param name: The name to give to the database object, optional.

		:type path: str
		:type name: str
		"""

        if not os.path.isdir(".TEMP"):
            os.makedirs(".TEMP")

        # Number of skiped files
        skipedFiles = 0
        # Total number of files
        N = 0
        self.data = []
        self.files = []

        if filename[filename.rfind("."):] in [".mid", ".midi"]:
            if os.path.isfile(filename):
                try:
                    self.data.append(score.score(filename))
                    self.files.append(filename)

                except RuntimeError:
                    skipedFiles += 1
                N += 1

        self.getViewpointRepresentation()

        if augment is True:
            self.augmentData()
示例#2
0
文件: data.py 项目: TomsCoder/IDyOM
    def addFile(self, file):
        """ 
		Parse a midi file

		:param file: file to parse
		:type file: string
		"""

        self.data.append(score.score(file))

        self.getViewpointRepresentation()
示例#3
0
    def generate(self, length):
        """
		Implement a very easy random walk in order to generate a sequence

		:param length: length of the generated sequence (in elements, not beat so it depends on the quantization)
		:type length: int

		:return: sequence (score object) 
		"""

        S = []
        # We uniformly choose the first element
        S.extend(ast.literal_eval(np.random.choice(self.stateAlphabet)))

        while len(S) < length and str(S[-self.order:]) in self.stateAlphabet:

            S.append(self.sample(S))

        return score.score(S)
示例#4
0
文件: data.py 项目: TomsCoder/IDyOM
    def addFiles(self, files, augmentation=True):
        """ 
		Parse a list of midi file

		:param files: files to parse
		:type file: list of string
		"""
        for file in files:
            print("__", file)
            self.data.append(score.score(file))

        print("___ Constructing viewPoint representation")

        self.getViewpointRepresentation()

        if augmentation:
            print("_____ Augmenting database ...")
            print()

            self.augmentData()
示例#5
0
文件: idyom.py 项目: GuiMarion/IDyOM
    def generate(self, length):
        """
		Return a piece of music generated using the model; works only with pitch and length.

		:param length: length of the output

		:type length: int

		:return: class piece
		"""

        S = [{"pitch": 74, "length": 24}]

        while len(S) < length and S[-1] is not None:
            S.append(self.sample(S))

        if S[-1] is None:
            S = S[:-1]

        ret = []
        for note in S:
            ret.extend([note["pitch"]] * note["length"])

        return score.score(ret)
示例#6
0
import sys
sys.path.append('../')

from idyom import score
import matplotlib.pyplot as plt
import numpy as np
import copy

# Import one of my masterpieces ...
#s = score.score("velocity.mid")

s = score.score("../stimuli/Chinese/test1/chinese-001.mid")
s.plot()

print(s.getData())

quit()

s = score.score("dataBaseTest/easy.mid")

s = score.score("../stimuli/giovanni/audio1.mid")

print(list(s.getData()))

tmp = list(s.getData())

for i in range(1, len(tmp)):
    if tmp[i] == -1:
        tmp[i] = tmp[i - 1]

print(tmp)
示例#7
0
import sys 
sys.path.append('../')

from idyom import score
import matplotlib.pyplot as plt
import numpy as np
import copy

# Import one of my masterpieces ...
#s = score.score("velocity.mid")

s = score.score("../shanx185.mid")
#s = score.score("../dataset/shanxi_train_enculturation/shanx188.mid")

s.plot()
with np.printoptions(threshold=np.inf):
	print(s.getData())


quit()

s = score.score("dataBaseTest/easy.mid")

s = score.score("../stimuli/giovanni/audio1.mid")


print(list(s.getData()))

tmp = list(s.getData())

for i in range(1, len(tmp)):
示例#8
0
import sys
sys.path.append('../')

from idyom import score
import matplotlib.pyplot as plt
import numpy as np
import copy

# Import one of my masterpieces ...
#s = score.score("velocity.mid")
s = score.score("dataBaseTest/002606b_.mid")

plt.plot(s.getData())
plt.show()

s.fromData(s.getData())

s.plot()

s.writeToMidi("dataBaseTest/out.mid")

quit()
'''
Part for the midi
'''

# Return the length in time beat
print("length:", s.getLength())

# Plot the piano roll representation of the score
s.plot()
import sys
sys.path.append('../')

from idyom import longTermModel
from idyom import data
from idyom import score

import numpy as np
import matplotlib.pyplot as plt

L = longTermModel.longTermModel("pitch", maxOrder=None)

M = data.data()

#M.parse("../dataset/")
M.parse("dataBaseTest/")

L.train(M.getData("pitch"))

G = L.generate(500)

print(G)

s = score.score(G)

s.plot()

s.writeToMidi("exGen.mid")

L.save("longTermModel.save")
示例#10
0
文件: data.py 项目: TomsCoder/IDyOM
    def parse(self, path, name=None):
        """Construct the database of tuples from an existing midi database.

		:param path: The path to the folder to load (must contain midi files).
		:param name: The name to give to the database object, optional.

		:type path: str
		:type name: str
		"""

        if os.path.isdir(path):
            self.path = path
            if name:
                self.name = name
            else:
                self.name = str(path)
            print()
            print("________ We are working on '" + path + "'")
            print()
        else:
            print(
                "The path you gave is not a directory, please provide a correct directory."
            )
            raise RuntimeError("Invalid database directory")

        if not os.path.isdir(".TEMP"):
            os.makedirs(".TEMP")

        print("_____ Filling the database ...")
        print()

        # Number of skiped files
        skipedFiles = 0
        # Total number of files
        N = 0
        self.data = []
        self.files = []
        for filename in glob(self.path + '/**', recursive=True):

            if filename[filename.rfind("."):] in [".mid", ".midi"]:
                if os.path.isfile(filename):
                    print(" -", filename)
                    try:
                        self.data.append(score.score(filename))
                        self.files.append(filename)

                    except RuntimeError:
                        skipedFiles += 1
                    N += 1

        print()
        print("We passed a total of ", N, "files.")
        print(skipedFiles, "of them have been skiped.")
        print()

        print("_____ Computing multiple viewpoints representation")

        self.getViewpointRepresentation()

        print("_____ Augmenting database ...")
        print()

        self.augmentData()

        #random.shuffle(self.data)

        print("Data processing done.")