Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
complexlogic committed Feb 22, 2022
0 parents commit 1906ac5
Show file tree
Hide file tree
Showing 19 changed files with 3,759 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
v1.0 (2022-2-21)
- Fork from Moonbase59/loudgain v0.6.8
- Native Windows port
170 changes: 170 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# loudgain CMakeLists.txt
# Copyright (C) 2014 Alessandro Ghedini <[email protected]>
# Modifications Copyright (C) 2019 Matthias C. Hormann <[email protected]>
# Windows port by complexlogic, 2022
# This file is released under the 2 clause BSD license, see COPYING

cmake_minimum_required(VERSION 3.13)
project(
loudgain
VERSION 1.0
DESCRIPTION "ReplayGain 2.0 loudness normalizer"
HOMEPAGE_URL "https://github.com/complexlogic/loudgain"
LANGUAGES C CXX
)
set(EXECUTABLE_TITLE "loudgain")
configure_file(
"${PROJECT_SOURCE_DIR}/config/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)

# Find dependencies - Windows
if (WIN32)
find_package(ffmpeg MODULE REQUIRED)

find_path(TAGLIB_INCLUDE_DIR "taglib/id3v2tag.h" REQUIRED)
set(TAGLIB_INCLUDE_DIR ${TAGLIB_INCLUDE_DIR}/taglib)
find_library(TAGLIB tag REQUIRED)

find_path(LIBEBUR128_INCLUDE_DIR "ebur128.h" REQUIRED)
find_library(LIBEBUR128 ebur128 REQUIRED)

find_path(GETOPT_INCLUDE_DIR "getopt.h" REQUIRED)
find_library(GETOPT getopt REQUIRED)

include_directories(
${FFMPEG_INCLUDE_DIRS}
${TAGLIB_INCLUDE_DIR}
${LIBEBUR128_INCLUDE_DIR}
${GETOPT_INCLUDE_DIR}
${PROJECT_BINARY_DIR}
)
link_libraries(
${FFMPEG_LIBRARIES}
${TAGLIB}
${LIBEBUR128}
${GETOPT}
)

# Find dependencies - Linux/Mac
else ()
if (APPLE)
# Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035
link_directories(/usr/local/lib)
endif (APPLE)

find_package(PkgConfig MODULE REQUIRED)
pkg_check_modules(LAVC REQUIRED libavcodec)
pkg_check_modules(LAVF REQUIRED libavformat)
if (${LAVF_VERSION} VERSION_LESS 58.9.100)
add_compile_definitions(LAVF_REGISTER_ALL=1)
endif ()
pkg_check_modules(LAVR REQUIRED libswresample)
pkg_check_modules(LAVU REQUIRED libavutil)
pkg_check_modules(LTAG REQUIRED taglib)
pkg_check_modules(EBUR128 REQUIRED libebur128)

include_directories(
${LAVC_INCLUDE_DIRS}
${LAVF_INCLUDE_DIRS}
${LAVR_INCLUDE_DIRS}
${LAVU_INCLUDE_DIRS}
${LTAG_INCLUDE_DIRS}
${EBUR128_INCLUDE_DIRS}
${PROJECT_BINARY_DIR}
)
link_libraries(
${LAVC_LIBRARIES}
${LAVF_LIBRARIES}
${LAVR_LIBRARIES}
${LAVU_LIBRARIES}
${LTAG_LIBRARIES}
${EBUR128_LIBRARIES}
)
endif()

# Generate Windows application manifest
if (WIN32)
set(VERSION_M ${PROJECT_VERSION_MAJOR})
if (PROJECT_VERSION_MINOR)
set(VERSION_N ${PROJECT_VERSION_MINOR})
else ()
set(VERSION_N 0)
endif()
if (PROJECT_VERSION_PATCH)
set(VERSION_O ${PROJECT_VERSION_PATCH})
else ()
set(VERSION_O 0)
endif()
if (PROJECT_VERSION_TWEAK)
set(VERSION_P ${PROJECT_VERSION_TWEAK})
else ()
set(VERSION_P 0)
endif()
configure_file(
${PROJECT_SOURCE_DIR}/config/${PROJECT_NAME}.manifest.in
${PROJECT_BINARY_DIR}/${PROJECT_NAME}.manifest
)
endif()

# Build source files
add_subdirectory(src)

# Compile options - Linux/Mac
if (UNIX)
set_target_properties(loudgain PROPERTIES COMPILE_FLAGS "-Wall -pedantic -g")
set(CMAKE_C_FLAGS "-std=gnu99 -D_GNU_SOURCE")
set(CMAKE_CXX_FLAGS "-std=gnu++11 -D_GNU_SOURCE")
endif ()

# Installation - Windows
if (WIN32)
install(DIRECTORY ${PROJECT_BINARY_DIR}/Release/ DESTINATION "./")
install(DIRECTORY ${PROJECT_SOURCE_DIR}/scripts DESTINATION "./")
install(FILES "${PROJECT_SOURCE_DIR}/LICENSE.txt" DESTINATION "./")
install(FILES "${PROJECT_SOURCE_DIR}/CHANGELOG.txt" DESTINATION "./")
set(CPACK_PACKAGE_NAME ${EXECUTABLE_TITLE})
set(CPACK_GENERATOR "ZIP")
include(CPack)

# Installation - Linux/Mac
else ()
install(TARGETS ${EXECUTABLE_TITLE} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(FILES
${PROJECT_SOURCE_DIR}/docs/loudgain.1
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1
)

# Build Debian packages
if (PACKAGE STREQUAL "DEB")
set(CPACK_DEBIAN_PACKAGE_NAME ${EXECUTABLE_TITLE})
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEBIAN_PACKAGE_VERSION ${CMAKE_PROJECT_VERSION})
if (NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
endif()
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libavcodec58 (>= 4.2.4), libavutil56 (>= 4.2.4), libswresample3 (>= 4.2.4), libavformat58 (>= 4.2.4), libtag1v5 (>= 1.11.1), libebur128-1 (>=1.2.4), libc6 (>=2.29)")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "complexlogic")
set(CPACK_DEBIAN_PACKAGE_SECTION "utils")
set(CPACK_DEBIAN_ARCHIVE_TYPE "gnutar")
set(CPACK_DEBIAN_COMPRESSION_TYPE "gzip")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_PACKAGE_NAME ${EXECUTABLE_TITLE})
set(CPACK_GENERATOR ${PACKAGE})
include(CPack)
endif ()

# Provide 'uninstall' target
if(NOT TARGET uninstall)
configure_file(
"${PROJECT_SOURCE_DIR}/config/cmake_uninstall.cmake.in"
"${PROJECT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)

add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
endif()



26 changes: 26 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2014, Alessandro Ghedini <[email protected]>
v0.1-v0.6.8: Copyright (C) 2019 Matthias C. Hormann <[email protected]>
Windows port by complexlogic, 2022

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# loudgain
This repo is a fork of the loudgain command line utility, originally by [ghedo](https://github.com/ghedo/loudgain) and continued by [Moonbase59](https://github.com/Moonbase59/loudgain). The primary purpose of this fork was to port the program to run natively in Windows (Moonbase59's version could only run under WSL). However, since the previous repo seems to have been abandoned, I am hoping that loudgain users will submit PRs for bugfixes and new features on this repo going forward.

The following changes have been made from Moonbase59's latest version, 0.6.8:
- The build system was completely rewritten to support Windows. For Linux, the build script now supports building .deb packages directly. See [Building](#building) for more info.
- The I/O code was significantly refactored to be cross-platform, with function definitions that are abstracted, and separate Unix/Windows code underneath
- The progress bar was refactored to be more performant

The underlying program logic was mostly untouched, other than a few minor tweaks I made to get it to compile in MSVC, which doesn't have full C99 support.

Due to the previous maintainer's decision to commit static binary files, the repo ballooned to neary 1 GB in size. Consequently, I decided to delete the git history and start over from new, and rebaseline the versioning at 1.0. For this repo, binary packages for Windows 64 bit and Debian/Ubuntu amd64 will be provided on the release page. For the best results, loudgain on Windows should be run on the latest version of Windows 10, or Windows 11. The Linux .deb package is compatible with Debian Bullseye and later, Ubuntu 20.04 and later.

I have also included an original python script I wrote called ```scan.py``` that I use to scan my music library. It is a much simpler alternative to the more complex ```rgbpm``` and ```rgbpm2``` scripts that were written by Moonbase59, and is cross-platform Unix/Windows.

## Usage
Usage is exactly the same as previous versions. No features have been added or removed at this point in time. See the [previous repo](https://github.com/Moonbase59/loudgain#getting-started) for usage instructions.

## Scanning Your Music Library With scan.py
The repo contains a simple, cross-platform python script ```scan.py```, which will recursively scan your entire music library using the recommended settings for each file type. To use the script, the following requirements must be met:
- The loudgain executable is in your PATH
- Your library is organized with each album in its own folder
- In each album folder, all audio files are of the same type. It is acceptable to have non-audio files in an album folder e.g. log files or cover art, but if multiple audio file types are detected, the folder will not be scanned.

To use the script, run it in the python interpreter and pass the root of the directory you want to scan as the first argument, e.g.:

```
python scan.py /path/to/music/library
```
```
python scan.py "C:\Music\ripped CDs"
```

The previous scripts ```rgbpm``` and ```rgbpm2``` that were written by Moonbase59 are also included in the scripts directory.

## Building
The build system was rewritten to support both Unix and Windows.

### Unix
The basic build instructions are the same as for the [previous repo](https://github.com/Moonbase59/loudgain#building).

For Linux, the build system now directly supports building .deb packages via CPack. During the cmake generation step, pass ```-DPACKAGE=DEB``` and ```-DCMAKE_INSTALL_PREFIX=/usr``` to cmake. Then, build the package with:
```
make package
```
By default, this will build a package for the amd64 architecture. To explicitly specify an architecture, pass ```-DCPACK_DEBIAN_PACKAGE_ARCHITECTURE```.

### Windows
The Windows toolchain consists of Visual Studio and vcpkg in addition to Git and CMake. Before starting, make sure that Visual Studio is installed with C++ core desktop features and C++ CMake tools.

Clone the master repo and create a build directory:
```
git clone https://github.com/complexlogic/loudgain.git
cd loudgain
mkdir build && cd build
```
Build the dependencies with vcpkg:
```
git clone https://github.com/microsoft/vcpkg
.\vcpkg\bootstrap-vcpkg.bat -disableMetrics
.\vcpkg\vcpkg install taglib libebur128 getopt ffmpeg[avcodec,opus,avformat,swresample] --triplet=x64-windows
```

Generate the Visual Studio project files:
```
cmake .. -DCMAKE_TOOLCHAIN_FILE=".\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET="x64-windows"
```
Build and test the program:
```
cmake --build .
.\Debug\loudgain.exe
```
Optionally, generate a zipped install package:
```
cmake --build . --config Release --target package
```
21 changes: 21 additions & 0 deletions config/cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")

file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif(NOT "${rm_retval}" STREQUAL 0)
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)
4 changes: 4 additions & 0 deletions config/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define PROJECT_NAME "@PROJECT_NAME@"
#define EXECUTABLE_TITLE "@EXECUTABLE_TITLE@"
#define PROJECT_VERSION "@PROJECT_VERSION@"
#define PROJECT_URL "@PROJECT_HOMEPAGE_URL@"
9 changes: 9 additions & 0 deletions config/loudgain.manifest.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity type="win32" name="@PROJECT_NAME@" version="@VERSION_M@.@VERSION_N@.@VERSION_O@.@VERSION_P@"/>
<application>
<windowsSettings>
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
</windowsSettings>
</application>
</assembly>
Loading

0 comments on commit 1906ac5

Please sign in to comment.