2 Commit-ok 5eec9ae65a ... c9dd94e700

Szerző SHA1 Üzenet Dátum
  Adam Dominec c9dd94e700 received by mail 2 éve
  Adam Dominec 72e7aa293c received by mail 2 éve
2 módosított fájl, 93 hozzáadás és 79 törlés
  1. 57 37
      main_m.py
  2. 36 42
      qtdesigner_zkouska.ui

+ 57 - 37
main_m.py

@@ -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())

+ 36 - 42
qtdesigner_zkouska.ui

@@ -6,46 +6,20 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>969</width>
-    <height>625</height>
+    <width>893</width>
+    <height>613</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>noticky</string>
   </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">
    <property name="geometry">
     <rect>
-     <x>610</x>
+     <x>490</x>
      <y>0</y>
-     <width>131</width>
-     <height>98</height>
+     <width>141</width>
+     <height>121</height>
     </rect>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout">
@@ -108,15 +82,15 @@
   <widget class="QWidget" name="horizontalLayoutWidget_3">
    <property name="geometry">
     <rect>
-     <x>370</x>
-     <y>30</y>
+     <x>0</x>
+     <y>20</y>
      <width>168</width>
      <height>41</height>
     </rect>
    </property>
    <layout class="QHBoxLayout" name="horizontalLayout_3">
     <item>
-     <widget class="QPushButton" name="b">
+     <widget class="QPushButton" name="becko_button">
       <property name="text">
        <string>♭</string>
       </property>
@@ -134,8 +108,8 @@
   <widget class="QWidget" name="verticalLayoutWidget_3">
    <property name="geometry">
     <rect>
-     <x>750</x>
-     <y>10</y>
+     <x>630</x>
+     <y>0</y>
      <width>170</width>
      <height>51</height>
     </rect>
@@ -185,8 +159,8 @@
    <property name="geometry">
     <rect>
      <x>0</x>
-     <y>70</y>
-     <width>599</width>
+     <y>100</y>
+     <width>351</width>
      <height>25</height>
     </rect>
    </property>
@@ -302,10 +276,10 @@
   <widget class="QWidget" name="verticalLayoutWidget_4">
    <property name="geometry">
     <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>
    </property>
    <layout class="QVBoxLayout" name="verticalLayout_4">
@@ -321,6 +295,26 @@
     </item>
    </layout>
   </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>
  <resources/>
  <connections/>