/* This is -*- C -*- */
/* vim: set sw=2: */
/* $Id$ */

/*
 * fragment.h
 *
 * Copyright (C) 2003 The Free Software Foundation, Inc.
 *
 */

/*
 * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA.
 */

#ifndef __FRAGMENT_H__
#define __FRAGMENT_H__

#include <glib.h>
#include <Python.h>

#include "token.h"
#include "markov.h"

typedef struct _Fragment Fragment;
struct _Fragment {
  
  int refs;
  
  Token *token;
  double metric_error;

  int    syllables;
  Meter *target_meter;

  char  *rhyme_key;
  Token *rhymes_with;

  unsigned is_break : 1;
};

struct _Template; /* forward declaration */

#define fragment_is_bound(f) ((f) && (f)->token != NULL)
#define fragment_is_start(f) ((f) && (f)->token && token_is_start((f)->token))
#define fragment_is_stop(f)  ((f) && (f)->token && token_is_stop((f)->token))
#define fragment_is_text(f)  ((f) && fragment_is_bound(f) && !(fragment_is_start(f) || fragment_is_stop(f)))
#define fragment_is_break(f) ((f) && (f)->is_break)

Fragment *fragment_new   (void);
Fragment *fragment_ref   (Fragment *f);
void      fragment_unref (Fragment *f);
Fragment *fragment_copy  (Fragment *f);

double    fragment_priority (Fragment *f);

void      fragment_bind  (Fragment *f, Token *t);

void      fragment_split (Fragment *f,
			  int num_syls_to_left,
			  Fragment **left_frag,
			  Fragment **right_frag);

struct _Template *fragment_evolve (Fragment *f, 
				   Markov   *m,
				   struct _Template *tpl);

PyObject *fragment_to_py       (Fragment *f);
PyObject *fragment_to_py_steal (Fragment *f);
Fragment *fragment_from_py     (PyObject *obj);

/* Python Extensions */

PyObject *py_fragment_new_start    (PyObject *self, PyObject *args);
PyObject *py_fragment_new_stop     (PyObject *self, PyObject *args);
PyObject *py_fragment_new_break    (PyObject *self, PyObject *args);
PyObject *py_fragment_new_token    (PyObject *self, PyObject *args);
PyObject *py_fragment_new_language (PyObject *self, PyObject *args);


#endif /* __FRAGMENT_H__ */

