// tonalisa - software to look at overtone-structures // Copyright (C) 2016 Dominik Schmidt-Philipp // // This program 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 . // import QtQuick 2.0 Item { id:root width:512; height:300 property string file: activeAudioFile.path property real sampleRate: activeAudioFile.sampleRate property int fftSize: activeAudioFile.npts property var fftData: activeAudioFile.spectrum property var grid: [[100,300,500,1000,2000,5000,10000]] property var pixelData: [] property real leftHz: 0 property real rightHz: 10000 property real max:0 property real min:0 function binToHertz(bin) { return bin * sampleRate / fftSize } function hertzToBin(hertz) { return Math.floor(hertz * fftSize / sampleRate) } function binToX(bin) { return width * (binToHertz(bin)-leftHz)/(rightHz-leftHz) } onFftDataChanged: { display.requestPaint() } onLeftHzChanged: { display.requestPaint() } onRightHzChanged: { display.requestPaint() } Canvas { id: display anchors.fill: parent function scale(val){ return -Math.log(val/sampleRate) * 8 } onPaint: { var ctx = getContext("2d") ctx.fillStyle = Qt.rgba(255,255,255,1); ctx.fillRect(0,0,width,height); ctx.beginPath() var i = hertzToBin(leftHz) ctx.moveTo(binToX(i),scale(fftData[i])) while ( i