|
|
@@ -1,16 +1,21 @@
|
|
|
import sys
|
|
|
+import os
|
|
|
sys.path.append('/home/lida/Downloads/lilypond-2.24.1/python')
|
|
|
from PyQt5.QtWidgets import *
|
|
|
from PyQt5.QtCore import Qt, QThread, pyqtSignal
|
|
|
from PyQt5.QtGui import QPixmap
|
|
|
from PyQt5 import uic
|
|
|
import keyboard
|
|
|
-from ly import * #LilyPondFile, LilyPondFormat
|
|
|
-import ly.document
|
|
|
-import ly.cli.command
|
|
|
-import ly.cli.main
|
|
|
-#from ly import ly.transposition ?
|
|
|
-from abjad import *
|
|
|
+from ly import *
|
|
|
+#import ly.document
|
|
|
+#import ly.cli.command
|
|
|
+#import ly.cli.main
|
|
|
+from ly.pitch import transpose
|
|
|
+from ly.pitch.transpose import ModalTransposer
|
|
|
+from abjad import LilyPondFile, Note
|
|
|
+from abjad.parsers import parse
|
|
|
+from abjad.pitch import NamedPitch
|
|
|
+import re
|
|
|
|
|
|
class SheetMusicEditor(QDialog):
|
|
|
class KeyboardListener(QThread):
|
|
|
@@ -19,13 +24,13 @@ class SheetMusicEditor(QDialog):
|
|
|
def __init__(self, parent=None):
|
|
|
super().__init__(parent=parent)
|
|
|
self.key_to_note = {
|
|
|
- "c": Pitch("c'"),
|
|
|
- "d": Pitch("d'"),
|
|
|
- "e": Pitch("e'"),
|
|
|
- "f": Pitch("f'"),
|
|
|
- "g": Pitch("g'"),
|
|
|
- "a": Pitch("a'"),
|
|
|
- "b": Pitch("b'"),
|
|
|
+ "c": NamedPitch("c'"),
|
|
|
+ "d": NamedPitch("d'"),
|
|
|
+ "e": NamedPitch("e'"),
|
|
|
+ "f": NamedPitch("f'"),
|
|
|
+ "g": NamedPitch("g'"),
|
|
|
+ "a": NamedPitch("a'"),
|
|
|
+ "b": NamedPitch("b'"),
|
|
|
}
|
|
|
|
|
|
def run(self):
|
|
|
@@ -37,7 +42,8 @@ class SheetMusicEditor(QDialog):
|
|
|
|
|
|
def __init__(self):
|
|
|
super(SheetMusicEditor, self).__init__()
|
|
|
- uic.loadUi("qtdesigner_zkouska.ui", self)
|
|
|
+ #uic.loadUi("qtdesigner_zkouska.ui", self)
|
|
|
+ uic.loadUi(os.path.normpath(os.path.join(__file__, "..", "qtdesigner_zkouska.ui")), self)
|
|
|
|
|
|
self.keyboard_listener = self.KeyboardListener()
|
|
|
self.keyboard_listener.note_added.connect(self.add_note_to_file)
|
|
|
@@ -59,7 +65,6 @@ class SheetMusicEditor(QDialog):
|
|
|
self.save_button.clicked.connect(self.saveFile)
|
|
|
self.openFile_button.clicked.connect(self.openFile)
|
|
|
self.new_file_button.clicked.connect(self.create_new_file)
|
|
|
- self.refresh_button.clicked.connect(self.refresh_sheet)
|
|
|
|
|
|
self.c_button.clicked.connect(lambda: self.add_note_to_file("c'"))
|
|
|
self.d_button.clicked.connect(lambda: self.add_note_to_file("d'"))
|
|
|
@@ -69,11 +74,13 @@ class SheetMusicEditor(QDialog):
|
|
|
self.a_button.clicked.connect(lambda: self.add_note_to_file("a'"))
|
|
|
self.b_button.clicked.connect(lambda: self.add_note_to_file("b'"))
|
|
|
|
|
|
- self.lineEdit(self.change_title)
|
|
|
+ #self.lineEdit(self.change_title)
|
|
|
line_edit = QLineEdit()
|
|
|
line_edit.textChanged.connect(lambda text: change_title(title=text))
|
|
|
#tady takové divné, ten první a třetí řádek spolu neinteragují hezky
|
|
|
|
|
|
+ self.refresh_button.clicked.connect(self.refresh_sheet)
|
|
|
+
|
|
|
self.bpm_slider = QSlider(Qt.Horizontal)
|
|
|
self.bpm_slider.setMinimum(1)
|
|
|
self.bpm_slider.setMaximum(10000)
|
|
|
@@ -82,25 +89,35 @@ class SheetMusicEditor(QDialog):
|
|
|
self.bpm_slider.setTickInterval(30)
|
|
|
self.bpm_slider.setTickPosition(QSlider.TicksBelow)
|
|
|
self.bpm_slider.valueChanged.connect(self.bpm_changed)
|
|
|
- self.horizontalLayout_2.addWidget(self.bpm_slider)
|
|
|
+ #self.horizontalLayout_2.addWidget(self.bpm_slider)
|
|
|
|
|
|
- self.actionClose.triggered.connect(exit)
|
|
|
+ #self.actionClose.triggered.connect(exit)
|
|
|
|
|
|
def transpose_up(self):
|
|
|
- pass
|
|
|
- #self.pitch = transposition.transpose_pitch(self.pitch, "1")
|
|
|
+ with open("new_file.ly", "r") as f:
|
|
|
+ code = f.read
|
|
|
+ #transponitko = ModalTransposer(7, 0)
|
|
|
+ tonina = ModalTransposer.getKeyIndex(f)
|
|
|
+ transpose(tonina)
|
|
|
+
|
|
|
+ with open("new_file.ly", "r") as f:
|
|
|
+ f.write(code)
|
|
|
+ #self.pitch = transpose.transpose_pitch(self.pitch, "1")
|
|
|
|
|
|
def transpose_down(self):
|
|
|
pass
|
|
|
- #self.pitch = transposition.transpose_pitch(self.pitch, "-1")
|
|
|
+ #self.pitch = transpose.transpose_pitch(self.pitch, "-1")
|
|
|
|
|
|
|
|
|
def add_becko_to_file(self):
|
|
|
+ with open("new_file.ly", "r") as f:
|
|
|
+ code = f.read()
|
|
|
+
|
|
|
# Get current text in music editor
|
|
|
current_text = self.musicEdit.toPlainText()
|
|
|
|
|
|
# Add znaminko to music editor
|
|
|
- new_text = current_text.rstrip() + "{ \flat }" + " "
|
|
|
+ new_text = current_text.rstrip() + "{ \\flat }" + " "
|
|
|
|
|
|
# Set new text in music editor
|
|
|
self.musicEdit.setPlainText(new_text)
|
|
|
@@ -118,7 +135,7 @@ class SheetMusicEditor(QDialog):
|
|
|
|
|
|
def bpm_changed(slider_val, self):
|
|
|
bpm = slider_val
|
|
|
- with open("test.ly", "r+") as file:
|
|
|
+ with open("new_file.ly", "r+") as file:
|
|
|
data = file.read()
|
|
|
file.seek(0)
|
|
|
file.truncate()
|
|
|
@@ -147,19 +164,22 @@ class SheetMusicEditor(QDialog):
|
|
|
|
|
|
|
|
|
def add_note_to_file(self, note):
|
|
|
+ with open("new_file.ly", "r") as f:
|
|
|
+ code = f.read()
|
|
|
# Get current text in music editor
|
|
|
- current_text = self.musicEdit.toPlainText()
|
|
|
|
|
|
- # Add note to music editor
|
|
|
- new_text = current_text + note + " "
|
|
|
+ # Add note to music editor - v pohodě, protože value tý noty potom dostane v argumetu
|
|
|
+ #ale nefunguje
|
|
|
+ new_text = code + note + " "
|
|
|
|
|
|
# Set new text in music editor
|
|
|
- self.musicEdit.setPlainText(new_text)
|
|
|
+ with open("new_file.ly", "w") as f:
|
|
|
+ f.write(new_text)
|
|
|
|
|
|
def create_new_file(self):
|
|
|
with open("new_file.ly", "w") as f:
|
|
|
f.write("\\version \"2.18.2\"\n\n")
|
|
|
- f.write(f'\\clef {self.clef}\n')
|
|
|
+ f.write(f"\\clef {self.clef}\n")
|
|
|
f.write("\\header {\n")
|
|
|
f.write("\ttitle = \"Untitled\"\n")
|
|
|
f.write("}\n\n")
|
|
|
@@ -167,7 +187,7 @@ class SheetMusicEditor(QDialog):
|
|
|
f.write("\t\\new Staff { }\n")
|
|
|
f.write("\t\\layout { }\n")
|
|
|
f.write("}\n")
|
|
|
- self.pitch = Pitch("c'")
|
|
|
+ #self.pitch = Pitch("c'")
|
|
|
|
|
|
def change_title(self, new_title):
|
|
|
new_title = self.lineEdit.text()
|
|
|
@@ -192,12 +212,13 @@ class SheetMusicEditor(QDialog):
|
|
|
# Create PNG file
|
|
|
png_filename = "sheet_music.png"
|
|
|
lilypond_file.to_pdf(png_filename)
|
|
|
+ #tohle hodně sus
|
|
|
|
|
|
# Load PNG file and display it in the graphics view
|
|
|
pixmap = QPixmap(png_filename)
|
|
|
- self.graphicsView.setScene(QGraphicsScene(self))
|
|
|
+ self.graphicsView.setScene(QGraphicsView(self))
|
|
|
self.graphicsView.scene().addPixmap(pixmap)
|
|
|
- self.graphicsView.fitInView(self.graphicsView.scene().sceneRect(), Qt.KeepAspectRatio)
|
|
|
+ self.graphicsView.fitInView(self.graphicsView.scene().sceneRect())
|
|
|
|
|
|
def saveFile(self):
|
|
|
# Get filename from user
|
|
|
@@ -211,9 +232,8 @@ class SheetMusicEditor(QDialog):
|
|
|
lilypond_file.add_item(self.musicEdit.toPlainText())
|
|
|
|
|
|
# Save LilyPond file
|
|
|
- lilypond_format = LilyPondFormat()
|
|
|
with open(filename, 'w') as f:
|
|
|
- f.write(lilypond_format(lilypond_file))
|
|
|
+ f.write(lilypond_file)
|
|
|
|
|
|
def openFile(self):
|
|
|
# Get filename from user
|
|
|
@@ -227,14 +247,14 @@ class SheetMusicEditor(QDialog):
|
|
|
|
|
|
# Parse LilyPond file
|
|
|
lilypond_file = LilyPondFile()
|
|
|
- lilypond_file.parse(lilypond_text)
|
|
|
+ lilypond_file = parse.parse(lilypond_text)
|
|
|
|
|
|
# Set widget values
|
|
|
- self.titleEdit.setPlainText(lilypond_file.header_title)
|
|
|
- self.musicEdit.setPlainText(lilypond_file.items()[0].to_lilypond())
|
|
|
+ self.titleEdit.setPlainText(lilypond_text.header_title)
|
|
|
+ self.musicEdit.setPlainText(lilypond_text.items()[0].to_lilypond())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
app = QApplication(sys.argv)
|
|
|
editor = SheetMusicEditor()
|
|
|
editor.show()
|
|
|
- sys.exit(app.exec_())
|
|
|
+ sys.exit(app.exec())
|