2 Commits 5eec9ae65a ... c9dd94e700

Author SHA1 Message Date
  Adam Dominec c9dd94e700 received by mail 2 years ago
  Adam Dominec 72e7aa293c received by mail 2 years ago
2 changed files with 93 additions and 79 deletions
  1. 57 37
      main_m.py
  2. 36 42
      qtdesigner_zkouska.ui

+ 57 - 37
main_m.py

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

+ 36 - 42
qtdesigner_zkouska.ui

@@ -6,46 +6,20 @@
    <rect>
    <rect>
     <x>0</x>
     <x>0</x>
     <y>0</y>
     <y>0</y>
-    <width>969</width>
-    <height>625</height>
+    <width>893</width>
+    <height>613</height>
    </rect>
    </rect>
   </property>
   </property>
   <property name="windowTitle">
   <property name="windowTitle">
    <string>noticky</string>
    <string>noticky</string>
   </property>
   </property>
-  <widget class="QWidget" name="verticalLayoutWidget_2">
-   <property name="geometry">
-    <rect>
-     <x>870</x>
-     <y>150</y>
-     <width>82</width>
-     <height>54</height>
-    </rect>
-   </property>
-   <layout class="QVBoxLayout" name="verticalLayout_2">
-    <item>
-     <widget class="QPushButton" name="pushButton_3">
-      <property name="text">
-       <string>+</string>
-      </property>
-     </widget>
-    </item>
-    <item>
-     <widget class="QPushButton" name="pushButton_4">
-      <property name="text">
-       <string>-</string>
-      </property>
-     </widget>
-    </item>
-   </layout>
-  </widget>
   <widget class="QWidget" name="verticalLayoutWidget">
   <widget class="QWidget" name="verticalLayoutWidget">
    <property name="geometry">
    <property name="geometry">
     <rect>
     <rect>
-     <x>610</x>
+     <x>490</x>
      <y>0</y>
      <y>0</y>
-     <width>131</width>
-     <height>98</height>
+     <width>141</width>
+     <height>121</height>
     </rect>
     </rect>
    </property>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout">
    <layout class="QVBoxLayout" name="verticalLayout">
@@ -108,15 +82,15 @@
   <widget class="QWidget" name="horizontalLayoutWidget_3">
   <widget class="QWidget" name="horizontalLayoutWidget_3">
    <property name="geometry">
    <property name="geometry">
     <rect>
     <rect>
-     <x>370</x>
-     <y>30</y>
+     <x>0</x>
+     <y>20</y>
      <width>168</width>
      <width>168</width>
      <height>41</height>
      <height>41</height>
     </rect>
     </rect>
    </property>
    </property>
    <layout class="QHBoxLayout" name="horizontalLayout_3">
    <layout class="QHBoxLayout" name="horizontalLayout_3">
     <item>
     <item>
-     <widget class="QPushButton" name="b">
+     <widget class="QPushButton" name="becko_button">
       <property name="text">
       <property name="text">
        <string>♭</string>
        <string>♭</string>
       </property>
       </property>
@@ -134,8 +108,8 @@
   <widget class="QWidget" name="verticalLayoutWidget_3">
   <widget class="QWidget" name="verticalLayoutWidget_3">
    <property name="geometry">
    <property name="geometry">
     <rect>
     <rect>
-     <x>750</x>
-     <y>10</y>
+     <x>630</x>
+     <y>0</y>
      <width>170</width>
      <width>170</width>
      <height>51</height>
      <height>51</height>
     </rect>
     </rect>
@@ -185,8 +159,8 @@
    <property name="geometry">
    <property name="geometry">
     <rect>
     <rect>
      <x>0</x>
      <x>0</x>
-     <y>70</y>
-     <width>599</width>
+     <y>100</y>
+     <width>351</width>
      <height>25</height>
      <height>25</height>
     </rect>
     </rect>
    </property>
    </property>
@@ -302,10 +276,10 @@
   <widget class="QWidget" name="verticalLayoutWidget_4">
   <widget class="QWidget" name="verticalLayoutWidget_4">
    <property name="geometry">
    <property name="geometry">
     <rect>
     <rect>
-     <x>770</x>
-     <y>60</y>
-     <width>131</width>
-     <height>51</height>
+     <x>180</x>
+     <y>30</y>
+     <width>171</width>
+     <height>61</height>
     </rect>
     </rect>
    </property>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout_4">
    <layout class="QVBoxLayout" name="verticalLayout_4">
@@ -321,6 +295,26 @@
     </item>
     </item>
    </layout>
    </layout>
   </widget>
   </widget>
+  <widget class="QPlainTextEdit" name="musicEdit">
+   <property name="geometry">
+    <rect>
+     <x>13</x>
+     <y>129</y>
+     <width>421</width>
+     <height>471</height>
+    </rect>
+   </property>
+  </widget>
+  <widget class="QGraphicsView" name="graphicsView">
+   <property name="geometry">
+    <rect>
+     <x>450</x>
+     <y>130</y>
+     <width>431</width>
+     <height>471</height>
+    </rect>
+   </property>
+  </widget>
  </widget>
  </widget>
  <resources/>
  <resources/>
  <connections/>
  <connections/>