Skip to content

TypeDreamMoon/libdlp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎡 Dream Lyric Parser (libdlp)

A modern C++ library for parsing common lyric file formats

License Language Platform Version Badge


✨ Features

  • πŸ“„ Multi-format support: Parse LRC, SRT, ESLyric, ASS and more
  • ⚑ High performance: Optimized C++20 implementation
  • 🧩 Extensible architecture: Easy to add new parsers
  • 🏷️ Role assignment: Flexible lyric content role management
  • πŸ“Š Word-level timing: Support for karaoke-style word-by-word lyrics

πŸ“‹ Supported File Formats

Format Status Parser Modes Supported Role Assignment
LRC βœ… lexy Line & Word-by-word βœ…
SRT βœ… lexy Line-only βœ…
ESLyric βœ… lexy Line & Word-by-word βœ…
ASS βœ… C++ Line & Word-by-word ❌
KRC ❌ - - -
YRC ❌ - - -
QRC ❌ - - -
LYS ❌ - - -
TTML ❌ - - -
VTT ❌ - - -

πŸ’‘ Note: Missing sample files prevent development of certain formats. Contributions welcome!


πŸ—οΈ Architecture Overview

Core Components

  • FProcess: Main entry point for parsing operations
  • FLyricFile: Container for parsed lyrics and metadata
  • FLyricGroup: Groups lyrics by time periods
  • FLyricLine: Individual lyric lines with timing
  • FLyricWord: Word-level timing data
  • FLyricGroupRoleOption: Role assignment configuration
  • IParser: Abstract parser interface

Processing Flow

mermaid
graph TD
    A[User Input: Format + Lyrics + Roles] --> B[FProcess::Process]
    B --> C[Select Parser via GetParser]
    C --> D[Parse Input String]
    D --> E[Create FLyricGroups & Metadata]
    E --> F[Process Individual Lines]
    F --> G[Assign Roles via ApplyRole]
    G --> H[Return FLyricFile]

Data Structure


FLyricFile
β”œβ”€β”€ FLyricMetadata (key-value pairs)
└── std::vector<FLyricGroup>
    └── FLyricGroup
        β”œβ”€β”€ Timestamps (start/end)
        β”œβ”€β”€ FLyricGroupRoleOption
        └── std::vector<FLyricLine>
            └── FLyricLine
                β”œβ”€β”€ Content & Timing
                β”œβ”€β”€ ELyricContentRole
                β”œβ”€β”€ word_by_word flag
                └── std::vector<FLyricWord>
                    └── FLyricWord
                        β”œβ”€β”€ Text content
                        └── Timestamps (start/end)

πŸš€ Quick Start

Installation

bash
# Clone the repository
git clone https://github.com/TypeDreamMoon/libdlp.git
cd libdlp

# Build using CMake
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)

Basic Usage

cpp
#include <dlp/Process.hpp>
#include <dlp/File.hpp>

// Define content roles
std::vector<dlp::ELyricContentRole> roles{
    dlp::ELyricContentRole::Romanization,  // First priority
    dlp::ELyricContentRole::Lyric,         // Second priority  
    dlp::ELyricContentRole::Translation    // Third priority
};

// Create processor and parse
dlp::FProcess processor;
dlp::File::FLyricFile lyric_file = processor.Process(
    dlp::EFileFormat::LRC,           // File format
    "Lyric content string...",       // Input lyrics
    {roles, dlp::ELyricContentRole::Lyric}  // Role options
);

// Access parsed data
for (const auto& group : lyric_file.groups) {
    for (const auto& line : group.parsed_lines) {
        std::cout << "Role: " << static_cast<int>(line.role) 
                  << ", Content: " << line.lyric 
                  << ", Time: " << line.time_start.count() 
                  << std::endl;
    }
}

Advanced Usage - Word-by-Word Lyrics

cpp
// For karaoke-style lyrics with word-level timing
if (lyric_line.IsWordByWord()) {
    for (const auto& word : lyric_line.parsed_words) {
        std::cout << "Word: '" << word.word 
                  << "' starts at: " << word.time_start.count() 
                  << "ms, ends at: " << word.time_end.count() 
                  << "ms" << std::endl;
    }
}

πŸ› οΈ Building from Source

Prerequisites

  • C++20 compatible compiler (GCC 10+, Clang 10+, MSVC 19.28+)
  • CMake 3.16+
  • Git

Build Steps

bash
# Clone the repository
git clone https://github.com/TypeDreamMoon/libdlp.git
cd libdlp

# Configure and build
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config Release

# Run tests (if available)
cd build && ./test_executable

🀝 Contributing

We welcome contributions! Here are some ways you can help:

Adding New Format Support

  1. Implement the IParser interface
  2. Register your parser in FProcess::GetParser
  3. Update the format table in this README

Providing Sample Files

Many formats are unimplemented due to lack of sample files. If you have sample lyric files for unsupported formats, please contribute them!

Code Improvements

  • Performance optimizations
  • Better error handling
  • Additional features

πŸ“œ License

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


πŸ†˜ Support

If you encounter issues or have questions:

  • Check the Issues section
  • Open a new issue for bug reports or feature requests
  • Contribute samples for unsupported formats

ChangeLog

CHANGLOG


⭐ Star this repo if it helped you!

Dream Toolkit