<commit_before>/*
 * GStreamer
 * Copyright (C) 2005 <NAME> <<EMAIL>>
 * Copyright (C) 2005 <NAME> <<EMAIL>>
 * Copyright (C) 2009 <NAME> <<EMAIL>>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Alternatively, the contents of this file may be used under the
 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
 * which case the following provisions apply instead of the ones
 * mentioned above:
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library 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.
 */

/**
 * SECTION:element-musicxml2midi
 *
 * Converts MusicXML in to MIDI format suitable for either direct synthesis 
 * via a MIDI element (such as wildmidi or timidity) or saving as a MIDI file.
 *
 * <refsect2>
 * <title>Example launch line</title>
 * |[
 * gst-launch -v -m filesrc location=test.xml ! musicxml2midi ! wildmidi ! audioconvert ! autoaudiosink
 * gst-launch -v -m filesrc location=test.xml ! musicxml2midi ! filesink location=test.mid
 * ]|
 * </refsect2>
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gst/gst.h>
#include <string.h>
#include <math.h>

#include "gstmusicxml2midi.h"

GST_DEBUG_CATEGORY_STATIC (gst_musicxml2midi_debug);
#define GST_CAT_DEFAULT gst_musicxml2midi_debug

#define TIME_DIVISION 384

/* Filter signals and args */
enum
{
  /* FILL ME */
  LAST_SIGNAL
};

enum
{
  PROP_0
};

/* the capabilities of the inputs and outputs.
 *
 * describe the real formats here.
 */
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("application/xml")
    );

static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("audio/midi")
    );

GST_BOILERPLATE (GstMusicXml2Midi, gst_musicxml2midi, GstElement,
    GST_TYPE_ELEMENT);

static void gst_musicxml2midi_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec);
static void gst_musicxml2midi_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec);

static gboolean gst_musicxml2midi_set_caps (GstPad * pad, GstCaps * caps);
static GstFlowReturn gst_musicxml2midi_chain (GstPad * pad, GstBuffer * buf);
static gboolean gst_musicxml2midi_sink_event (GstPad * pad, GstEvent * event);
static Track *get_track_by_part (GstMusicXml2Midi * filter, xmlChar * part_id);
static GstBuffer *process_element(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_partlist(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_part(GstMusicXml2Midi * filter, xmlNode * node);
static void process_score_part(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_attributes(GstMusicXml2Midi * filter, xmlNode * node, Track *t);
static GstBuffer *process_time(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_key(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_note(GstMusicXml2Midi * filter, xmlNode * node, Track * track);
static GstBuffer *get_vlv(guint32 val);


/* GObject vmethod implementations */

static void
gst_musicxml2midi_base_init (gpointer gclass)
{
  GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);

  gst_element_class_set_details_simple(element_class,
    "MusicXml2Midi",
    "Parser",
    "Converts musicxml to midi format allowing playback via a standard midi synthesizer",
    "<NAME> <<EMAIL>>");

  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&src_factory));
  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&sink_factory));
}

/* initialize the musicxml2midi's class */
static void
gst_musicxml2midi_class_init (GstMusicXml2MidiClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;

  gobject_class = (GObjectClass *) klass;
  gstelement_class = (GstElementClass *) klass;

  gobject_class->set_property = gst_musicxml2midi_set_property;
  gobject_class->get_property = gst_musicxml2midi_get_property;
}

/* initialize the new element
 * instantiate pads and add them to element
 * set pad calback functions
 * initialize instance structure
 */
static void
gst_musicxml2midi_init (GstMusicXml2Midi * filter,
    GstMusicXml2MidiClass * gclass)
{
  filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
  gst_pad_set_setcaps_function (filter->sinkpad,
                                GST_DEBUG_FUNCPTR(gst_musicxml2midi_set_caps));
  gst_pad_set_getcaps_function (filter->sinkpad,
                                GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
  gst_pad_set_event_function (filter->sinkpad,
                                GST_DEBUG_FUNCPTR (gst_musicxml2midi_sink_event));
  gst_pad_set_chain_function (filter->sinkpad,
                              GST_DEBUG_FUNCPTR(gst_musicxml2midi_chain));

  filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");
  gst_pad_set_getcaps_function (filter->srcpad,
                                GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));

  gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);<commit_msg>Use default getcaps function instead of gst_pad_proxy_getcaps<commit_after>/*
 * GStreamer
 * Copyright (C) 2005 <NAME> <<EMAIL>>
 * Copyright (C) 2005 <NAME> <<EMAIL>>
 * Copyright (C) 2009 <NAME> <<EMAIL>>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Alternatively, the contents of this file may be used under the
 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
 * which case the following provisions apply instead of the ones
 * mentioned above:
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library 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.
 */

/**
 * SECTION:element-musicxml2midi
 *
 * Converts MusicXML in to MIDI format suitable for either direct synthesis 
 * via a MIDI element (such as wildmidi or timidity) or saving as a MIDI file.
 *
 * <refsect2>
 * <title>Example launch line</title>
 * |[
 * gst-launch -v -m filesrc location=test.xml ! musicxml2midi ! wildmidi ! audioconvert ! autoaudiosink
 * gst-launch -v -m filesrc location=test.xml ! musicxml2midi ! filesink location=test.mid
 * ]|
 * </refsect2>
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gst/gst.h>
#include <string.h>
#include <math.h>

#include "gstmusicxml2midi.h"

GST_DEBUG_CATEGORY_STATIC (gst_musicxml2midi_debug);
#define GST_CAT_DEFAULT gst_musicxml2midi_debug

#define TIME_DIVISION 384

/* Filter signals and args */
enum
{
  /* FILL ME */
  LAST_SIGNAL
};

enum
{
  PROP_0
};

/* the capabilities of the inputs and outputs.
 *
 * describe the real formats here.
 */
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
    GST_PAD_SINK,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("application/xml")
    );

static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
    GST_PAD_SRC,
    GST_PAD_ALWAYS,
    GST_STATIC_CAPS ("audio/midi")
    );

GST_BOILERPLATE (GstMusicXml2Midi, gst_musicxml2midi, GstElement,
    GST_TYPE_ELEMENT);

static void gst_musicxml2midi_set_property (GObject * object, guint prop_id,
    const GValue * value, GParamSpec * pspec);
static void gst_musicxml2midi_get_property (GObject * object, guint prop_id,
    GValue * value, GParamSpec * pspec);

static gboolean gst_musicxml2midi_set_caps (GstPad * pad, GstCaps * caps);
static GstFlowReturn gst_musicxml2midi_chain (GstPad * pad, GstBuffer * buf);
static gboolean gst_musicxml2midi_sink_event (GstPad * pad, GstEvent * event);
static Track *get_track_by_part (GstMusicXml2Midi * filter, xmlChar * part_id);
static GstBuffer *process_element(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_partlist(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_part(GstMusicXml2Midi * filter, xmlNode * node);
static void process_score_part(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_attributes(GstMusicXml2Midi * filter, xmlNode * node, Track *t);
static GstBuffer *process_time(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_key(GstMusicXml2Midi * filter, xmlNode * node);
static GstBuffer *process_note(GstMusicXml2Midi * filter, xmlNode * node, Track * track);
static GstBuffer *get_vlv(guint32 val);


/* GObject vmethod implementations */

static void
gst_musicxml2midi_base_init (gpointer gclass)
{
  GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);

  gst_element_class_set_details_simple(element_class,
    "MusicXml2Midi",
    "Parser",
    "Converts musicxml to midi format allowing playback via a standard midi synthesizer",
    "<NAME> <<EMAIL>>");

  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&src_factory));
  gst_element_class_add_pad_template (element_class,
      gst_static_pad_template_get (&sink_factory));
}

/* initialize the musicxml2midi's class */
static void
gst_musicxml2midi_class_init (GstMusicXml2MidiClass * klass)
{
  GObjectClass *gobject_class;
  GstElementClass *gstelement_class;

  gobject_class = (GObjectClass *) klass;
  gstelement_class = (GstElementClass *) klass;

  gobject_class->set_property = gst_musicxml2midi_set_property;
  gobject_class->get_property = gst_musicxml2midi_get_property;
}

/* initialize the new element
 * instantiate pads and add them to element
 * set pad calback functions
 * initialize instance structure
 */
static void
gst_musicxml2midi_init (GstMusicXml2Midi * filter,
    GstMusicXml2MidiClass * gclass)
{
  filter->sinkpad = gst_pad_new_from_static_template (&sink_factory, "sink");
  gst_pad_set_setcaps_function (filter->sinkpad,
                                GST_DEBUG_FUNCPTR(gst_musicxml2midi_set_caps));
  gst_pad_set_event_function (filter->sinkpad,
                                GST_DEBUG_FUNCPTR (gst_musicxml2midi_sink_event));
  gst_pad_set_chain_function (filter->sinkpad,
                              GST_DEBUG_FUNCPTR(gst_musicxml2midi_chain));

  filter->srcpad = gst_pad_new_from_static_template (&src_factory, "src");

  gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
{'fraction_non_alphanumeric': 0.07896881250462998, 'fraction_numerical': 0.010667456848655455, 'mean_word_length': 4.641454241537819, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 68}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2189400', 'n_tokens_mistral': 4473, 'n_tokens_neox': 4260, 'n_words': 1325}