|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- // 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 <http://www.gnu.org/licenses/>.
- //
- import QtQuick 2.3
-
- Item {
- id: root
- width:500; height:70
-
- property string file: activeAudioFile.path
- property var pixelSamples: []
- property var realSamples: activeAudioFile.samples;
- property int nSamples: 0
- onRealSamplesChanged: {
- var max;
- var min;
- nSamples = realSamples.length
- var samplesPerPixel = nSamples / width
- for ( var i=width; i>0; --i ) {
- min=0;max=0;
- for ( var j=0; j<samplesPerPixel; j++ ) {
- max = Math.max(realSamples[Math.floor(i*samplesPerPixel+j)],max)
- min = Math.min(realSamples[Math.floor(i*samplesPerPixel+j)],min)
- }
- pixelSamples[i] = (max-min)/4;
- }
-
- display.requestPaint()
- }
- onFileChanged: {
- activeAudioFile.calculateFFT()
- }
-
- property int select1: 1
- property int select2: activeAudioFile.select2 * width / nSamples
- onSelect1Changed: {
- activeAudioFile.select1 = Math.floor(select1 * nSamples / width)
- display.requestPaint()
- }
- onSelect2Changed: {
- display.requestPaint()
- }
-
- Canvas {
- id: display
- anchors.fill: parent
- property var waveForm: 0
- property var selection: 0
- onPaint: {
-
- var zero;
- var ctx = getContext("2d")
- var val;
-
- ctx.fillStyle = Qt.rgba(255,255,255,1);
- ctx.fillRect(0,0,width,height);
- ctx.beginPath();
- zero = height/2
- for ( var i=0; i<pixelSamples.length; i++ ) {
- val = pixelSamples[i]*height
- ctx.moveTo(i+0.5,zero+val)
- ctx.lineTo(i+0.5,zero-val)
- }
- ctx.lineWidth = 1;
- ctx.strokeStyle = "#740098";
- waveForm=ctx.stroke();
- if ( select1 != -1 ) {
- ctx.beginPath()
- ctx.moveTo(select1+0.5, 0)
- ctx.lineTo(select1+0.5, height)
- ctx.strokeWidth = 2
- ctx.strokeStyle = "#FCFC10"
- ctx.stroke()
- if ( select2 != -1 ) {
- ctx.moveTo(select2+0.5, 0)
- ctx.lineTo(select2+0.5, height)
- ctx.strokeWidth = 2
- ctx.strokeStyle = "#FCFC10"
- ctx.stroke()
- ctx.fillStyle = Qt.rgba(90,90,5,.6)
- ctx.fillRect(select1,0,select2-select1,height)
- }
- }
- }
-
- MouseArea {
- acceptedButtons: Qt.LeftButton
- anchors.fill:parent
- onPressed: {
- if ( mouse.x > 0 )
- select1=mouse.x
- else select1=1
- }
- onPositionChanged: {
- if ( mouse.x > 0 )
- select1=mouse.x
- else select1=1
- activeAudioFile.calculateFFT()
- }
- onReleased: {
- activeAudioFile.calculateFFT()
- }
- }
- }
- }
|