1 /* 2 __ 3 / _| 4 __ _ _ _ _ __ ___ _ __ __ _ | |_ ___ ___ ___ 5 / _` | | | | '__/ _ \| '__/ _` | | _/ _ \/ __/ __| 6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \ 7 \__,_|\__,_|_| \___/|_| \__,_| |_| \___/|___/___/ 8 9 Copyright (C) 2018-2019 Aurora Free Open Source Software. 10 11 This file is part of the Aurora Free Open Source Software. This 12 organization promote free and open source software that you can 13 redistribute and/or modify under the terms of the GNU Lesser General 14 Public License Version 3 as published by the Free Software Foundation or 15 (at your option) any later version approved by the Aurora Free Open Source 16 Software Organization. The license is available in the package root path 17 as 'LICENSE' file. Please review the following information to ensure the 18 GNU Lesser General Public License version 3 requirements will be met: 19 https://www.gnu.org/licenses/lgpl.html . 20 21 Alternatively, this file may be used under the terms of the GNU General 22 Public License version 3 or later as published by the Free Software 23 Foundation. Please review the following information to ensure the GNU 24 General Public License requirements will be met: 25 http://www.gnu.org/licenses/gpl-3.0.html. 26 27 NOTE: All products, services or anything associated to trademarks and 28 service marks used or referenced on this file are the property of their 29 respective companies/owners or its subsidiaries. Other names and brands 30 may be claimed as the property of others. 31 32 For more info about intellectual property visit: aurorafoss.org or 33 directly send an email to: contact (at) aurorafoss.org . 34 */ 35 36 module aurorafw.audio.utils; 37 38 import std.string : toStringz; 39 import std.conv : to; 40 41 import aurorafw.core.debugmanager; 42 import aurorafw.audio.sndfile; 43 import aurorafw.audio.backend : catchSNDFILEProblem; 44 45 class AudioInfo { 46 this(SF_INFO* sndInfo = new SF_INFO, SNDFILE* sndFile = null) { 47 _sndInfo = sndInfo; 48 _sndFile = sndFile; 49 } 50 51 ~this() { 52 if(_sndFile) 53 catchSNDFILEProblem(sf_close(_sndFile)); 54 } 55 56 @property int sampleRate() { 57 return _sndInfo.samplerate; 58 } 59 60 @property int frames() { 61 return cast(int)_sndInfo.frames; 62 } 63 64 @property int channels() { 65 return _sndInfo.channels; 66 } 67 68 @property int format() { 69 return _sndInfo.format; 70 } 71 72 @property void sampleRate(immutable int sampleRate) { 73 _sndInfo.samplerate = sampleRate; 74 } 75 76 @property void frames(immutable int frames) { 77 _sndInfo.frames = cast(sf_count_t)frames; 78 } 79 80 @property void channels(immutable int channels) { 81 _sndInfo.channels = channels; 82 } 83 84 @property void format(immutable int format) { 85 _sndInfo.format = format; 86 } 87 88 @property string title() { 89 string str = to!string(sf_get_string(_sndFile, SF_STR_TITLE)); 90 return str ? str : ""; 91 } 92 93 @property string copyright() { 94 string str = to!string(sf_get_string(_sndFile, SF_STR_COPYRIGHT)); 95 return str ? str : ""; 96 } 97 98 @property string software() { 99 string str = to!string(sf_get_string(_sndFile, SF_STR_SOFTWARE)); 100 return str ? str : ""; 101 } 102 103 @property string artist() { 104 string str = to!string(sf_get_string(_sndFile, SF_STR_ARTIST)); 105 return str ? str : ""; 106 } 107 108 @property string comment() { 109 string str = to!string(sf_get_string(_sndFile, SF_STR_COMMENT)); 110 return str ? str : ""; 111 } 112 113 @property string date() { 114 string str = to!string(sf_get_string(_sndFile, SF_STR_DATE)); 115 return str ? str : ""; 116 } 117 118 @property string album() { 119 string str = to!string(sf_get_string(_sndFile, SF_STR_ALBUM)); 120 return str ? str : ""; 121 } 122 123 @property string license() { 124 string str = to!string(sf_get_string(_sndFile, SF_STR_LICENSE)); 125 return str ? str : ""; 126 } 127 128 @property string trackNumber() { 129 string str = to!string(sf_get_string(_sndFile, SF_STR_TRACKNUMBER)); 130 return str ? str : ""; 131 } 132 133 @property string genre() { 134 string str = to!string(sf_get_string(_sndFile, SF_STR_GENRE)); 135 return str ? str : ""; 136 } 137 138 @property void title(string title) { 139 sf_set_string(_sndFile, SF_STR_TITLE, title.toStringz); 140 } 141 142 @property void copyright(string copyright) { 143 sf_set_string(_sndFile, SF_STR_COPYRIGHT, copyright.toStringz); 144 } 145 146 @property void software(string software) { 147 sf_set_string(_sndFile, SF_STR_SOFTWARE, software.toStringz); 148 } 149 150 @property void artist(string artist) { 151 sf_set_string(_sndFile, SF_STR_ARTIST, artist.toStringz); 152 } 153 154 @property void comment(string comment) { 155 sf_set_string(_sndFile, SF_STR_COMMENT, comment.toStringz); 156 } 157 158 @property void date(string date) { 159 sf_set_string(_sndFile, SF_STR_DATE, date.toStringz); 160 } 161 162 @property void album(string album) { 163 sf_set_string(_sndFile, SF_STR_ALBUM, album.toStringz); 164 } 165 166 @property void license(string license) { 167 sf_set_string(_sndFile, SF_STR_LICENSE, license.toStringz); 168 } 169 170 @property void tracknumber(string trackNumber) { 171 sf_set_string(_sndFile, SF_STR_TRACKNUMBER, trackNumber.toStringz); 172 } 173 174 @property void genre(string genre) { 175 sf_set_string(_sndFile, SF_STR_GENRE, genre.toStringz); 176 } 177 178 package SF_INFO* _sndInfo; 179 package SNDFILE* _sndFile; 180 }