Skip to content
Snippets Groups Projects
Instrument.qml 1.86 KiB
Newer Older
/** This file is part of Nootka (http://nootka.sf.net)               *
SeeLook's avatar
SeeLook committed
 * Copyright (C) 2017-2021 by Tomasz Bojczuk (seelook@gmail.com)     *
 * on the terms of GNU GPLv3 license (http://www.gnu.org/licenses)   */
import QtQuick 2.12
SeeLook's avatar
SeeLook committed
Flickable {
SeeLook's avatar
SeeLook committed
  property var instrument: null
  property var score: null
SeeLook's avatar
SeeLook committed
  boundsBehavior: Flickable.StopAtBounds
  height: sizable.height
  width: nootkaWindow.width * (GLOB.instrument.isSax ? 0.15 : 1)
  y: GLOB.instrument.isSax ? 0 : nootkaWindow.contentItem.height - height
  x: GLOB.instrument.isSax ? parent.width - width : 0
  z: instrument && instrument.scale > 1.0 ? 7 : (GLOB.instrument.isSax ? 6 : 1)
  contentWidth: sizable.width
  contentHeight: sizable.height

  Item {
    id: sizable
    width: instrument ? instrument.width * instrument.scale : 0
    height: instrument ? instrument.height * instrument.scale : 0
  }
SeeLook's avatar
SeeLook committed

  Component.onCompleted: setInstrument()

  Connections {
    target: GLOB
    onInstrumentChanged: setInstrument()
  property real hiFactor: GLOB.instrument.getItemHeight(100) / 100.0
SeeLook's avatar
SeeLook committed
  function setInstrument() {
    if (instrument) {
      score.parent.scale = 1.0
SeeLook's avatar
SeeLook committed
      instrument.destroy()
SeeLook's avatar
SeeLook committed
    if (GLOB.instrument.type)
      instrument = Qt.createComponent("qrc:/instruments/" +  GLOB.instrument.qmlFile + ".qml").createObject(sizable)
SeeLook's avatar
SeeLook committed
    else
      instrument = null
    if (GLOB.instrument.piano)
SeeLook's avatar
SeeLook committed
      instrument.setAmbitus(score.scoreObj.lowestNote(), score.scoreObj.highestNote())
    NOO.instrument = instrument
    if (instrument && !GLOB.instrument.isSax)
      score.parent.scale = Qt.binding(function() { return (1.0 - hiFactor * instrument.scale) / (1 - hiFactor) })
    enabled: GLOB.instrument.piano
    onClefChanged: instrument.setAmbitus(score.scoreObj.lowestNote(), score.scoreObj.highestNote())