#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright 2020, Nils Hilbricht, Germany ( https://www.hilbricht.net )
This file is part of the Laborejo Software Suite ( https://www.laborejo.org ),
Laborejo2 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
Most commands work in the appending position (last position in a track) and apply to the item before it.
Use it to apply dots, sharps and flats on the item you just inserted without moving the cursor back and forth.
"), translate("About", "Learn the keyboard shortcuts! Laborejo is designed to work with the keyboard alone and with midi instruments for full speed.
Everytime you grab your mouse you loose concentration, precision and time."), translate("About", "Spread/shrink the space between notes with Ctrl+Shift+Mousewheel or Ctrl+Shift with Plus and Minus.
"), translate("About", "Click with the left mouse button to set the cursor to that position. Hold Shift to create a selection.
"), translate("About", "Most commands can be applied to single notes and selections equally.
Use Shift + movement-keys to create selections.
"), translate("About", "Blocks and Tracks can be moved in Block-View Mode [F6]. Use Shift+Middle Mouse Button to move blocks and Alt+Middle to reorder tracks.
"), translate("About", "There are no empty measures/bars.
Use Multi Measure Rests[R] instead. You need to have a metrical instruction for that [M].
"), translate("About", "Many Music Items like clefs can only be inserted, not edited. They are however such simplistic that delete-and-reinsert is equally time-efficient.
"), translate("About", "All notes should be considered non-transposing. Treat everything as 'in C'.
That said, there is a semitone transposition in the Track Properties [Ctrl+T].
"), translate("About", "Upbeats/anacrusis can be set per-track in the Track Properties [Ctrl+T].
"), translate("About", "There is no key-rebinding except numpad-shortcuts.
"), translate("About", "Hidden tracks still output sound.
"), translate("About", "Non-audible tracks still output instrument changes and CCs so that they can be switched on again in the middle of playback.
"), ] + About.didYouKnow super().__init__() #New menu entries and template-menu overrides self.menu.addMenuEntry("menuDebug", "actionRedrawAllTracks", "Redraw all Tracks") self.menu.connectMenuEntry("actionSave", api.save) self.menu.hideSubmenu("menuFile") self.menu.hideSubmenu("menuGeneric") api.callbacks.setCursor.append(self.updateStatusBar) #returns a dict. This get's called after loading the file so the status bar is filled on self.show #Create the Main Widgets in the Stacked Widget self.scoreView = ScoreView(self) self.ui.mainStackWidget.addWidget(self.scoreView) self.ui.mainStackWidget.setCurrentIndex(self.ui.mainStackWidget.indexOf(self.scoreView)) self.trackEditor = QtWidgets.QScrollArea() self.trackEditor.setWidgetResizable(True) self.actualTrackEditor = TrackEditor(self) self.trackEditor.setWidget(self.actualTrackEditor) self.ui.actionData_Editor.setChecked(False) self.ui.mainStackWidget.addWidget(self.trackEditor) #Bind shortcuts to actions (as init effect) #TODO: Integrate better into template menu system. self.menuActionDatabase = MenuActionDatabase(self) #The menu needs to be started before api.startEngine #Make toolbars unclosable ##self.ui.toolBar.setContextMenuPolicy(QtCore.Qt.PreventContextMenu) #only for right mouse clicks. Keyboard context menu key still works. ##self.ui.leftToolBar.setContextMenuPolicy(QtCore.Qt.PreventContextMenu) self.setContextMenuPolicy(QtCore.Qt.NoContextMenu) #Make toolbars unclosable by preventing the main window from having context menus. #The statusbar is intended for tooltips. To make it permanent we add our own widget self.statusLabel = QtWidgets.QLabel() self.statusBar().insertPermanentWidget(0, self.statusLabel) self.scoreView.setFocus() #So the user can start typing from moment 0. self.start() #Inherited from template main window #This shows the GUI, or not, depends on the NSM gui save setting. We need to call that after the menu, otherwise the about dialog will block and then we get new menu entries, which looks strange. stepMidiInput.start() #imported directly. Handles everything else internally, we just need to start it after the engine somehow. Which is here. #Populate the left toolbar. The upper toolbar is created in menu.py self.ui.leftToolBar.addWidget(LeftToolBarPrevailingDuration(self)) #needs stepmidiinput started #Now all tracks and items from a loaded backend-file are created. We can setup the initial editMode and viewPort. self.scoreView.updateMode() #hide CCs at program start and other stuff #self.scoreView.scoreScene.grid.redrawTickGrid() #Init the grid only after everything got loaded and drawn to prevent a gap in the display. #TODO: which might be a bug. but this here works fine. #There is so much going on in the engine, we never reach a save status on load. #Here is the crowbar-method. self.nsmClient.announceSaveStatus(isClean = True) api.connectModMidiMerger() def zoom(self, scaleFactor:float): """Scale factor is absolute""" self.scoreView.zoom(scaleFactor) def stretchXCoordinates(self, factor:float): self.scoreView.stretchXCoordinates(factor) def updateStatusBar(self, exportCursorDict): """Every cursor movement updates the statusBar message""" c = exportCursorDict try: i = c["item"] except: print (c) if i: ly = i.lilypond(carryLilypondRanges = {}) if (not ly) or len(ly) > 13: ly = "" else: ly = "Lilypond: {}".format(ly.replace("<", "<").replace(">", ">")) itemMessage = "Item: {} {}".format(i.__class__.__name__, ly) else: itemMessage = "" #Appending positionMessage = "Pos: {} Ticks: {} Pitch: {}".format(c["position"], c["tickindex"], c["lilypondPitch"]) message = "{} | {}".format(itemMessage, positionMessage) #self.statusBar().showMessage(message) #overriden by tool tips, even empty ones self.statusLabel.setText(message) def toggleMainView(self): if self.ui.actionData_Editor.isChecked(): self.ui.mainStackWidget.setCurrentIndex(self.ui.mainStackWidget.indexOf(self.trackEditor)) self.scoreView.setEnabled(False) #disables shortcut like cursor movement, but not all of them. self.menuActionDatabase.writeProtection(True) self.trackEditor.setEnabled(True) else: self.ui.mainStackWidget.setCurrentIndex(self.ui.mainStackWidget.indexOf(self.scoreView)) self.scoreView.setEnabled(True) self.menuActionDatabase.writeProtection(False) self.scoreView.updateMode() self.trackEditor.setEnabled(False) class LeftToolBarPrevailingDuration(QtWidgets.QLabel): def __init__(self, mainWindow): super().__init__(self.makeText(api.D4)) self.mainWindow = mainWindow self.setFont(constantsAndConfigs.musicFont) #TODO replace with svg api.callbacks.prevailingBaseDurationChanged.append(self.changed) def makeText(self, baseDuration): if not stepMidiInput.midiInIsActive: return "" labelText = "" for i in (api.D1, api.D2, api.D4, api.D8, api.D16): #,api.DB, api.DL): if i == baseDuration: labelText += "" labelText += constantsAndConfigs.realNoteDisplay[i] if i == baseDuration: labelText += "" labelText += "