Skip to content
Snippets Groups Projects
Instrument.qml 2.05 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)   */
SeeLook's avatar
SeeLook committed
import QtQuick 2.12
SeeLook's avatar
SeeLook committed
Flickable {
SeeLook's avatar
SeeLook committed
    id: instrFlick

    property var instrument: null
    property var score: null
    property real hiFactor: GLOB.instrument.getItemHeight(100) / 100

    function setInstrument() {
        if (instrument) {
            score.parent.scale = 1;
            instrument.destroy();
        }
        if (GLOB.instrument.type)
            instrument = Qt.createComponent("qrc:/instruments/" + GLOB.instrument.qmlFile + ".qml").createObject(sizable);
        else
            instrument = null;
        if (GLOB.instrument.piano)
            instrument.setAmbitus(score.scoreObj.lowestNote(), score.scoreObj.highestNote());

        NOO.instrument = instrument;
        if (instrument && !GLOB.instrument.isSax)
            score.parent.scale = Qt.binding(function() {
            return (1 - hiFactor * instrument.scale) / (1 - hiFactor);
        });
SeeLook's avatar
SeeLook committed
    }
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 ? 7 : (GLOB.instrument.isSax ? 6 : 1)
    contentWidth: sizable.width
    contentHeight: sizable.height
    Component.onCompleted: setInstrument()

    Item {
        id: sizable

        width: instrument ? instrument.width * instrument.scale : 0
        height: instrument ? instrument.height * instrument.scale : 0
SeeLook's avatar
SeeLook committed
    Connections {
        target: GLOB
        function onInstrumentChanged() : void { setInstrument() }
SeeLook's avatar
SeeLook committed
    }
SeeLook's avatar
SeeLook committed
    Connections {
        target: score
        enabled: GLOB.instrument.piano
        function onClefChanged() : void { instrument.setAmbitus(score.scoreObj.lowestNote(), score.scoreObj.highestNote()) }
SeeLook's avatar
SeeLook committed
    }