emdee_0.2.1_514ac5e1/src/track.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
--  SPDX-License-Identifier: GPL-3.0-or-later
--  SPDX-FileCopyrightText: Copyright 2024 Stephen Merrony

with Ada.Characters.Handling; use Ada.Characters.Handling;

package body Track is

   function Ends_With (Source, Pattern : String) return Boolean is
   begin
      return
         Pattern'Length <= Source'Length and then
         Source (Source'Last - Pattern'Length + 1 .. Source'Last) = Pattern;
   end Ends_With;

   function Guess_Media_Type (Filename : String) return Media_Type is
      Result      : Media_Type := UNKNOWN;
      UC_Filename : constant String := To_Upper (Filename);
   begin
      if Filename'Length = 0 then
         Result := NONE;
      elsif Ends_With (UC_Filename, "MP3") then
         Result := MP3;
      elsif Ends_With (UC_Filename, "OGG") then
         Result := OGG;
      elsif Ends_With (UC_Filename, "WAV") then
         Result := WAV;
      elsif Ends_With (UC_Filename, "FLAC") then
         Result := FLAC;
      elsif Ends_With (UC_Filename, "MID") then
         Result := MIDI;
      elsif Ends_With (UC_Filename, "MIDI") then
         Result := MIDI;
      elsif Ends_With (UC_Filename, "SMF") then
         Result := MIDI;
      elsif Ends_With (UC_Filename, "KAR") then
         Result := MIDI;
      end if;
      return Result;
   end Guess_Media_Type;

end Track;