summaryrefslogtreecommitdiff
path: root/example/file_info_example.adb
blob: 39711639de1d8a88f93b3c5adf6fd4dd5958cc66 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70


--  Programmed by Jedidiah Barber
--  Released into the public domain

--  This program opens the file supplied as a command line argument, outputs the
--  file info from it, then closes the file. No modifications are made.


with

    Ada.Command_Line,
    Ada.Directories,
    Ada.Text_IO,
    Libsndfile;


procedure File_Info_Example is


    package ACom renames Ada.Command_Line;
    package ADir renames Ada.Directories;
    package TIO renames Ada.Text_IO;


    My_Info : Libsndfile.File_Info := Libsndfile.Blank_Info;
    My_Sound_File : Libsndfile.Sound_File;


begin


    if ACom.Argument_Count < 1 then
        TIO.Put_Line ("No filename provided");
        ACom.Set_Exit_Status (ACom.Failure);
        return;
    end if;

    if not ADir.Exists (ACom.Argument (1)) then
        TIO.Put_Line ("File does not exist");
        ACom.Set_Exit_Status (ACom.Failure);
        return;
    end if;


    TIO.Put_Line ("Load file " & ACom.Argument (1));
    My_Sound_File.Open (ACom.Argument (1), Libsndfile.Read_Only, My_Info);
    TIO.New_Line;

    TIO.Put_Line ("Open frame count:" &
        Libsndfile.Count_Type'Image (Libsndfile.Frames (My_Info)));
    TIO.Put_Line ("Open sample rate:" & Natural'Image (Libsndfile.Rate (My_Info)));
    TIO.Put_Line ("Open channel count:" & Natural'Image (Libsndfile.Channels (My_Info)));
    TIO.Put_Line ("Open major format: " &
        Libsndfile.Major_Format'Image (Libsndfile.Major (My_Info)));
    TIO.Put_Line ("Open minor format: " &
        Libsndfile.Minor_Format'Image (Libsndfile.Minor (My_Info)));
    TIO.Put_Line ("Open endianness: " &
        Libsndfile.Endianness'Image (Libsndfile.Endian (My_Info)));
    TIO.Put_Line ("Open section count:" & Natural'Image (Libsndfile.Sections (My_Info)));
    TIO.Put_Line ("Open seekable: " & Boolean'Image (Libsndfile.Seekable (My_Info)));

    TIO.New_Line;
    My_Sound_File.Close;
    TIO.Put_Line ("File closed");


end File_Info_Example;