comp.lang.ada
 help / color / mirror / Atom feed
From: Frank Buss <fb@frank-buss.de>
Subject: Re: quiz for Sequential_IO Read
Date: Mon, 4 Sep 2017 21:58:27 +0200
Date: 2017-09-04T21:58:27+02:00	[thread overview]
Message-ID: <ookb93$feb$1@newsreader4.netcologne.de> (raw)
In-Reply-To: <oogv1s$1k09$1@gioia.aioe.org>

On 09/03/2017 03:11 PM, Dmitry A. Kazakov wrote:
>
> In practice Stream I/O is a better choice. You also should not use
> compiler-generated serialization attributes (see T'Read, T'Write,
> T'Input, T'Output attributes). These are not portable either. You should
> always replace them with your own.

Ok, I wrote my program with Stream_IO. It will be reading from a FIFO 
file for receiving MIDI signals, and then write to a sound device 
continuously. I found a convenient package which defines low-level types 
of fixed size, same as stdint.h in C. See below for the code. Would this 
be portable on all systems (assuming they provide FIFO files) ? At least 
it works on my Debian system so far.


with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO;
with Ada.Text_IO; use Ada.Text_IO;
with Interfaces; use Interfaces;

procedure Hello is

    Data : Unsigned_8;
    Input_File : Ada.Streams.Stream_IO.File_Type;
    Input_Stream : Ada.Streams.Stream_IO.Stream_Access;

    task Main_Task is
       entry Data_Received(Data : in Unsigned_8);
    end Main_Task;

    task body Main_Task is
    begin
       loop
          select
             accept Data_Received(Data : in Unsigned_8) do
                Put("test: " & Unsigned_8'Image(Data));
                New_Line;
             end Data_Received;
          else
             delay 0.1;
             -- TODO: create continuous sound output here
          end select;
       end loop;
    end Main_Task;

begin
    Open(Input_File, In_File, "/home/frank/midi");
    Input_Stream := Stream(Input_File);
    loop
       Unsigned_8'Read(Input_Stream, Data);
       Main_Task.Data_Received(Data);
    end loop;
end;


-- 
Frank Buss, http://www.frank-buss.de
electronics and more: http://www.youtube.com/user/frankbuss


  reply	other threads:[~2017-09-04 19:58 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-03 11:01 quiz for Sequential_IO Read Frank Buss
2017-09-03 11:40 ` Jeffrey R. Carter
2017-09-03 12:47   ` Frank Buss
2017-09-03 13:44     ` Jeffrey R. Carter
2017-09-03 15:38       ` AdaMagica
2017-09-03 12:26 ` Dmitry A. Kazakov
2017-09-03 12:43   ` Frank Buss
2017-09-03 13:11     ` Dmitry A. Kazakov
2017-09-04 19:58       ` Frank Buss [this message]
2017-09-04 20:55         ` Dmitry A. Kazakov
2017-09-04 21:51           ` Frank Buss
2017-09-05  1:54             ` Dennis Lee Bieber
2017-09-03 17:28 ` J-P. Rosen
2017-09-03 20:10   ` Frank Buss
2017-09-04  5:12     ` J-P. Rosen
2017-09-04  7:37     ` Dmitry A. Kazakov
2017-09-03 20:17   ` Dennis Lee Bieber
2017-09-04  5:14     ` J-P. Rosen
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox