| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Source: $ |
| 21 | * $Revision: 4 $ |
| 22 | * $Author: Jeff $ |
| 23 | * $Date: 3/15/99 4:32p $ |
| 24 | * |
| 25 | * |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/music/tracklist.cpp $ |
| 28 | * |
| 29 | * 4 3/15/99 4:32p Jeff |
| 30 | * fixed code so mem library compiles correctly |
| 31 | * |
| 32 | * 3 12/11/98 4:03p Samir |
| 33 | * error checking. |
| 34 | * |
| 35 | * 2 11/13/98 2:27p Samir |
| 36 | * created. |
| 37 | * |
| 38 | */ |
| 39 | |
| 40 | #include "music.h" |
| 41 | #include "mem.h" |
| 42 | #include "pserror.h" |
| 43 | |
| 44 | #include <string.h> |
| 45 | |
| 46 | ////////////////////////////////////////////////////////////////////////////// |
| 47 | |
| 48 | oms_tracklist::oms_tracklist() { |
| 49 | m_fnamelist = NULL; |
| 50 | m_symlist = NULL; |
| 51 | m_numtracks = 0; |
| 52 | m_maxtracks = 0; |
| 53 | m_init = false; |
| 54 | } |
| 55 | |
| 56 | oms_tracklist::~oms_tracklist() { oms_tracklist::free(); } |
| 57 | |
| 58 | // initializes track list system |
| 59 | void oms_tracklist::init(int16_t maxtracks) { |
| 60 | if (!m_init) { |
| 61 | m_maxtracks = maxtracks; |
| 62 | m_numtracks = 0; |
| 63 | |
| 64 | m_fnamelist = new char *[m_maxtracks]; |
| 65 | m_symlist = new char *[m_maxtracks]; |
| 66 | m_init = true; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // frees track list system |
| 71 | void oms_tracklist::free() { |
| 72 | if (m_init) { |
| 73 | oms_tracklist::reset(); |
| 74 | delete[] m_symlist; |
| 75 | delete[] m_fnamelist; |
| 76 | |
| 77 | m_init = false; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // resets track list to 0 |
| 82 | void oms_tracklist::reset() { |
| 83 | int i; |
| 84 | |
| 85 | if (!m_init) |
| 86 | return; |
| 87 | |
| 88 | for (i = 0; i < m_numtracks; i++) { |
| 89 | ::mem_free(m_fnamelist[i]); |
| 90 | ::mem_free(m_symlist[i]); |
| 91 | } |
| 92 | |
| 93 | m_numtracks = 0; |
| 94 | } |
| 95 | |
| 96 | // adds a track to list. |
| 97 | bool oms_tracklist::add(const char *fname, const char *sym) { |
| 98 | if (!m_init) |
| 99 | return false; |
| 100 | |
| 101 | if (m_numtracks == m_maxtracks) { |
| 102 | Int3(); |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | // add symbol and track name |
| 107 | m_fnamelist[m_numtracks] = mem_strdup(fname); |
| 108 | m_symlist[m_numtracks] = mem_strdup(sym); |
| 109 | m_numtracks++; |
| 110 | |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | // returns a track filename. |
| 115 | const char *oms_tracklist::get(const char *sym) { |
| 116 | int i; |
| 117 | |
| 118 | if (sym) { |
| 119 | for (i = 0; i < m_numtracks; i++) { |
| 120 | if (strcmp(m_symlist[i], sym) == 0) |
| 121 | return m_fnamelist[i]; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return NULL; |
| 126 | } |