|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- // 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
- import QtQuick.Controls 1.2
-
- Item {
- id:root
- anchors.fill:parent
-
- property int nKeys: 17
- property var amps: [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- property var detunes: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- property var pitches:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- property var transpose:0
- property var marks: [1,3,6,8,10,13,15]
- property var inSpectrum:[]
-
- function calculate_spectrum() {
- calculate_grid() // do this only when there is a new grid, not for every keypress!!! (how to know???)
- var y=[];
- for ( var i=0;i<nKeys;i++ ){
- if(root.amps[i]) {
-
- for(var j=0;j<inSpectrum.length/2;j++){
- y.push(root.pitches[i]*inSpectrum[2*j])
- y.push(root.amps[i]*inSpectrum[2*j+1])
- }
- }
- }
-
- buffer.spectrumF0=y
- }
- function calculate_grid() {
-
- var grid_delta = []
- for(var i=0;i<buffer.grid.length; i++) {
- var upper;
- if(i==buffer.grid.length-1)upper=1200
- else upper = buffer.grid[i+1]
- grid_delta.push(upper-buffer.grid[i])
- }
-
- var root_pitch = buffer.gridPitch * Math.pow(2,(-buffer.grid[buffer.gridTunedStep]/1200))
-
- for(var i=0; i<nKeys; i++){
- var reg= root.transpose + Math.floor(i/buffer.grid.length)
- root.pitches[i] =
- root_pitch//buffer.gridPitch
- * Math.pow(2,reg+(buffer.grid[i%buffer.grid.length]+100*root.detunes[i])/1200)
- }
-
- }
-
- Rectangle {
- anchors.fill:parent
- color:"#333"
- }
- ListView {
- id:keyList
- anchors.fill: parent
- spacing: 1
- clip: true
- model:parent.nKeys
- orientation: ListView.Horizontal
- delegate: keyComponent
- }
- /* Button {
- anchors.right:parent.right
- anchors.bottom:parent.bottom
- text:qsTr("All Cents Zero")
- onClicked:{
- root.detunes=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- calculate_spectrum()
- }
- }*/
- Item {
- id:worker
-
- function pitch_ratios(){
-
- }
-
- }
-
-
- Component {
- id:keyComponent
-
- Item {
- width:30
- height:parent.height
- id:key
- property real amp: 0.0
- property real detune: 0.0 // cents
-
- Rectangle {
- anchors.fill:parent
- color: {
- if(marks.indexOf(index%buffer.grid.length)<0)
- return "ivory"
- else
- return "black"
- }
- }
- Column {
- width:29
- Text {text:index;color:"gray"}
- Text {
- anchors.right:parent.right
- text:Math.floor(key.detune*100);
- color:"gray"
- }
- }
- MouseArea {
- anchors.fill: parent
- acceptedButtons: Qt.LeftButton | Qt.RightButton
- onClicked: {
- if (mouse.button & Qt.LeftButton) {
- root.amps[index] = Math.max(0,0.9- mouseY/parent.height)
- parent.amp = root.amps[index]
- root.calculate_spectrum()
- } else {
- root.detunes[index] = 0.5 - mouseY/parent.height
- parent.detune = root.detunes[index]
- root.calculate_spectrum()
- }
- }
- }
- Rectangle {
- anchors.bottom:parent.bottom
- height: parent.amp*(1/0.9)*parent.height; width:parent.width
- color:"#a0aaaaaa"
- }
- Rectangle {
- y:Math.min(0.5-parent.detune,0.5)*parent.height;
- height: Math.abs(parent.detune)*parent.height; width:parent.width
- color:"#5000aa00"
- }
- }
- }
- }
|