|
- // 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
- import QtQuick.LocalStorage 2.0
-
- Item {
- id: root
- width: parent.width; height:parent.height
-
- property alias model: scaleModel
- property alias list: scaleList
- property var db;
-
- Rectangle {
- anchors.fill: parent
- }
-
- Button {
- id: newScale
- text: "new"
- x:0;y:0
- onClicked: {
- scaleList.model.append({
- "name":"equal",
- "tunedStep":9,
- "pitch":440.0,
- "highest":0,
- "lowest":0,
- "cents":"[0,100,200,300,400,500,600,700,800,900,1000,1100]"
- });
- scaleList.currentIndex = scaleModel.count-1
- }
- }
- Button {
- id: updateScale
- text: "update"
- x:80;y:0
- onClicked: {
- scaleList.model.get(scaleList.currentIndex).name = sEname.text;
- scaleList.model.get(scaleList.currentIndex).tunedStep = sEtunedStep.text;
- scaleList.model.get(scaleList.currentIndex).pitch = sEpitch.text;
- scaleList.model.get(scaleList.currentIndex).lowest = sElowest.text;
- scaleList.model.get(scaleList.currentIndex).highest = sEhighest.text;
- scaleList.model.get(scaleList.currentIndex).cents = JSON.stringify(scaleEditor.centBuffer);
- }
- }
- Button {
- id: deleteScale
- text: "delete"
- anchors.right:parent.right;
- onClicked: {
- scaleList.model.remove(scaleList.currentIndex)
- }
- }
- Item {
- id: scaleEditor
- x:2;y:30
- width:parent.width/2-4
- height:parent.height-40
-
- property var index:0
- property var centBuffer:[]
-
- TextField {
- height:18
- x:10;y:0
- id: sEname
- }
- Text {x:120;y:0;text:"name" }
- TextField {
- height:18
- x:10;y:20
- id: sEpitch
- }
- Text {x:120;y:20;text:"ReferencePitch (Hz)" }
- TextField {
- height:18
- x:10;y:40
- id: sEtunedStep
- }
- Text {x:120;y:40;text:"index of tuned Step" }
- TextField {
- height:18
- x:10;y:60
- id: sEhighest
- }
- Text {x:120;y:60;text:"upper limit (Hz)" }
- TextField {
- height:18
- x:10;y:80
- id: sElowest
- }
- Text {x:120;y:80;text:"lower limit (Hz)" }
- ListView {
- id:sEcents
- x: 10;y:100
- height:200
- model:[10,20,30]
- delegate: Item {
- height:16
- TextField {
- height:16;width:40;
- text:modelData
- onTextChanged: {
- scaleEditor.centBuffer[index]=text
- }
- }
- Text { x:45; text: "cents" }
- }
- }
- }
-
- function initDatabase() {
- db = LocalStorage.openDatabaseSync(
- "ExtendedFrequencyToolDB",
- "0.2",
- "Scales and Spectra",
- 100000)
- db.transaction( function(tx) {
- console.log("... create 'scales' table")
- tx.executeSql(
- // all entries for scales are in cents, which are saved as REALs
- 'CREATE TABLE IF NOT EXISTS scales('
- +'id INTEGER,'
- +'name TEXT,'
- +'tunedStep INTEGER,'
- +'pitch REAL,' // Hz
- +'highest REAL,'
- +'lowest REAL,'
- +'cents TEXT)'
- )
- });
- }
-
- function storeData() {
- if(!db) { return; }
- db.transaction( function(tx) {
- for (var i=0;i<scaleModel.count;i++) {
- var item = scaleModel.get(i);
- var result = tx.executeSql('SELECT * FROM scales WHERE id = "'+i+'"');
- if(result.rows.length === 1) { // use update
- console.log("update")
- result = tx.executeSql('UPDATE scales SET name=?, tunedStep=?, pitch=?, highest=?, lowest=?, cents=? WHERE id="'+i+'"',[
- item.name,
- item.tunedStep,
- item.pitch,
- item.highest,
- item.lowest,
- item.cents
- ]);
- } else { // use insert
- console.log("insert")
- result = tx.executeSql('INSERT INTO scales VALUES (?,?,?,?,?,?,?)',[
- i,
- item.name,
- item.tunedStep,
- item.pitch,
- item.highest,
- item.lowest,
- item.cents
- ])
- }
- }
- });
- }
-
- function readData() {
- if(!db){return;}
- db.transaction( function(tx){
- console.log("... read data from 'scale' table")
- var result = tx.executeSql('SELECT * FROM scales');
- if ( result.rows.length > 0 ) {
- for ( var i=0;i<result.rows.length;i++ ) {
- scaleList.model.append(result.rows.item(i))
- }
- } else {
- console.log("no scales in database")
- }
- });
- }
- Component.onCompleted: {
- initDatabase();
- readData();
- }
- Component.onDestruction: {
- storeData()
- }
-
- ListModel {
- id:scaleModel
- }
-
- ListView {
- id:scaleList
- anchors.fill:parent
- anchors.margins: 2
- anchors.leftMargin:parent.width/2+2
- anchors.topMargin:20
- clip:true
- model:scaleModel
- delegate:scaleDelegate
-
- spacing:1
- focus:true
- onCurrentItemChanged: {
- var item = scaleModel.get(currentIndex);
- // populate editor
- sEname.text = item.name
- sEpitch.text = item.pitch
- sEtunedStep.text = item.tunedStep
- sElowest.text = item.lowest
- sEhighest.text = item.highest
- sEcents.model=JSON.parse(item.cents)
-
- spiral.gridTunedStep = item.tunedStep
- spiral.gridLowest = item.lowest
- spiral.gridHighest = item.highest
- spiral.gridPitch = item.pitch
- spiral.grid = JSON.parse(item.cents)
-
- karthesisch.gridTunedStep = item.tunedStep
- karthesisch.gridLowest = item.lowest
- karthesisch.gridHighest = item.highest
- karthesisch.gridPitch = item.pitch
- karthesisch.grid = JSON.parse(item.cents)
-
- dissonanceCurve.gridTunedStep = item.tunedStep
- dissonanceCurve.gridLowest = item.lowest
- dissonanceCurve.gridHighest = item.highest
- dissonanceCurve.gridPitch = item.pitch
- dissonanceCurve.grid = JSON.parse(item.cents)
-
- buffer.grid = JSON.parse(item.cents)
- }
- }
- Component {
- id: scaleDelegate
- ScaleListElement {
- text:name
- }
- }
- }
|