Skip to content

Commit

Permalink
docs: update README and CONTRIBUTING
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanam committed Jul 24, 2024
1 parent 847f756 commit a4ed881
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 68 deletions.
19 changes: 10 additions & 9 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
## Report Bug 🐛

If you find a bug or think of an improvement, feel free to [open an issue](https://github.com/mcanam/liricle/issues).
If you find a bug or have an improvement in mind, feel free to [open an issue](https://github.com/mcanam/liricle/issues).

## Feature Request 🌱

Feature requests are always welcome. If you are thinking of contributing a feature, please [open an issue](https://github.com/mcanam/liricle/issues) first to discuss it.
Feature requests are always welcome. If you want to contribute a feature, please [open an issue](https://github.com/mcanam/liricle/issues) first to discuss it.

## Fixing Bug 👩‍💻
## Contributing Code 👩‍💻

You'll likely start by forking the repository on GitHub and then cloning it locally.
To contribute code, follow these steps:

1. Fork this project.
2. Clone it locally `git clone https://github.com/{YOUR_USERNAME}/liricle`.
4. Create a work branch (`git checkout -b your-branch`).
5. Commit your changes (`git commit -m 'your changes'`).
6. Push the branch (`git push origin your-branch`).
1. Fork this repository.
2. Clone your fork locally: `git clone https://github.com/{YOUR_USERNAME}/liricle`.
3. Create a new branch: `git checkout -b your-branch`.
4. Make your changes and commit them: `git commit -m 'your changes'`.
5. Run the tests and ensure all tests pass: `npm test`.
6. Push your branch: `git push origin your-branch`.
7. Open a Pull Request from your fork back to this repository.
184 changes: 125 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,112 +1,177 @@
# Liricle

Liricle is javascript library for syncing timed lyrics or commonly called [LRC](https://en.wikipedia.org/wiki/LRC_(file_format)) file format with song.
Liricle is simple javascript library to synchronize lyrics with music in real-time using the [LRC](https://en.wikipedia.org/wiki/LRC_(file_format)) file format. It supports both basic and enhanced LRC formats, providing methods to load, sync, and adjust lyrics.

**[Live Demo →](https://mcanam.github.io/liricle)**

> Liricle now support [enhanced](https://en.wikipedia.org/wiki/LRC_(file_format)#Enhanced_format) LRC format 🎉
> thanks to [@itaibh](https://github.com/itaibh) for the feature request and contributions 🤘
## Installation 📦

using npm:
### Using npm

``` bash
```bash
npm install liricle
```

in browser:
### In Browser

``` html
```html
<script src="https://cdn.jsdelivr.net/npm/liricle"></script>
```

## Usage 🚀
## Example Usage 🚀

### Setup
### Initialization

create the Liricle instance
Create a Liricle instance:

``` javascript
```javascript
const liricle = new Liricle();
```

### Load lyrics
### Registering Events

Before loading lyrics, you should register event handlers to handle events such as when the lyrics are loaded and when the lyrics are synced. This ensures that your application responds to these events correctly.

**Example:**

```javascript
// Register the load event
liricle.on("load", (data) => {
console.log("Lyrics loaded:", data);
});

// Register the sync event
liricle.on("sync", (line, word) => {
console.log("Sync event:", line, word);
});
```

### Load Lyrics

from url:
You can load lyrics from either a URL or raw text.

**From URL:**

```javascript
liricle.load({
url: "your-lrc-file.lrc"
url: "path/to/your-lrc-file.lrc"
});
```

from text:
**From Text:**

```javascript
liricle.load({
text: `
[01:02.03] lyric line 1
[04:05.06] lyric line 2
...
`;
`
});
```

you can call `.load()` method many times if you want to update the lyrics.
**Note:** You must provide either `url` or `text`, but not both simultaneously. For more details, see [load method](#methods).

### Sync Lyrics

### Sync lyrics
Synchronize lyrics with the given time from audio player or something else in seconds:

``` javascript
liricle.sync(time, continuous);
```javascript
liricle.sync(60); // Sync with time at 60 seconds
```

`.sync()` method has 2 parameters:
### Set Offset

- **time**: current time from audio player or something else in seconds
Adjust the offset or speed of the lyrics:

- required: `yes`
```javascript
// Speed up lyrics by 200 milliseconds
liricle.offset = 200;

- type: `number`
// Slow down lyrics by 200 milliseconds
liricle.offset = -200;
```

- **continuous**: always emit [sync event](#on-sync-event). by default Liricle only emit [sync event](#on-sync-event) if the lyric index changes
## Methods

- required: `no`
### `load(options)`

- type: `boolean`
Loads lyrics from a URL or text.

- default: `false`
**Parameters:**

### Adjust lyrics offset
- `options.url` (string, optional): URL to the LRC file.
- `options.text` (string, optional): Raw LRC text.
- `options.skipBlankLine` (boolean, optional): Whether to ignore blank lyric lines. Default is `true`.

to adjust lyrics offset or speed, you can set `.offset` property value. the value is `number` in milliseconds
**Note:** You must provide either `url` or `text`, but not both. For more information, see [Example Usage → Load Lyrics](#load-lyrics).

``` javascript
// positive value = speed up
liricle.offset = 200;
### `sync(time, continuous)`

// negative value = slow down
liricle.offset = -200;
Synchronizes the lyrics with the provided time.

**Parameters:**

- `time` (number): Current time from audio player or something else in seconds.
- `continuous` (boolean, optional): Always emit [sync event](#sync). By default Liricle only emit event if the lyrics index changes.

For more information, see [Example Usage → Sync Lyrics](#sync-lyrics).

## Properties

### `offset` (getter/setter)

**Type:** `number` (milliseconds)

Adjusts the offset or speed of the lyrics. Positive values speed up the lyrics, while negative values slow them down.

**Getter Example:**

```javascript
const currentOffset = liricle.offset;
console.log("Current offset:", currentOffset);
```

### Listen to event
**Setter Example:**

#### on load event
```javascript
liricle.offset = 200; // Speed up lyrics
```

### `data` (getter)

**Type:** `object`

``` javascript
Contains the parsed LRC file data after calling the `load` method.

**Getter Example:**

```javascript
const lyricData = liricle.data;
console.log("Lyrics data:", lyricData);
```

## Events

### `load`

**Callback Signature:**

```javascript
liricle.on("load", (data) => {
// ...
// Handle load event
});
```

callback function will receive an `object` of parsed LRC file
**Parameters:**

- `data` (object): Contains parsed LRC file data.

<details>
<summary>expand to see code</summary>
<summary>Expand to see data object example</summary>

``` javascript
```javascript
{

// LRC tags or metadata
tags: {
ar: "Liricle",
Expand Down Expand Up @@ -135,31 +200,30 @@ callback function will receive an `object` of parsed LRC file

// indicates whether the lrc format is enhanced or not.
enhanced: true

}
```

</details>

#### on sync event
### `sync`

``` javascript
**Callback Signature:**

```javascript
liricle.on("sync", (line, word) => {
// ...
// Handle sync event
});
```

> 🚧 If LRC format is not enhanced the `word` value will be `null`
**Parameters:**

callback function will receive 2 arguments which represents the current lyric.
both can be `object` or `null` if none of the lyrics match the time so always check the value.
- `line` (object or null): Current lyric line.
- `word` (object or null): Current lyric word (if the LRC format is enhanced).

<details>
<summary>expand to see code</summary>
<summary>Expand to see lyric object example</summary>

``` javascript
// both line and word objects have the same properties

```javascript
{
index: 1,
time: 39.98,
Expand All @@ -171,12 +235,14 @@ both can be `object` or `null` if none of the lyrics match the time so always ch

## Example

for a complete example you can see **[here →](https://github.com/mcanam/liricle/tree/main/examples/simple)**
For a complete example, see **[here →](https://github.com/mcanam/liricle/tree/main/examples/simple)**

## Contributing

want to contribute? [Let's go](https://github.com/mcanam/liricle/blob/main/.github/CONTRIBUTING.md) 🚀
Want to contribute? [Let's go](https://github.com/mcanam/liricle/blob/main/.github/CONTRIBUTING.md) 🚀

## License

## Licence
Distributed under the MIT License. See [LICENSE](https://github.com/mcanam/liricle/blob/main/LICENSE) for more information.

distributed under the MIT License. see [LICENSE](https://github.com/mcanam/liricle/blob/main/LICENSE) for more information.
---

0 comments on commit a4ed881

Please sign in to comment.