展示 HN:一个小型、简单的 C99 音乐理论库
Show HN: A small, simple music theory library in C99

原始链接: https://github.com/thelowsunoverthemoon/mahler.c

## Mahler:一个C99音乐理论库 Mahler是一个小型、仅包含头文件的C99库,专为西方音乐理论计算而设计。它提供了用于处理音程、和弦、音阶和调号的函数,支持甚至理论上和变化正确的表示(例如Fb+或G 20th sharp)。 值得注意的是,Mahler避免了内部内存分配,并拥有100%的测试覆盖率。该库易于使用——一个简单的例子演示了创建C4布鲁斯音阶。可以使用`mah_write_note`函数生成输出。 编译使用CMake(包括`src`和`inc`文件夹)或通过命令行直接进行都很简单。 该库的创建者还推荐探索古斯塔夫·马勒的作品,这位作曲家融合了瓦格纳的情感与斯特拉文斯基的创新——特别是他的第五和第六交响曲以及《大地的歌》。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Show HN: 一个小型、简单的C99音乐理论库 (github.com/thelowsunoverthemoon) 7点 由 lowsun 2小时前 | 隐藏 | 过去 | 收藏 | 讨论 帮助 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系方式 搜索:
相关文章

原文

Simple library for Western music theory in C99

  • Small & Easy-to-use
  • Interval, Chord, Scale, and Key Signature functions
  • No Internal Memory Allocation
  • Supports Theoretical Keys (eg Fb+)
  • No Accidental Limit (eg G 20th sharp)
  • Enharmonically Correct (eg minor 6th of D is Bb, not A#)
  • 100% Test Coverage

Here's an example that creates the C4 Blues Scale, ascending:

struct mah_note notes[7];
struct mah_scale scale = mah_get_scale(
    (struct mah_note) {MAH_C, MAH_NATURAL, 4}, &MAH_BLUES_SCALE, notes, MAH_ASCEND, NULL
);

And if you want to print it:

char buf[MAH_DISP_LEN];
for (int i = 0; i < scale.size; i++) {
    puts(mah_write_note(scale.notes[i], buf, MAH_DISP_LEN, NULL));
}

See here for more!

Gustav Mahler is one of my favourite composers; if you like the emotions of Wagner, and the ideas of Stravinsky, Mahler is the perfect middle ground! All his works have a flair of modernism that gives his emotional works a unique touch. You should definitely check him out, especially his Symphony No.5 in C# Minor, The Song of the Earth, and Symphony No.6 in A Minor.

See here!

See here!

To compile, you can use cmake. Be sure to include the src and inc folders as folders to search for the source and header. For example, given example.c and mahler is located in the same directory

cmake_minimum_required(VERSION 3.10)
project(example)
set(MAHLER_PATH "${PROJECT_SOURCE_DIR}/mahler.c")

add_executable(${PROJECT_NAME} ${PROJECT_NAME}.c)
target_include_directories(
    ${PROJECT_NAME} PUBLIC
    "${PROJECT_BINARY_DIR}"
    "${MAHLER_PATH}/inc"
    "${MAHLER_PATH}/src"
)

add_subdirectory(${MAHLER_PATH})
target_link_libraries(${PROJECT_NAME} PUBLIC mahler)

where MAHLER_PATH is the path to mahler. It is also simple to compile via commandline.

联系我们 contact @ memedata.com