コード例 #1
0
 def test_from_Track(self):
     self.assertEqual(LilyPond.from_Track(self.track1),
                      "{ { c'4 e'4 g'4 b'4 } }")
     self.assertEqual(
         LilyPond.from_Track(self.track2),
         "{ { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }",
     )
コード例 #2
0
def save_and_print(treble_track, bass_track):
    ly_input = """
    \header {
        composer = "Zhang Transcriber 2016"
        tagline = "Music engraving by LilyPond 2.18.2. Note identification algorithm by Oliver Zhang."
    }
    \\new PianoStaff <<
        \\new Staff { \clef treble %s }
        \\new Staff { \clef bass %s }
    >>
    """ % (LilyPond.from_Track(treble_track)[1:-1],
           LilyPond.from_Track(bass_track)[1:-1])

    LilyPond.to_pdf(ly_input, "my_first_bar")
    webbrowser.open_new(r'file://' + os.path.realpath("my_first_bar.pdf"))
コード例 #3
0
def update_sheet_music(note):
    dict_note = notes_dict[note]
    t.add_notes(dict_note)
    track = LilyPond.from_Track(t)
    LilyPond.to_png(track, "track")
    img = mpimg.imread("track.png")
    cropped_image = img[0:300, :, :]
    sheet.set_data(cropped_image)
コード例 #4
0
ファイル: main.py プロジェクト: nmcasasr/Grafasol
def randomMusic(n, x, y, m, t):
    g = Graph(n=n, max_x=x, max_y=y, mode=m)
    t = tk.generate_track(g, n, t)
    bar = LilyPond.from_Track(t)
    print("Lilypond music sheet: ")
    print(bar)
    nx.draw(g.G)
    plt.show()
コード例 #5
0
ファイル: app.py プロジェクト: Ankit-04/sonicSynth
def testingLilypond():
    n = [
        "A", "B", "C", "A", "B", "D", "D", "D", "E", "A", "B", "C", "A", "B",
        "C", "A", "B", "C", "A", "B", "C", "A", "B", "C", "C-5"
    ]
    b = mingus.containers.Bar()
    track = mingus.containers.Track()
    for i in n:
        track.add_notes(i)
    trackString = lilypond.from_Track(track)
    lilypond.to_pdf(trackString, "Piece")
コード例 #6
0
ファイル: melodybot.py プロジェクト: Fuddlebob/MelodyBot3456
def create_frames(melody):
    sheet = LilyPond.from_Track(melody.notes)
    LilyPond.to_svg(sheet, OUTSVG)
    tree = ET.parse(OUTSVG)
    root = tree.getroot()
    i = 0
    notelist = []
    linkreg = re.compile(r'(\d\d*):(\d\d*):(\d\d*)')
    coordreg = re.compile(r'(\d[\d\.]*), (\d[\d\.]*)')
    for child in root:
        if (child.tag[svglen:] == "a" and len(list(child)) == 1):
            if (child[0].tag[svglen:] == "path"):
                link = child.get(linktag + "href")
                r = linkreg.search(link)
                coordstr = child[0].get("transform")[10:26]
                r2 = coordreg.search(coordstr)
                notelist.append(
                    (int(r.group(1)), int(r.group(2)), (float(r2.group(1)),
                                                        float(r2.group(2)))))
    notelist.sort()

    if (melody.key == "G" or melody.key == "F"):
        #If the Key is F or G the above reads the key signature as an extra note, we remove that here
        notelist = notelist[1:]
    if os.path.exists(FRAMELENGTHTXT):
        os.remove(FRAMELENGTHTXT)
    f = open(FRAMELENGTHTXT, "a+")
    if (not os.path.exists(FRAMEPATH)):
        os.mkdir(FRAMEPATH)
    index = 0
    for n in notelist:
        frame = Image.open(VIDPIC)
        draw = ImageDraw.Draw(frame)
        oldx = n[2][0]
        oldy = n[2][1]
        newx = conv_x(oldx)
        newy = conv_y(oldy)
        row = int(int(newy) / 85 + 1)
        draw.line([newx - 1, row * 85 - 10, newx - 1, row * 85 - 50],
                  fill=(255, 0, 0),
                  width=2)
        fn = FRAMEPATH + "frame" + str(index) + ".png"
        frame.save(fn)
        f.write("file \'" + fn + "\'\nduration " +
                str((1 / melody.raw_song[index][1] * 4) /
                    (melody.tempo / 60.0)) + "\n")
        index = index + 1
    f.write("file \'" + FRAMEPATH + "frame" + str(len(notelist) - 1) +
            ".png\'\nduration 2\nfile \'" + FRAMEPATH + "frame" +
            str(len(notelist) - 1) + ".png\'")
    f.close()
コード例 #7
0
ファイル: app.py プロジェクト: Ankit-04/sonicSynth
def stopPlaying():
    x.do_run = False
    n = getattr(x, "notes")
    b = mingus.containers.Bar()
    track = mingus.containers.Track()
    if (len(n) == 0):
        return "No file"
    for i in n:
        track.add_notes(i)
    trackString = lilypond.from_Track(track)
    lilypond.to_png(trackString, "MasterPiece" + str(len(n)))
    time.sleep(3)
    filename = 'MasterPiece' + str(len(n)) + '.png'
    return send_file(filename, mimetype='image/PNG')
コード例 #8
0
def GenSingleLily(time, bars, withChrom, with16):
    track, count = NewTrack(time, bars, withChrom, with16)
    ground_lp = LilyPond.from_Track(track)
    lp = CleanTrack(ground_lp)
    main_pattern = r" [a-z]'*\d "
    occurances = re.findall(main_pattern, lp)
    count = random.randint(0, len(occurances))
    to_replace = random.sample(occurances, k=count)
    new_notes = [
        note[:-1] + random.choice(noteSymbols) + " " for note in to_replace
    ]
    for pattern, replacement in zip(to_replace, new_notes):
        lp = re.sub(pattern, replacement, lp, count=1)
    return lp, ground_lp
コード例 #9
0
def to_Sheet(bars, chords, track, key, mode, file, out_dir, title, author):
    path = out_dir + '/' + file.split('.')[0]
    file = file.split('/')[-1]
    track = LilyPond.from_Track(track)
    track = track[1:-1]
    track = '\\header {title= "' + title + '" composer = "' + author + '"} \nmelody = {\n\\key ' + key.lower(
    ) + ' \\' + mode + '\n' + track + '''}
		harmonies = \\chordmode {''' + get_Shorthands(
        determine_chords(chords)) + '''}\n
		\\score {\n
		<<\n
    	\\new ChordNames {\n 
      	\\set chordChanges = ##t\n''' + determine_clef(bars) + '''
      	\\harmonies\n 
    	}\n 
    	\\new Staff \\melody 
 		>>\n 
  		\\layout{ } \n 
  		\\midi { }\n 
		}'''

    LilyPond.to_pdf(track, path)
    if os.path.exists(path + '.midi'):
        os.remove(path + '.midi')
コード例 #10
0
ファイル: test_lilypond.py プロジェクト: psnj/python-mingus
 def test_from_Track(self):
     self.assertEqual(LilyPond.from_Track(self.track1),
                      "{ { c'4 e'4 g'4 b'4 } }")
     self.assertEqual(LilyPond.from_Track(self.track2),
                      "{ { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }"
                      )
コード例 #11
0
#Creating tracks --- Left
t_l = Track()
for i in set(df["Measure"].unique()[:-1]):
    b = Bar(key=keysig)
    subset = df[df["Measure"] == i]
    for j, k in zip(subset["Notes_l"], subset["Diff"]):
        if len(j) > 0:  #If note is not NaN
            nc = NoteContainer(j)  #Define the note
            b.place_notes(nc, k)  #Add note to bar with length
        else:
            b.place_notes(
                None,
                k)  #Place a rest note the lenght of the other hand's note
    t_l + b
LithHarbor_ly_left = LilyPond.from_Track(t_l)  #Create .ly file

#Creating tracks --- right
t_r = Track()
for i in set(df["Measure"].unique()[:-1]):
    b = Bar(key=keysig)
    subset = df[df["Measure"] == i]
    for j, k in zip(subset["Notes_r"], subset["Diff"]):
        if j:  #If note is not NaN
            nc = NoteContainer(j)  #Define the note
            b.place_notes(nc, k)  #Add note to bar with length
        else:
            b.place_notes(
                None,
                k)  #Place a rest note the lenght of the other hand's note
    t_r + b
コード例 #12
0
ファイル: melodybot.py プロジェクト: Fuddlebob/MelodyBot3456
def create_sheet(melody):
    sheet = LilyPond.from_Track(melody.notes)
    sheet = LilyPond.to_png(sheet, VIDPIC)
    im = Image.open(VIDPIC)
    im = im.crop((0, 0, 834, 500))
    im.save(VIDPIC)
コード例 #13
0
    "I",
    "V",
    "V",
    "I",
    "I",
]

#getting the chords for the progression
my_chords = progressions.to_chords(my_progression)

#add a 4th note on each chord
my_chords = [my_chord + [my_chord[1]] for my_chord in my_chords]

#grouping notes as 4x4
all_notes = list(itertools.chain(*my_chords))
all_notes_4x4 = chunks(all_notes, 4)

#generating the track
my_track = Track()
for my4notes in all_notes_4x4:
    my_bar = Bar()
    for my_note in my4notes:
        my_bar + my_note
    my_track + my_bar

#exporting
my_lilypond = LilyPond.from_Track(my_track)
_folder = "Scores"
_file = "poc"
_path = os.path.join(_folder, _file)
LilyPond.to_png(my_lilypond, _path)