Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

156 lines
3.8KB

  1. // tonalisa - software to look at overtone-structures
  2. // Copyright (C) 2016 Dominik Schmidt-Philipp
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. //
  17. import QtQuick 2.3
  18. import QtQuick.Controls 1.2
  19. Item {
  20. id:root
  21. anchors.fill:parent
  22. property int nKeys: 17
  23. property var amps: [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  24. property var detunes: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  25. property var pitches:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  26. property var transpose:0
  27. property var marks: [1,3,6,8,10,13,15]
  28. property var inSpectrum:[]
  29. function calculate_spectrum() {
  30. calculate_grid() // do this only when there is a new grid, not for every keypress!!! (how to know???)
  31. var y=[];
  32. for ( var i=0;i<nKeys;i++ ){
  33. if(root.amps[i]) {
  34. for(var j=0;j<inSpectrum.length/2;j++){
  35. y.push(root.pitches[i]*inSpectrum[2*j])
  36. y.push(root.amps[i]*inSpectrum[2*j+1])
  37. }
  38. }
  39. }
  40. buffer.spectrumF0=y
  41. }
  42. function calculate_grid() {
  43. var grid_delta = []
  44. for(var i=0;i<buffer.grid.length; i++) {
  45. var upper;
  46. if(i==buffer.grid.length-1)upper=1200
  47. else upper = buffer.grid[i+1]
  48. grid_delta.push(upper-buffer.grid[i])
  49. }
  50. var root_pitch = buffer.gridPitch * Math.pow(2,(-buffer.grid[buffer.gridTunedStep]/1200))
  51. for(var i=0; i<nKeys; i++){
  52. var reg= root.transpose + Math.floor(i/buffer.grid.length)
  53. root.pitches[i] =
  54. root_pitch//buffer.gridPitch
  55. * Math.pow(2,reg+(buffer.grid[i%buffer.grid.length]+100*root.detunes[i])/1200)
  56. }
  57. }
  58. Rectangle {
  59. anchors.fill:parent
  60. color:"#333"
  61. }
  62. ListView {
  63. id:keyList
  64. anchors.fill: parent
  65. spacing: 1
  66. clip: true
  67. model:parent.nKeys
  68. orientation: ListView.Horizontal
  69. delegate: keyComponent
  70. }
  71. /* Button {
  72. anchors.right:parent.right
  73. anchors.bottom:parent.bottom
  74. text:qsTr("All Cents Zero")
  75. onClicked:{
  76. root.detunes=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  77. calculate_spectrum()
  78. }
  79. }*/
  80. Item {
  81. id:worker
  82. function pitch_ratios(){
  83. }
  84. }
  85. Component {
  86. id:keyComponent
  87. Item {
  88. width:30
  89. height:parent.height
  90. id:key
  91. property real amp: 0.0
  92. property real detune: 0.0 // cents
  93. Rectangle {
  94. anchors.fill:parent
  95. color: {
  96. if(marks.indexOf(index%buffer.grid.length)<0)
  97. return "ivory"
  98. else
  99. return "black"
  100. }
  101. }
  102. Column {
  103. width:29
  104. Text {text:index;color:"gray"}
  105. Text {
  106. anchors.right:parent.right
  107. text:Math.floor(key.detune*100);
  108. color:"gray"
  109. }
  110. }
  111. MouseArea {
  112. anchors.fill: parent
  113. acceptedButtons: Qt.LeftButton | Qt.RightButton
  114. onClicked: {
  115. if (mouse.button & Qt.LeftButton) {
  116. root.amps[index] = Math.max(0,0.9- mouseY/parent.height)
  117. parent.amp = root.amps[index]
  118. root.calculate_spectrum()
  119. } else {
  120. root.detunes[index] = 0.5 - mouseY/parent.height
  121. parent.detune = root.detunes[index]
  122. root.calculate_spectrum()
  123. }
  124. }
  125. }
  126. Rectangle {
  127. anchors.bottom:parent.bottom
  128. height: parent.amp*(1/0.9)*parent.height; width:parent.width
  129. color:"#a0aaaaaa"
  130. }
  131. Rectangle {
  132. y:Math.min(0.5-parent.detune,0.5)*parent.height;
  133. height: Math.abs(parent.detune)*parent.height; width:parent.width
  134. color:"#5000aa00"
  135. }
  136. }
  137. }
  138. }