Re: [linux-audio-dev] discussion about development overlap

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] discussion about development overlap
From: Paul Barton-Davis (pbd_AT_Op.Net)
Date: Fri Sep 29 2000 - 22:24:58 EEST


>length and position, that's about it. EDL support would require more
>tight binding between the editor and the lowlevel engine... nothing
>especially bad about this, just a different kind of approach.

hmm, i am not totally sure of this ... here are some class headers i
have (they are implemented too) that is based on some papers on text
editing that i was sent refs to by Eli Brandt. they had some good
stuff on efficient representations of editing operations. there are
actually 3 files below, one for Sequence, one for Piece, one for
Buffer

the implementation is fully operational for character strings, and i
think it can all be templatized to work with samples as well. i was
working on this when i started a project to reimplement snd. i gave it
up very rapidly, but had managed to implement and mostly debug the
Sequence code.

the key point here is that you can define the basic operations (and
you might choose to leave "change()" out the list, without any
knowledge of the underlying data semantics.

there are 2 important things missing from this code: an implementation
based on disk-storage, and a method of storing the edit history. That
is, there is no way right now to say "get me the data stream" when the
stream is really on disk, and there is no way to store the edit
history so that it could be undone later (after a Sequence has been
edited by a program, and the program had exited).

just to finicky, the copyright/license at the top applies to all 3
files. call me obsessed :)

--p

/*
    Copyright (C) 2000 Paul Barton-Davis

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    $Id$
*/

#ifndef __ground_sequence_h__
#define __ground_sequence_h__

#include <sys/types.h>
#include <list>
#include <vector>
#include <stack>
#include <iostream>

#include "piece.h"
#include "buffer.h"

namespace Ground {

class Sequence
{
  public:
        Sequence (vector<Buffer *> &bs);
        Sequence (Sequence &);

        Sequence *subseq (size_t start, size_t length);

        size_t copy (unsigned char *buf, size_t start, size_t length);

        ostream &dump (ostream &);

        int insert (size_t where, Piece *);
        int insert (size_t where, Sequence &);

        int del (Piece *);
        int del (size_t start, size_t length);

        int replace (size_t start, Piece *);
        int replace (size_t start, Sequence &);

        int change (int (*do_func)(Sequence &, size_t, size_t, void *),
                    int (*undo_func)(Sequence &, size_t, size_t, void *),
                    const Piece * const, void *arg);

        int change (int (*do_func)(Sequence &, size_t, size_t, void *),
                    int (*undo_func)(Sequence &, size_t, size_t, void *),
                    size_t start, size_t length, void *arg);

        size_t length() {
                return _length;
        }
        
        int undo ();
        int redo ();

  private:
        typedef list<Piece *> Pieces;

        struct Undo {
            Pieces pieces;
            size_t length;
            
            Undo (Pieces &p, size_t len)
                    : pieces (p), length (len) { }
        };

        typedef stack<Undo *> UndoStack;

        UndoStack undo_stack;
        UndoStack redo_stack;
        vector<Buffer *> &buffers;
        Pieces *pieces;
        size_t _length;

        void insert_piece (Pieces::iterator before, Piece *p) {
                pieces->insert (before, p);
                _length += p->length;
        }
        
        void remove_piece (Pieces::iterator at) {
                _length -= (*at)->length;
                pieces->erase (at);
        }

        Pieces::iterator insert_position_for (size_t where);
        Piece *piece_containing (size_t where,
                                 size_t *start_of_piece,
                                 Pieces::iterator *iter);

        void push_state (UndoStack &);

};

}; /* namespace Ground */

#endif /* __ground_sequence_h__ */

------------------------------------------------------------------------------

#ifndef __ground_buffer_h__
#define __ground_buffer_h__

#include <stdlib.h>
#include <sys/types.h>

#include <iostream>

namespace Ground
{

class Buffer
{
  public:
        Buffer (size_t sz, size_t len) {
                item_size = sz;
                length = len;
                buf = new unsigned char[item_size * length];
        }

        Buffer (size_t sz, size_t len, void *b) {
                item_size = sz;
                length = len;
                buf = (unsigned char *) b;
        }

        ~Buffer () {
                delete [] buf;
        }

        size_t item_count() { return length; }
        size_t data_size () { return item_size * length; }

        void copy_to (unsigned char *dst, size_t start, size_t len) {
                memcpy (dst, buf+(start*item_size), len*item_size);
        }

        void copy_from (unsigned char *src, size_t start, size_t len) {
                memcpy (buf+(start*item_size), src, len*item_size);
        }

        void copy_to (Buffer *b, size_t start, size_t len) {
                memcpy (b->buf, buf+(start*item_size), len*item_size);
        }

        void copy_from (Buffer *b, size_t start, size_t len) {
                memcpy (buf+(start*item_size), b->buf, len*item_size);
        }

  private:
        unsigned char *buf;
        size_t item_size;
        size_t length;
};

}; /* namespace Ground */

#endif /* __ground_buffer_h__ */

------------------------------------------------------------------------------

#ifndef __ground_piece_h__
#define __ground_piece_h__

#include <sys/types.h>
#include <list>

namespace Ground
{

struct Piece
{
    Piece (size_t b, size_t s, size_t l)
            : buffer_id (b), start (s), length (l) { }

    size_t buffer_id;
    size_t start;
    size_t length;
};

}; /* namespace Ground */

#endif /* __ground_piece_h__ */


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Fri Sep 29 2000 - 22:59:47 EEST