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

119 lines
3.7KB

  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. Item {
  19. id: root
  20. width:500; height:70
  21. property string file: activeAudioFile.path
  22. property var pixelSamples: []
  23. property var realSamples: activeAudioFile.samples;
  24. property int nSamples: 0
  25. onRealSamplesChanged: {
  26. var max;
  27. var min;
  28. nSamples = realSamples.length
  29. var samplesPerPixel = nSamples / width
  30. for ( var i=width; i>0; --i ) {
  31. min=0;max=0;
  32. for ( var j=0; j<samplesPerPixel; j++ ) {
  33. max = Math.max(realSamples[Math.floor(i*samplesPerPixel+j)],max)
  34. min = Math.min(realSamples[Math.floor(i*samplesPerPixel+j)],min)
  35. }
  36. pixelSamples[i] = (max-min)/4;
  37. }
  38. display.requestPaint()
  39. }
  40. onFileChanged: {
  41. activeAudioFile.calculateFFT()
  42. }
  43. property int select1: 1
  44. property int select2: activeAudioFile.select2 * width / nSamples
  45. onSelect1Changed: {
  46. activeAudioFile.select1 = Math.floor(select1 * nSamples / width)
  47. display.requestPaint()
  48. }
  49. onSelect2Changed: {
  50. display.requestPaint()
  51. }
  52. Canvas {
  53. id: display
  54. anchors.fill: parent
  55. property var waveForm: 0
  56. property var selection: 0
  57. onPaint: {
  58. var zero;
  59. var ctx = getContext("2d")
  60. var val;
  61. ctx.fillStyle = Qt.rgba(255,255,255,1);
  62. ctx.fillRect(0,0,width,height);
  63. ctx.beginPath();
  64. zero = height/2
  65. for ( var i=0; i<pixelSamples.length; i++ ) {
  66. val = pixelSamples[i]*height
  67. ctx.moveTo(i+0.5,zero+val)
  68. ctx.lineTo(i+0.5,zero-val)
  69. }
  70. ctx.lineWidth = 1;
  71. ctx.strokeStyle = "#740098";
  72. waveForm=ctx.stroke();
  73. if ( select1 != -1 ) {
  74. ctx.beginPath()
  75. ctx.moveTo(select1+0.5, 0)
  76. ctx.lineTo(select1+0.5, height)
  77. ctx.strokeWidth = 2
  78. ctx.strokeStyle = "#FCFC10"
  79. ctx.stroke()
  80. if ( select2 != -1 ) {
  81. ctx.moveTo(select2+0.5, 0)
  82. ctx.lineTo(select2+0.5, height)
  83. ctx.strokeWidth = 2
  84. ctx.strokeStyle = "#FCFC10"
  85. ctx.stroke()
  86. ctx.fillStyle = Qt.rgba(90,90,5,.6)
  87. ctx.fillRect(select1,0,select2-select1,height)
  88. }
  89. }
  90. }
  91. MouseArea {
  92. acceptedButtons: Qt.LeftButton
  93. anchors.fill:parent
  94. onPressed: {
  95. if ( mouse.x > 0 )
  96. select1=mouse.x
  97. else select1=1
  98. }
  99. onPositionChanged: {
  100. if ( mouse.x > 0 )
  101. select1=mouse.x
  102. else select1=1
  103. activeAudioFile.calculateFFT()
  104. }
  105. onReleased: {
  106. activeAudioFile.calculateFFT()
  107. }
  108. }
  109. }
  110. }