1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /*************************************************************************** 3 * drumkit_creator.h 4 * 5 * Thu Jan 12 18:51:34 CET 2017 6 * Copyright 2017 Andr� Nusser 7 * andre.nusser@googlemail.com 8 ****************************************************************************/ 9 10 /* 11 * This file is part of DrumGizmo. 12 * 13 * DrumGizmo is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU Lesser General Public License as published by 15 * the Free Software Foundation; either version 3 of the License, or 16 * (at your option) any later version. 17 * 18 * DrumGizmo is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU Lesser General Public License for more details. 22 * 23 * You should have received a copy of the GNU Lesser General Public License 24 * along with DrumGizmo; if not, write to the Free Software 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 26 */ 27 #pragma once 28 29 #include <string> 30 #include <vector> 31 #include <cstdint> 32 33 class DrumkitCreator 34 { 35 public: 36 using Sample = uint16_t; 37 38 //! If is_random is true then this overrules the sample member. If is_random 39 //! is false however, every sample is chosen as the one in the member variable. 40 struct WavInfo 41 { 42 const std::string filename; 43 const std::size_t length; 44 45 const bool is_random; 46 const Sample sample; 47 WavInfoWavInfo48 WavInfo(const std::string& filename, std::size_t length) 49 : filename(filename), length(length), is_random(true), sample(0) {} 50 WavInfoWavInfo51 WavInfo(const std::string& filename, std::size_t length, Sample sample) 52 : filename(filename), length(length), is_random(false), sample(sample) {} 53 }; 54 55 struct Audiofile 56 { 57 WavInfo* wav_info; 58 std::size_t filechannel; 59 }; 60 61 struct SampleData 62 { 63 std::string name; 64 // Vector of non-owning pointers and therefore it is raw. 65 std::vector<Audiofile> audiofiles; 66 }; 67 68 struct InstrumentData 69 { 70 std::string name; 71 std::string filename; 72 std::vector<SampleData> sample_data; 73 }; 74 75 struct DrumkitData 76 { 77 std::string name; 78 std::size_t number_of_channels; 79 std::vector<InstrumentData> instruments; 80 std::vector<WavInfo> wav_infos; 81 }; 82 83 DrumkitCreator() = default; 84 85 //! This destructor removes all the created temporary files and directories. 86 ~DrumkitCreator(); 87 88 //! Creates a drumkit from data in the temporary directory of the OS and 89 //! returns its filename. 90 std::string create(const DrumkitData& data); 91 92 //! Creates a single wav file 93 void createWav(const WavInfo& wav_info, std::size_t number_of_channels, const std::string& dir); 94 95 //! Those functions create some special wav files, drumkits, and midimaps 96 //@{ 97 std::string createStdKit(const std::string& name); 98 std::string createSmallKit(const std::string& name); 99 std::string createHugeKit(const std::string& name); 100 101 std::string createSingleChannelWav(const std::string& name); 102 std::string createMultiChannelWav(const std::string& name); 103 std::string create0000Wav(const std::string& name); 104 105 std::string createStdMidimap(const std::string& name); 106 //@} 107 108 private: 109 std::vector<std::string> created_files; 110 std::vector<std::string> created_directories; 111 112 bool is_valid(const DrumkitData& data); 113 114 std::string createTemporaryDirectory(const std::string& name); 115 std::vector<Sample> createData(const WavInfo& wav_info, 116 std::size_t number_of_channels); 117 void createInstrument(const InstrumentData& data, std::size_t number_of_channels, 118 const std::string& dir); 119 std::string createDrumkitFile(const DrumkitData& data, const std::string& dir); 120 }; 121