@_000407/transpose.js 中文文档教程

发布于 4年前 浏览 8 项目主页 更新于 3年前

transpose.js - Chord Transposition made simple

这是一个简单的实用程序,用于移调给定乐曲中的和弦。 一旦包含和弦的元素的 CSS 选择器和目标换位索引被提供,库就可以将在所述元素中定义的和弦换位到给定的换位索引。 转置索引 i[-12 <= i <= +12] 范围内。

Getting Started

Using npm

import { Transpose } from '@_00407/transpose.js';

const t = new Transpose();
t.transpose(+1);

Plain JS

<script type="text/javascript" src="https://kanchana.senadheera.net/transpose.js/dist/transpose.min.js"></script> <!-- Transposer instance will be initialized in the window object -->

<button class="transpose transpose-down" onclick="Transposer.transpose(-1)">-1</button>
<button class="transpose transpose-reset" onclick="Transposer.transpose(0)">R</button>
<button class="transpose transpose-up" onclick="Transposer.transpose(+1)">+1</button>

Prerequisites

N/A

Installing

Using npm

npm install @_000407/singlish.js

Plain JS

<script type="text/javascript" src="https://kanchana.senadheera.net/transpose.js/dist/transpose.min.js"></script>

Configuration

您可以自定义移调输出渲染的行为、和弦容器的选择等,如下所示。

  1. During instantiation - accepts an object contains configuration
  2. Calling init method of an instance - accepts an object contains configuration
PropertyDescriptionTypeReq/OptDefault
selectorCSS selector of the elements that contain the chords.stringOptionalspan.chord
renderFunction that renders the transposed chord output.functionOptionalsee Rendering

Rendering

默认情况下,渲染是使用以下函数完成的。

function(offset) {
  for(let c of document.querySelectorAll(this.selector)) {
    c.innerHTML = this.transposeChord(c.innerHTML, offset);
  }
}

Example

// During construction
const t = new Transposer({
    selector: "span.chord",
    render: function(offset) {
        console.log("Overridden version");
        for(let c of document.querySelectorAll(this.selector)) {
            c.innerHTML = this.transposeChord(c.innerHTML, offset);
        }
    }
});

// Using init method
t.init({
    selector: "span.chord",
    render: function(offset) {
        console.log("Overridden version");
        for(let c of document.querySelectorAll(this.selector)) {
            c.innerHTML = this.transposeChord(c.innerHTML, offset);
        }
    }
});

Running the tests

N/A

Break down into end to end tests

N/A

Deployment

N/A

Built With

N/A

Contributing

N/A

Versioning

我们使用 SemVer 进行版本控制。 有关可用版本,请参阅此存储库上的标签

Authors

  • Kanchana Senadheera - Initial work - 000407

另请参阅参与此项目的贡献者列表。

License

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE.md 文件

Acknowledgments

N/A

transpose.js - Chord Transposition made simple

This is a simple utility for transposing the chords in a given composition. Once the CSS selector for the element that contains the chord, and the target transposition index is provided, the library can transpose the chord defined within the said element, to the given transposition index. Transposition index i is in the range [-12 <= i <= +12].

Getting Started

Using npm

import { Transpose } from '@_00407/transpose.js';

const t = new Transpose();
t.transpose(+1);

Plain JS

<script type="text/javascript" src="https://kanchana.senadheera.net/transpose.js/dist/transpose.min.js"></script> <!-- Transposer instance will be initialized in the window object -->

<button class="transpose transpose-down" onclick="Transposer.transpose(-1)">-1</button>
<button class="transpose transpose-reset" onclick="Transposer.transpose(0)">R</button>
<button class="transpose transpose-up" onclick="Transposer.transpose(+1)">+1</button>

Prerequisites

N/A

Installing

Using npm

npm install @_000407/singlish.js

Plain JS

<script type="text/javascript" src="https://kanchana.senadheera.net/transpose.js/dist/transpose.min.js"></script>

Configuration

You may customize the behavior of transposed output rendering, selection of containers of chords etc as follows.

  1. During instantiation - accepts an object contains configuration
  2. Calling init method of an instance - accepts an object contains configuration
PropertyDescriptionTypeReq/OptDefault
selectorCSS selector of the elements that contain the chords.stringOptionalspan.chord
renderFunction that renders the transposed chord output.functionOptionalsee Rendering

Rendering

By default, the rendering is done using the following function.

function(offset) {
  for(let c of document.querySelectorAll(this.selector)) {
    c.innerHTML = this.transposeChord(c.innerHTML, offset);
  }
}

Example

// During construction
const t = new Transposer({
    selector: "span.chord",
    render: function(offset) {
        console.log("Overridden version");
        for(let c of document.querySelectorAll(this.selector)) {
            c.innerHTML = this.transposeChord(c.innerHTML, offset);
        }
    }
});

// Using init method
t.init({
    selector: "span.chord",
    render: function(offset) {
        console.log("Overridden version");
        for(let c of document.querySelectorAll(this.selector)) {
            c.innerHTML = this.transposeChord(c.innerHTML, offset);
        }
    }
});

Running the tests

N/A

Break down into end to end tests

N/A

Deployment

N/A

Built With

N/A

Contributing

N/A

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Kanchana Senadheera - Initial work - 000407

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

N/A

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文