--------------------------------------------------------------------------------
--                                                                            --
-- Copyright (C) 2004, RISC OS Ada Library (RASCAL) developers.               --
--                                                                            --
-- This library is free software; you can redistribute it and/or              --
-- modify it under the terms of the GNU Lesser General Public                 --
-- License as published by the Free Software Foundation; either               --
-- version 2.1 of the License, or (at your option) any later version.         --
--                                                                            --
-- This library is distributed in the hope that it will be useful,            --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of             --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           --
-- Lesser General Public License for more details.                            --
--                                                                            --
-- You should have received a copy of the GNU Lesser General Public           --
-- License along with this library; if not, write to the Free Software        --
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA    --
--                                                                            --
--------------------------------------------------------------------------------

-- @brief Binding to CDDB (!AcornCD)
-- $Author$
-- $Date$
-- $Revision$

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with System;                use System;

with RASCAL.Utility;        use RASCAL.Utility;
with RASCAL.OS;             use RASCAL.OS;

package RASCAL.CDDB is

   CDDB_MessageBase                             : constant Integer := 16#51BC0#;
   CDDB_Query_MessageNum                        : constant Message_Event_Code_Type := 16#51BC0# + 0;
   CDDB_QueryResults_MessageNum                 : constant Message_Event_Code_Type := 16#51BC0# + 1;
   CDDB_FreeArea_MessageNum                     : constant Message_Event_Code_Type := 16#51BC0# + 2;
   CDDB_StopRemote_MessageNum                   : constant Message_Event_Code_Type := 16#51BC0# + 3;
   CDDB_SubmitRequest_MessageNum                : constant Message_Event_Code_Type := 16#51BC0# + 4;
   CDDB_SubmitResult_MessageNum                 : constant Message_Event_Code_Type := 16#51BC0# + 5;
   CDDB_Hello_MessageNum                        : constant Message_Event_Code_Type := 16#51BC0# + 6;
   CDDB_GetIDResponse_Message                   : constant Message_Event_Code_Type := 16#51BC0# + 7;
   CDDB_GetIDRequest_Message                    : constant Message_Event_Code_Type := 16#51BC0# + 8;

   CDDB_Query_Flags_DisallowRemote              : constant Integer := 0;
   CDDB_Query_Flags_AllowRemote                 : constant Integer := 1;
   CDDB_Query_Flags_NoForceRemote               : constant Integer := 0;
   CDDB_Query_Flags_ForceRemote                 : constant Integer := 2;
   CDDB_Query_Flags_NoOpenStatus                : constant Integer := 0;
   CDDB_Query_Flags_OpenStatus                  : constant Integer := 4;

   CDDB_QueryResults_Code_LocalMatch            : constant Integer := 0;
   CDDB_QueryResults_Code_RemotePending         : constant Integer := 1;
   CDDB_QueryResults_Code_RemoteNeeded          : constant Integer := 2;
   CDDB_QueryResults_Code_RemoteFinished        : constant Integer := 3;
   CDDB_QueryResults_Code_RemoteConnectFailed   : constant Integer := 4;
   CDDB_QueryResults_Code_RemoteHandshakeFailed : constant Integer := 5;
   CDDB_QueryResults_Code_RemoteQueryError      : constant Integer := 6;
   CDDB_QueryResults_Code_RemoteReadError       : constant Integer := 7;
   CDDB_QueryResults_Code_RemoteSaveError       : constant Integer := 8;
   CDDB_QueryResults_Code_ErrorReadingTOC       : constant Integer := 9;
   CDDB_QueryResults_Code_NoMatch               : constant Integer := 10;
   CDDB_QueryResults_Code_SearchStopped         : constant Integer := 11;
   CDDB_QueryResults_Code_UnexpectedError       : constant Integer := 12;
   CDDB_QueryResults_Code_DisconnectError       : constant Integer := 13;
   CDDB_QueryResults_Code_Busy                  : constant Integer := 14;
   CDDB_QueryResults_Code_LocalCDDBError        : constant Integer := 15;
   CDDB_GetIDResponse_Code_OK                   : constant Integer := 0;
   CDDB_GetIDResponse_Code_ErrorReadingTOC      : constant Integer := 1;
   CDDB_GetIDResponse_Code_UnexpectedError      : constant Integer := 2;

   Genres : constant array (0..79) of unbounded_String := (U("Blues"),U("Classic Rock"),U("Country"),U("Dance"),U("Disco"),U("Funk"),U("Grunge"),U("Hip-Hop"),U("Jazz"),U("Metal"),
                                                  U("New Age"),U("Oldies"),U("Other"),U("Pop"),U("R&B"),U("Rap"),U("Reggae"),U("Rock"),U("Techno"),U("Industrial"),U("Alternative"),
                                                  U("Ska"),U("Death Metal"),U("Pranks"),U("Soundtrack"),U("Euro-Techno"),U("Ambient"),U("Trip-Hop"),U("Vocal"),
                                                  U("Jazz+Funk"),U("Fusion"),U("Trance"),U("Classical"),U("Instrumental"),U("Acid"),U("House"),U("Game"),U("Sound Clip"),
                                                  U("Gospel"),U("Noise"),U("AlternRock"),U("Bass"),U("Soul"),U("Punk"),U("Space"),U("Meditative"),U("Instrumental Pop"),
                                                  U("Instrumental Rock"),U("Ethnic"),U("Gothic"),U("Darkwave"),U("Techno-Industrial"),U("Electronic"),
                                                  U("Pop-Folk"),U("Eurodance"),U("Dream"),U("Southern Rock"),U("Comedy"),U("Cult"),U("Gangsta"),U("Top 40"),
                                                  U("Christian Rap"),U("Pop/Funk"),U("Jungle"),U("Native American"),U("Cabaret"),U("New Wave"),U("Psychadelic"),
                                                  U("Rave"),U("Showtunes"),U("Trailer"),U("Lo-Fi"),U("Tribal"),U("Acid Punk"),U("Acid Jazz"),U("Polka"),U("Retro"),U("Musical"),
                                                  U("Rock & Roll"),U("Hard Rock"));

   --
   -- Message send to CDDB to find track information for CD.
   --
   type Message_CDDB_Query is
   record
   Header : Message_Event_Header;
   Flags  : Integer;
   Drive  : Integer;
   end record;
   pragma Convention (C, Message_CDDB_Query);

   type Message_CDDB_Query_Pointer is access Message_CDDB_Query;

   type AMEL_Message_CDDB_Query is abstract new
        Message_EventListener(CDDB_Query_MessageNum) with
   record
   Event : Message_CDDB_Query_Pointer;
   end record;

   --
   -- CDDB answers a query.
   --
   type Message_CDDB_QueryResult is
   record
   Header : Message_Event_Header;
   Code   : Integer;
   DArea  : Address;
   AreaID : Integer;
   end record;
   pragma Convention (C, Message_CDDB_QueryResult);

   type Message_CDDB_QueryResult_Pointer is access Message_CDDB_QueryResult;

   type AMEL_Message_CDDB_QueryResult is abstract new
        Message_EventListener(CDDB_QueryResults_MessageNum) with
   record
   Event : Message_CDDB_QueryResult_Pointer;
   end record;

   --
   -- Message to CDDB to free buffer area used in by QueryResult.
   --
   type Message_CDDB_FreeArea is
   record
   Header : Message_Event_Header;
   hmm    : Integer;
   AreaID : Integer;
   end record;
   pragma Convention (C, Message_CDDB_FreeArea);

   type Message_CDDB_FreeArea_Pointer is access Message_CDDB_FreeArea;

   type AMEL_Message_CDDB_FreeArea is abstract new
        Message_EventListener(CDDB_FreeArea_MessageNum) with
   record
   Event : Message_CDDB_FreeArea_Pointer;
   end record;

   type Tracks_Type is array (Natural range <>) of unbounded_String;

   type Album_Type (Nr : Natural) is
   record
   Artist : Unbounded_String;
   Name   : Unbounded_String;
   Title  : Unbounded_String;
   Tracks : Tracks_Type (1..Nr);
   end record;

   --
   --
   --
   function Search_CDBurnDB (CD_ID : in Integer;
                             Nudge : in Integer) return Album_Type;

   --
   --
   --

private
end RASCAL.CDDB;
