├── .gitignore ├── .travis.yml ├── LICENSE ├── README.mediawiki ├── examples ├── example_1.py └── example_2.py ├── mary.mid ├── scripts ├── mididump.py ├── mididumphw.py ├── midilisten.py └── midiplay.py ├── setup.py ├── src ├── __init__.py ├── constants.py ├── containers.py ├── events.py ├── fileio.py ├── sequencer.py ├── sequencer_alsa │ ├── .gitignore │ ├── __init__.py │ ├── sequencer.py │ └── sequencer_alsa.i ├── sequencer_osx │ ├── CoreMIDI.framework │ ├── _sequencer_osx.so │ ├── a.out │ ├── backup.i │ ├── cfstring-typemaps-example-1.0.tar.gz │ ├── cfstring-typemaps-example-1.0 │ │ ├── PKG-INFO │ │ ├── example.c │ │ ├── example.i │ │ └── setup.py │ ├── make.sh │ ├── sequencer_osx.i │ ├── sequencer_osx.py │ ├── sequencer_osx_wrap.c │ ├── test │ ├── test.c │ └── test.py └── util.py └── tests ├── mary_test.py └── tests.py /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | *.pyc 3 | .coverage 4 | .*.sw? 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - 2.7 4 | before_install: 5 | - date -u 6 | - uname -a 7 | - lsb_release -a 8 | - sudo apt-get -qq update 9 | - sudo apt-get install build-essential python-dev swig libasound2-dev 10 | - swig -version 11 | install: 12 | - pip install coveralls 13 | - python setup.py install 14 | script: 15 | - nosetests --with-coverage --cover-package=midi 16 | after_success: 17 | - coveralls 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2013 Giles F. Hall 3 | 4 | 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: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | 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. 9 | -------------------------------------------------------------------------------- /README.mediawiki: -------------------------------------------------------------------------------- 1 | Build Statis 2 | Coverage Status 3 | 4 | =Python MIDI= 5 | 6 | Python, for all its amazing ability out of the box, does not provide you with 7 | an easy means to manipulate MIDI data. There are probably about ten different 8 | python packages out there that accomplish some part of this goal, but there is 9 | nothing that is totally comprehensive. 10 | 11 | This toolkit aims to fulfill this goal. In particular, it strives to provide a 12 | high level framework that is independent of hardware. It tries to offer a 13 | reasonable object granularity to make MIDI streams a painless thing to 14 | manipulate, sequence, record, and playback. It's important to have a good 15 | concept of time, and the event framework provides automatic hooks so you don't 16 | have to calculate ticks to wall clock, for example. 17 | 18 | This MIDI Python toolkit represents about two years of scattered work. If you 19 | are someone like me, who has spent a long time looking for a Python MIDI 20 | framework, than this might be a good fit. It's not perfect, but it has a large 21 | feature set to offer. 22 | 23 | ==Features== 24 | 25 | * High level class types that represent individual MIDI events. 26 | * A multi-track aware container, that allows you to manage your MIDI events. 27 | * A tempo map that actively keeps track of tempo changes within a track. 28 | * A reader and writer, so you can read and write your MIDI tracks to disk. 29 | 30 | ==Installation== 31 | 32 | Follow the [http://docs.python.org/2/install/index.html normal procedure for Python module installation]: 33 | 34 |
 35 | python setup.py install
 36 | 
37 | 38 | ===Examine a MIDI File=== 39 | 40 | To examine the contents of a MIDI file run 41 | 42 |
 43 | $ mididump.py mary.mid
 44 | 
45 | 46 | This will print out a representation of "Mary had a Little Lamb" as executable python code. 47 | 48 | ==Example Usage== 49 | 50 | ===Building a MIDI File from scratch=== 51 | 52 | It is easy to build a MIDI track from scratch. 53 | 54 |
 55 | import midi
 56 | # Instantiate a MIDI Pattern (contains a list of tracks)
 57 | pattern = midi.Pattern()
 58 | # Instantiate a MIDI Track (contains a list of MIDI events)
 59 | track = midi.Track()
 60 | # Append the track to the pattern
 61 | pattern.append(track)
 62 | # Instantiate a MIDI note on event, append it to the track
 63 | on = midi.NoteOnEvent(tick=0, velocity=20, pitch=midi.G_3)
 64 | track.append(on)
 65 | # Instantiate a MIDI note off event, append it to the track
 66 | off = midi.NoteOffEvent(tick=100, pitch=midi.G_3)
 67 | track.append(off)
 68 | # Add the end of track event, append it to the track
 69 | eot = midi.EndOfTrackEvent(tick=1)
 70 | track.append(eot)
 71 | # Print out the pattern
 72 | print pattern
 73 | # Save the pattern to disk
 74 | midi.write_midifile("example.mid", pattern)
 75 | 
76 | 77 | A MIDI file is represented as a hierarchical set of objects. At the top is a 78 | Pattern, which contains a list of Tracks, and a Track is is a list of MIDI 79 | Events. 80 | 81 | The MIDI Pattern class inherits from the standard python list, so it supports 82 | all list features such as append(), extend(), slicing, and iteration. Patterns 83 | also contain global MIDI metadata: the resolution and MIDI Format. 84 | 85 | The MIDI Track class also inherits from the standard python list. It does not 86 | have any special metadata like Pattern, but it does provide a few helper 87 | functions to manipulate all events within a track. 88 | 89 | There are 27 different MIDI Events supported. In this example, three different 90 | MIDI events are created and added to the MIDI Track: 91 | 92 | # The NoteOnEvent captures the start of note, like a piano player pushing down on a piano key. The tick is when this event occurred, the pitch is the note value of the key pressed, and the velocity represents how hard the key was pressed. 93 | 94 | # The NoteOffEvent captures the end of note, just like a piano player removing her finger from a depressed piano key. Once again, the tick is when this event occurred, the pitch is the note that is released, and the velocity has no real world analogy and is usually ignored. NoteOnEvents with a velocity of zero are equivalent to NoteOffEvents. 95 | 96 | # The EndOfTrackEvent is a special event, and is used to indicate to MIDI sequencing software when the song ends. With creating Patterns with multiple Tracks, you only need one EndOfTrack event for the entire song. Most MIDI software will refuse to load a MIDI file if it does not contain an EndOfTrack event. 97 | 98 | You might notice that the EndOfTrackEvent has a tick value of 1. This is 99 | because MIDI represents ticks in relative time. The actual tick offset of the 100 | MidiTrackEvent is the sum of its tick and all the ticks from previous events. 101 | In this example, the EndOfTrackEvent would occur at tick 101 (0 + 100 + 1). 102 | 103 | ====Side Note: What is a MIDI Tick?==== 104 | 105 | The problem with ticks is that they don't give you any information about when 106 | they occur without knowing two other pieces of information, the resolution, and 107 | the tempo. The code handles these issues for you so all you have to do is 108 | think about things in terms of milliseconds, or ticks, if you care about the beat. 109 | 110 | A tick represents the lowest level resolution of a MIDI track. Tempo is always 111 | analogous with Beats per Minute (BPM) which is the same thing as Quarter notes 112 | per Minute (QPM). The Resolution is also known as the Pulses per Quarter note 113 | (PPQ). It analogous to Ticks per Beat (TPM). 114 | 115 | Tempo is set by two things. First, a saved MIDI file encodes an initial 116 | Resolution and Tempo. You use these values to initialize the sequencer timer. 117 | The Resolution should be considered static to a track, as well as the 118 | sequencer. During MIDI playback, the MIDI file may have encoded sequenced 119 | (that is, timed) Tempo change events. These events will modulate the Tempo at 120 | the time they specify. The Resolution, however, can not change from its 121 | initial value during playback. 122 | 123 | Under the hood, MIDI represents Tempo in microseconds. In other words, you 124 | convert Tempo to Microseconds per Beat. If the Tempo was 120 BPM, the python 125 | code to convert to microseconds looks like this: 126 | 127 |
128 | >>> 60 * 1000000 / 120
129 | 500000
130 | 
131 | 132 | This says the Tempo is 500,000 microseconds per beat. This, in combination 133 | with the Resolution, will allow you to convert ticks to time. If there are 134 | 500,000 microseconds per beat, and if the Resolution is 1,000 than one tick is 135 | how much time? 136 | 137 |
138 | >>> 500000 / 1000
139 | 500
140 | >>> 500 / 1000000.0
141 | 0.00050000000000000001
142 | 
143 | 144 | In other words, one tick represents .0005 seconds of time or half a 145 | millisecond. Increase the Resolution and this number gets smaller, the inverse 146 | as the Resolution gets smaller. Same for Tempo. 147 | 148 | Although MIDI encodes Time Signatures, it has no impact on the Tempo. However, 149 | here is a quick refresher on Time Signatures: 150 | 151 | http://en.wikipedia.org/wiki/Time_signature 152 | 153 | ===Reading our Track back from Disk=== 154 | 155 | It's just as easy to load your MIDI file from disk. 156 | 157 |
158 | import midi
159 | pattern = midi.read_midifile("example.mid")
160 | print pattern
161 | 
162 | 163 | ==Sequencer== 164 | 165 | If you use this toolkit under Linux, you can take advantage of ALSA's 166 | sequencer. There is a SWIG wrapper and a high level sequencer interface that 167 | hides the ALSA details as best it can. This sequencer understands the higher 168 | level Event framework, and will convert these Events to structures accessible 169 | to ALSA. It tries to do as much as the hard work for you as possible, including 170 | adjusting the queue for tempo changes during playback. You can also record 171 | MIDI events, and with the right set of calls, the ALSA sequencer will timestamp 172 | your MIDI tracks at the moment the event triggers an OS hardware interrupt. 173 | The timing is extremely accurate, even though you are using Python to manage 174 | it. 175 | 176 | I am extremely interested in supporting OS-X and Win32 sequencers as well, but 177 | I need platform expert who can help me. Are you that person? Please contact 178 | me if you would like to help. 179 | 180 | ===Scripts for Sequencer=== 181 | 182 | To examine the hardware and software MIDI devices attached to your 183 | system, run the mididumphw.py script. 184 | 185 |
186 | $ mididumphw.py
187 | ] client(20) "OP-1 Midi Device"
188 | ]   port(0) [r, w, sender, receiver] "OP-1 Midi Device MIDI 1"
189 | ] client(129) "__sequencer__"
190 | ] client(14) "Midi Through"
191 | ]   port(0) [r, w, sender, receiver] "Midi Through Port-0"
192 | ] client(0) "System"
193 | ]   port(1) [r, sender] "Announce"
194 | ]   port(0) [r, w, sender] "Timer"
195 | ] client(128) "FLUID Synth (6438)"
196 | ]   port(0) [w, receiver] "Synth input port (6438:0)"
197 | 
198 | 199 | In the case shown, [http://qsynth.sourceforge.net/qsynth-index.html qsynth] 200 | is running (client 128), and a hardware synthesizer is attached via 201 | USB (client 20). 202 | 203 | To play the example MIDI file, run the midiplay.py script. 204 | 205 |
206 | midiplay.py 128 0 mary.mid
207 | 
208 | 209 | ==Website, support, bug tracking, development etc.== 210 | 211 | You can find the latest code on the home page: 212 | https://github.com/vishnubob/python-midi/ 213 | 214 | You can also check for known issues and submit new ones to the 215 | tracker: https://github.com/vishnubob/python-midi/issues/ 216 | 217 | ==Thanks== 218 | 219 | I originally wrote this to drive the electro-mechanical instruments of Ensemble 220 | Robot, which is a Boston based group of artists, programmers, and engineers. 221 | This API, however, has applications beyond controlling this equipment. For 222 | more information about Ensemble Robot, please visit: 223 | 224 | http://www.ensemblerobot.org/ 225 | -------------------------------------------------------------------------------- /examples/example_1.py: -------------------------------------------------------------------------------- 1 | import midi 2 | # Instantiate a MIDI Pattern (contains a list of tracks) 3 | pattern = midi.Pattern() 4 | # Instantiate a MIDI Track (contains a list of MIDI events) 5 | track = midi.Track() 6 | # Append the track to the pattern 7 | pattern.append(track) 8 | # Instantiate a MIDI note on event, append it to the track 9 | on = midi.NoteOnEvent(tick=0, velocity=20, pitch=midi.G_3) 10 | track.append(on) 11 | # Instantiate a MIDI note off event, append it to the track 12 | off = midi.NoteOffEvent(tick=100, pitch=midi.G_3) 13 | track.append(off) 14 | # Add the end of track event, append it to the track 15 | eot = midi.EndOfTrackEvent(tick=1) 16 | track.append(eot) 17 | # Print out the pattern 18 | print pattern 19 | # Save the pattern to disk 20 | midi.write_midifile("example.mid", pattern) 21 | -------------------------------------------------------------------------------- /examples/example_2.py: -------------------------------------------------------------------------------- 1 | import midi 2 | pattern = midi.read_midifile("example.mid") 3 | print pattern 4 | -------------------------------------------------------------------------------- /mary.mid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sniperwrb/python-midi/ec8071b56500dbf58d5a5650ca81990d855dc49f/mary.mid -------------------------------------------------------------------------------- /scripts/mididump.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Print a description of a MIDI file. 4 | """ 5 | import midi 6 | import sys 7 | 8 | if len(sys.argv) != 2: 9 | print "Usage: {0} ".format(sys.argv[0]) 10 | sys.exit(2) 11 | 12 | midifile = sys.argv[1] 13 | pattern = midi.read_midifile(midifile) 14 | print repr(pattern) 15 | -------------------------------------------------------------------------------- /scripts/mididumphw.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Print a description of the available devices. 4 | """ 5 | import midi.sequencer as sequencer 6 | 7 | s = sequencer.SequencerHardware() 8 | 9 | print s 10 | -------------------------------------------------------------------------------- /scripts/midilisten.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Attach to a MIDI device and print events to standard output. 4 | """ 5 | import sys 6 | import time 7 | import midi 8 | import midi.sequencer as sequencer 9 | 10 | if len(sys.argv) != 3: 11 | print "Usage: {0} ".format(sys.argv[0]) 12 | exit(2) 13 | 14 | client = sys.argv[1] 15 | port = sys.argv[2] 16 | 17 | seq = sequencer.SequencerRead(sequencer_resolution=120) 18 | seq.subscribe_port(client, port) 19 | seq.start_sequencer() 20 | 21 | while True: 22 | event = seq.event_read() 23 | if event is not None: 24 | print event 25 | -------------------------------------------------------------------------------- /scripts/midiplay.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | Attach to a MIDI device and send the contents of a MIDI file to it. 4 | """ 5 | import sys 6 | import time 7 | import midi 8 | import midi.sequencer as sequencer 9 | 10 | if len(sys.argv) != 4: 11 | print "Usage: {0} ".format(sys.argv[0]) 12 | exit(2) 13 | 14 | client = sys.argv[1] 15 | port = sys.argv[2] 16 | filename = sys.argv[3] 17 | 18 | pattern = midi.read_midifile(filename) 19 | 20 | hardware = sequencer.SequencerHardware() 21 | 22 | if not client.isdigit: 23 | client = hardware.get_client(client) 24 | 25 | if not port.isdigit: 26 | port = hardware.get_port(port) 27 | 28 | seq = sequencer.SequencerWrite(sequencer_resolution=pattern.resolution) 29 | seq.subscribe_port(client, port) 30 | 31 | pattern.make_ticks_abs() 32 | events = [] 33 | for track in pattern: 34 | for event in track: 35 | events.append(event) 36 | events.sort() 37 | seq.start_sequencer() 38 | for event in events: 39 | buf = seq.event_write(event, False, False, True) 40 | if buf == None: 41 | continue 42 | if buf < 1000: 43 | time.sleep(.5) 44 | while event.tick > seq.queue_get_tick_time(): 45 | seq.drain() 46 | time.sleep(.5) 47 | 48 | print 'The end?' 49 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | from setuptools import setup, Extension 5 | import setuptools.command.install 6 | 7 | __base__ = { 8 | 'name':'midi', 9 | 'version':'v0.2.3', 10 | 'description':'Python MIDI API', 11 | 'author':'giles hall', 12 | 'author_email':'ghall@csh.rit.edu', 13 | 'package_dir':{'midi':'src'}, 14 | 'py_modules':['midi.containers', 'midi.__init__', 'midi.events', 'midi.util', 'midi.fileio', 'midi.constants'], 15 | 'ext_modules':[], 16 | 'ext_package':'', 17 | 'scripts':['scripts/mididump.py', 'scripts/mididumphw.py', 'scripts/midiplay.py'], 18 | } 19 | 20 | # this kludge ensures we run the build_ext first before anything else 21 | # otherwise, we will be missing generated files during the copy 22 | class Install_Command_build_ext_first(setuptools.command.install.install): 23 | def run(self): 24 | self.run_command("build_ext") 25 | return setuptools.command.install.install.run(self) 26 | 27 | def setup_alsa(ns): 28 | # scan for alsa include directory 29 | dirs = ["/usr/include", "/usr/local/include"] 30 | testfile = "alsa/asoundlib.h" 31 | alsadir = None 32 | for _dir in dirs: 33 | tfn = os.path.join(_dir, testfile) 34 | if os.path.exists(tfn): 35 | alsadir = _dir 36 | break 37 | if not alsadir: 38 | print("Warning: could not find asoundlib.h, not including ALSA sequencer support!") 39 | return 40 | srclist = ["src/sequencer_alsa/sequencer_alsa.i"] 41 | include_arg = "-I%s" % alsadir 42 | extns = { 43 | 'libraries': ['asound'], 44 | 'swig_opts': [include_arg], 45 | #'extra_compile_args':['-DSWIGRUNTIME_DEBUG'] 46 | } 47 | ext = Extension('_sequencer_alsa', srclist, **extns) 48 | ns['ext_modules'].append(ext) 49 | 50 | ns['package_dir']['midi.sequencer'] = 'src/sequencer_alsa' 51 | ns['py_modules'].append('midi.sequencer.__init__') 52 | ns['py_modules'].append('midi.sequencer.sequencer') 53 | ns['py_modules'].append('midi.sequencer.sequencer_alsa') 54 | ns['ext_package'] = 'midi.sequencer' 55 | ns['cmdclass'] = {'install': Install_Command_build_ext_first} 56 | 57 | def configure_platform(): 58 | from sys import platform 59 | ns = __base__.copy() 60 | # currently, only the ALSA sequencer is supported 61 | setup_alsa(ns) 62 | return ns 63 | 64 | if __name__ == "__main__": 65 | setup(**configure_platform()) 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- 1 | from .containers import * 2 | from .events import * 3 | from struct import unpack, pack 4 | from .util import * 5 | from .fileio import * 6 | -------------------------------------------------------------------------------- /src/constants.py: -------------------------------------------------------------------------------- 1 | ## 2 | ## Constants 3 | ## 4 | 5 | OCTAVE_MAX_VALUE = 12 6 | OCTAVE_VALUES = list(range( OCTAVE_MAX_VALUE)) 7 | 8 | NOTE_NAMES = ['C', 'Cs', 'D', 'Ds', 'E', 'F', 'Fs', 'G', 'Gs', 'A', 'As', 'B'] 9 | WHITE_KEYS = [0, 2, 4, 5, 7, 9, 11] 10 | BLACK_KEYS = [1, 3, 6, 8, 10] 11 | NOTE_PER_OCTAVE = len( NOTE_NAMES ) 12 | NOTE_VALUES = list(range( OCTAVE_MAX_VALUE * NOTE_PER_OCTAVE)) 13 | NOTE_NAME_MAP_FLAT = {} 14 | NOTE_VALUE_MAP_FLAT = [] 15 | NOTE_NAME_MAP_SHARP = {} 16 | NOTE_VALUE_MAP_SHARP = [] 17 | 18 | for value in range( 128 ): 19 | noteidx = value % NOTE_PER_OCTAVE 20 | octidx = value / OCTAVE_MAX_VALUE 21 | name = NOTE_NAMES[noteidx] 22 | if len( name ) == 2: 23 | # sharp note 24 | flat = NOTE_NAMES[noteidx+1] + 'b' 25 | NOTE_NAME_MAP_FLAT['%s_%d' % (flat, octidx)] = value 26 | NOTE_NAME_MAP_SHARP['%s_%d' % (name, octidx)] = value 27 | NOTE_VALUE_MAP_FLAT.append( '%s_%d' % (flat, octidx) ) 28 | NOTE_VALUE_MAP_SHARP.append( '%s_%d' % (name, octidx) ) 29 | globals()['%s_%d' % (name[0] + 's', octidx)] = value 30 | globals()['%s_%d' % (flat, octidx)] = value 31 | else: 32 | NOTE_NAME_MAP_FLAT['%s_%d' % (name, octidx)] = value 33 | NOTE_NAME_MAP_SHARP['%s_%d' % (name, octidx)] = value 34 | NOTE_VALUE_MAP_FLAT.append( '%s_%d' % (name, octidx) ) 35 | NOTE_VALUE_MAP_SHARP.append( '%s_%d' % (name, octidx) ) 36 | globals()['%s_%d' % (name, octidx)] = value 37 | 38 | BEATNAMES = ['whole', 'half', 'quarter', 'eighth', 'sixteenth', 'thiry-second', 'sixty-fourth'] 39 | BEATVALUES = [4, 2, 1, .5, .25, .125, .0625] 40 | WHOLE = 0 41 | HALF = 1 42 | QUARTER = 2 43 | EIGHTH = 3 44 | SIXTEENTH = 4 45 | THIRTYSECOND = 5 46 | SIXTYFOURTH = 6 47 | 48 | DEFAULT_MIDI_HEADER_SIZE = 14 49 | 50 | -------------------------------------------------------------------------------- /src/containers.py: -------------------------------------------------------------------------------- 1 | from pprint import pformat, pprint 2 | 3 | class Pattern(list): 4 | def __init__(self, tracks=[], resolution=220, format=1, tick_relative=True): 5 | self.format = format 6 | self.resolution = resolution 7 | self.tick_relative = tick_relative 8 | super(Pattern, self).__init__(tracks) 9 | 10 | def __repr__(self): 11 | return "midi.Pattern(format=%r, resolution=%r, tracks=\\\n%s)" % \ 12 | (self.format, self.resolution, pformat(list(self))) 13 | 14 | def make_ticks_abs(self): 15 | self.tick_relative = False 16 | for track in self: 17 | track.make_ticks_abs() 18 | 19 | def make_ticks_rel(self): 20 | self.tick_relative = True 21 | for track in self: 22 | track.make_ticks_rel() 23 | 24 | def __getitem__(self, item): 25 | if isinstance(item, slice): 26 | indices = item.indices(len(self)) 27 | return Pattern(resolution=self.resolution, format=self.format, 28 | tracks=(super(Pattern, self).__getitem__(i) for i in range(*indices))) 29 | else: 30 | return super(Pattern, self).__getitem__(item) 31 | 32 | def __getslice__(self, i, j): 33 | # The deprecated __getslice__ is still called when subclassing built-in types 34 | # for calls of the form List[i:j] 35 | return self.__getitem__(slice(i, j)) 36 | 37 | class Track(list): 38 | def __init__(self, events=[], tick_relative=True): 39 | self.tick_relative = tick_relative 40 | super(Track, self).__init__(events) 41 | 42 | def make_ticks_abs(self): 43 | if (self.tick_relative): 44 | self.tick_relative = False 45 | running_tick = 0 46 | for event in self: 47 | event.tick += running_tick 48 | running_tick = event.tick 49 | 50 | def make_ticks_rel(self): 51 | if (not self.tick_relative): 52 | self.tick_relative = True 53 | running_tick = 0 54 | for event in self: 55 | event.tick -= running_tick 56 | running_tick += event.tick 57 | 58 | def __getitem__(self, item): 59 | if isinstance(item, slice): 60 | indices = item.indices(len(self)) 61 | return Track((super(Track, self).__getitem__(i) for i in range(*indices))) 62 | else: 63 | return super(Track, self).__getitem__(item) 64 | 65 | def __getslice__(self, i, j): 66 | # The deprecated __getslice__ is still called when subclassing built-in types 67 | # for calls of the form List[i:j] 68 | return self.__getitem__(slice(i, j)) 69 | 70 | def __repr__(self): 71 | return "midi.Track(\\\n %s)" % (pformat(list(self)).replace('\n', '\n '), ) 72 | -------------------------------------------------------------------------------- /src/events.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | class EventRegistry(object): 4 | Events = {} 5 | MetaEvents = {} 6 | 7 | def register_event(cls, event, bases): 8 | if (Event in bases) or (NoteEvent in bases): 9 | assert event.statusmsg not in cls.Events, \ 10 | "Event %s already registered" % event.name 11 | cls.Events[event.statusmsg] = event 12 | elif (MetaEvent in bases) or (MetaEventWithText in bases): 13 | assert event.metacommand not in cls.MetaEvents, \ 14 | "Event %s already registered" % event.name 15 | cls.MetaEvents[event.metacommand] = event 16 | else: 17 | raise ValueError("Unknown bases class in event type: "+event.name) 18 | register_event = classmethod(register_event) 19 | 20 | class AutoRegister(type): 21 | def __init__(cls, name, bases, dict): 22 | if name not in {'AbstractEvent', 'Event', 'MetaEvent', 'NoteEvent', 23 | 'MetaEventWithText'}: 24 | EventRegistry.register_event(cls, bases) 25 | 26 | 27 | class AbstractEvent(object,metaclass=AutoRegister): 28 | name = "Generic MIDI Event" 29 | length = 0 30 | statusmsg = 0x0 31 | 32 | def __init__(self, **kw): 33 | if isinstance(self.length, int): 34 | defdata = [0] * self.length 35 | else: 36 | defdata = [] 37 | self.tick = 0 38 | self.data = defdata 39 | for key in kw: 40 | setattr(self, key, kw[key]) 41 | 42 | def __cmp__(self, other): 43 | if self.tick < other.tick: return -1 44 | elif self.tick > other.tick: return 1 45 | return cmp(self.data, other.data) 46 | 47 | def __baserepr__(self, keys=[]): 48 | keys = ['tick'] + keys + ['data'] 49 | body = [] 50 | for key in keys: 51 | val = getattr(self, key) 52 | keyval = "%s=%r" % (key, val) 53 | body.append(keyval) 54 | body = str.join(', ', body) 55 | return "midi.%s(%s)" % (self.__class__.__name__, body) 56 | 57 | def __repr__(self): 58 | return self.__baserepr__() 59 | 60 | 61 | class Event(AbstractEvent): 62 | name = 'Event' 63 | 64 | def __init__(self, **kw): 65 | if 'channel' not in kw: 66 | kw = kw.copy() 67 | kw['channel'] = 0 68 | super(Event, self).__init__(**kw) 69 | 70 | def copy(self, **kw): 71 | _kw = {'channel': self.channel, 'tick': self.tick, 'data': self.data} 72 | _kw.update(kw) 73 | return self.__class__(**_kw) 74 | 75 | def __cmp__(self, other): 76 | if self.tick < other.tick: return -1 77 | elif self.tick > other.tick: return 1 78 | return 0 79 | 80 | def __repr__(self): 81 | return self.__baserepr__(['channel']) 82 | 83 | def is_event(cls, statusmsg): 84 | return (cls.statusmsg == (statusmsg & 0xF0)) 85 | is_event = classmethod(is_event) 86 | 87 | 88 | """ 89 | MetaEvent is a special subclass of Event that is not meant to 90 | be used as a concrete class. It defines a subset of Events known 91 | as the Meta events. 92 | """ 93 | 94 | class MetaEvent(AbstractEvent): 95 | statusmsg = 0xFF 96 | metacommand = 0x0 97 | name = 'Meta Event' 98 | 99 | def is_event(cls, statusmsg): 100 | return (statusmsg == 0xFF) 101 | is_event = classmethod(is_event) 102 | 103 | 104 | """ 105 | NoteEvent is a special subclass of Event that is not meant to 106 | be used as a concrete class. It defines the generalities of NoteOn 107 | and NoteOff events. 108 | """ 109 | 110 | class NoteEvent(Event): 111 | length = 2 112 | 113 | def get_pitch(self): 114 | return self.data[0] 115 | def set_pitch(self, val): 116 | self.data[0] = val 117 | pitch = property(get_pitch, set_pitch) 118 | 119 | def get_velocity(self): 120 | return self.data[1] 121 | def set_velocity(self, val): 122 | self.data[1] = val 123 | velocity = property(get_velocity, set_velocity) 124 | 125 | class NoteOnEvent(NoteEvent): 126 | statusmsg = 0x90 127 | name = 'Note On' 128 | 129 | class NoteOffEvent(NoteEvent): 130 | statusmsg = 0x80 131 | name = 'Note Off' 132 | 133 | class AfterTouchEvent(Event): 134 | statusmsg = 0xA0 135 | length = 2 136 | name = 'After Touch' 137 | 138 | def get_pitch(self): 139 | return self.data[0] 140 | def set_pitch(self, val): 141 | self.data[0] = val 142 | pitch = property(get_pitch, set_pitch) 143 | 144 | def get_value(self): 145 | return self.data[1] 146 | def set_value(self, val): 147 | self.data[1] = val 148 | value = property(get_value, set_value) 149 | 150 | class ControlChangeEvent(Event): 151 | statusmsg = 0xB0 152 | length = 2 153 | name = 'Control Change' 154 | 155 | def set_control(self, val): 156 | self.data[0] = val 157 | def get_control(self): 158 | return self.data[0] 159 | control = property(get_control, set_control) 160 | 161 | def set_value(self, val): 162 | self.data[1] = val 163 | def get_value(self): 164 | return self.data[1] 165 | value = property(get_value, set_value) 166 | 167 | class ProgramChangeEvent(Event): 168 | statusmsg = 0xC0 169 | length = 1 170 | name = 'Program Change' 171 | 172 | def set_value(self, val): 173 | self.data[0] = val 174 | def get_value(self): 175 | return self.data[0] 176 | value = property(get_value, set_value) 177 | 178 | class ChannelAfterTouchEvent(Event): 179 | statusmsg = 0xD0 180 | length = 1 181 | name = 'Channel After Touch' 182 | 183 | def set_value(self, val): 184 | self.data[1] = val 185 | def get_value(self): 186 | return self.data[1] 187 | value = property(get_value, set_value) 188 | 189 | class PitchWheelEvent(Event): 190 | statusmsg = 0xE0 191 | length = 2 192 | name = 'Pitch Wheel' 193 | 194 | def get_pitch(self): 195 | return ((self.data[1] << 7) | self.data[0]) - 0x2000 196 | def set_pitch(self, pitch): 197 | value = pitch + 0x2000 198 | self.data[0] = value & 0x7F 199 | self.data[1] = (value >> 7) & 0x7F 200 | pitch = property(get_pitch, set_pitch) 201 | 202 | class SysexEvent(Event): 203 | statusmsg = 0xF0 204 | name = 'SysEx' 205 | length = 'varlen' 206 | 207 | def is_event(cls, statusmsg): 208 | return (cls.statusmsg == statusmsg) 209 | is_event = classmethod(is_event) 210 | 211 | class SequenceNumberMetaEvent(MetaEvent): 212 | name = 'Sequence Number' 213 | metacommand = 0x00 214 | length = 2 215 | 216 | class MetaEventWithText(MetaEvent): 217 | def __init__(self, **kw): 218 | super(MetaEventWithText, self).__init__(**kw) 219 | if 'text' not in kw: 220 | self.text = ''.join(chr(datum) for datum in self.data) 221 | 222 | def __repr__(self): 223 | return self.__baserepr__(['text']) 224 | 225 | class TextMetaEvent(MetaEventWithText): 226 | name = 'Text' 227 | metacommand = 0x01 228 | length = 'varlen' 229 | 230 | class CopyrightMetaEvent(MetaEventWithText): 231 | name = 'Copyright Notice' 232 | metacommand = 0x02 233 | length = 'varlen' 234 | 235 | class TrackNameEvent(MetaEventWithText): 236 | name = 'Track Name' 237 | metacommand = 0x03 238 | length = 'varlen' 239 | 240 | class InstrumentNameEvent(MetaEventWithText): 241 | name = 'Instrument Name' 242 | metacommand = 0x04 243 | length = 'varlen' 244 | 245 | class LyricsEvent(MetaEventWithText): 246 | name = 'Lyrics' 247 | metacommand = 0x05 248 | length = 'varlen' 249 | 250 | class MarkerEvent(MetaEventWithText): 251 | name = 'Marker' 252 | metacommand = 0x06 253 | length = 'varlen' 254 | 255 | class CuePointEvent(MetaEventWithText): 256 | name = 'Cue Point' 257 | metacommand = 0x07 258 | length = 'varlen' 259 | 260 | class ProgramNameEvent(MetaEventWithText): 261 | name = 'Program Name' 262 | metacommand = 0x08 263 | length = 'varlen' 264 | 265 | class SomethingEvent(MetaEvent): 266 | name = 'Something' 267 | metacommand = 0x09 268 | 269 | class ChannelPrefixEvent(MetaEvent): 270 | name = 'Channel Prefix' 271 | metacommand = 0x20 272 | length = 1 273 | 274 | class PortEvent(MetaEvent): 275 | name = 'MIDI Port/Cable' 276 | metacommand = 0x21 277 | 278 | class TrackLoopEvent(MetaEvent): 279 | name = 'Track Loop' 280 | metacommand = 0x2E 281 | 282 | class EndOfTrackEvent(MetaEvent): 283 | name = 'End of Track' 284 | metacommand = 0x2F 285 | 286 | class SetTempoEvent(MetaEvent): 287 | name = 'Set Tempo' 288 | metacommand = 0x51 289 | length = 3 290 | 291 | def set_bpm(self, bpm): 292 | self.mpqn = int(float(6e7) / bpm) 293 | def get_bpm(self): 294 | return float(6e7) / self.mpqn 295 | bpm = property(get_bpm, set_bpm) 296 | 297 | def get_mpqn(self): 298 | assert(len(self.data) == 3) 299 | vals = [self.data[x] << (16 - (8 * x)) for x in range(3)] 300 | return sum(vals) 301 | def set_mpqn(self, val): 302 | self.data = [(val >> (16 - (8 * x)) & 0xFF) for x in range(3)] 303 | mpqn = property(get_mpqn, set_mpqn) 304 | 305 | class SmpteOffsetEvent(MetaEvent): 306 | name = 'SMPTE Offset' 307 | metacommand = 0x54 308 | 309 | class TimeSignatureEvent(MetaEvent): 310 | name = 'Time Signature' 311 | metacommand = 0x58 312 | length = 4 313 | 314 | def get_numerator(self): 315 | return self.data[0] 316 | def set_numerator(self, val): 317 | self.data[0] = val 318 | numerator = property(get_numerator, set_numerator) 319 | 320 | def get_denominator(self): 321 | return 2 ** self.data[1] 322 | def set_denominator(self, val): 323 | self.data[1] = int(math.log(val, 2)) 324 | denominator = property(get_denominator, set_denominator) 325 | 326 | def get_metronome(self): 327 | return self.data[2] 328 | def set_metronome(self, val): 329 | self.data[2] = val 330 | metronome = property(get_metronome, set_metronome) 331 | 332 | def get_thirtyseconds(self): 333 | return self.data[3] 334 | def set_thirtyseconds(self, val): 335 | self.data[3] = val 336 | thirtyseconds = property(get_thirtyseconds, set_thirtyseconds) 337 | 338 | class KeySignatureEvent(MetaEvent): 339 | name = 'Key Signature' 340 | metacommand = 0x59 341 | length = 2 342 | 343 | def get_alternatives(self): 344 | d = self.data[0] 345 | return d - 256 if d > 127 else d 346 | def set_alternatives(self, val): 347 | self.data[0] = 256 + val if val < 0 else val 348 | alternatives = property(get_alternatives, set_alternatives) 349 | 350 | def get_minor(self): 351 | return self.data[1] 352 | def set_minor(self, val): 353 | self.data[1] = val 354 | minor = property(get_minor, set_minor) 355 | 356 | class SequencerSpecificEvent(MetaEvent): 357 | name = 'Sequencer Specific' 358 | metacommand = 0x7F 359 | -------------------------------------------------------------------------------- /src/fileio.py: -------------------------------------------------------------------------------- 1 | from .containers import * 2 | from .events import * 3 | from struct import unpack, pack 4 | from .constants import * 5 | from .util import * 6 | 7 | class FileReader(object): 8 | def read(self, midifile): 9 | pattern = self.parse_file_header(midifile) 10 | for track in pattern: 11 | self.parse_track(midifile, track) 12 | return pattern 13 | 14 | def parse_file_header(self, midifile): 15 | # First four bytes are MIDI header 16 | magic = midifile.read(4) 17 | if magic != b'MThd': 18 | raise TypeError("Bad header in MIDI file.",magic) 19 | # next four bytes are header size 20 | # next two bytes specify the format version 21 | # next two bytes specify the number of tracks 22 | # next two bytes specify the resolution/PPQ/Parts Per Quarter 23 | # (in other words, how many ticks per quater note) 24 | data = unpack(">LHHH", midifile.read(10)) 25 | hdrsz = data[0] 26 | format = data[1] 27 | tracks = [Track() for x in range(data[2])] 28 | resolution = data[3] 29 | # XXX: the assumption is that any remaining bytes 30 | # in the header are padding 31 | if hdrsz > DEFAULT_MIDI_HEADER_SIZE: 32 | midifile.read(hdrsz - DEFAULT_MIDI_HEADER_SIZE) 33 | return Pattern(tracks=tracks, resolution=resolution, format=format) 34 | 35 | def parse_track_header(self, midifile): 36 | # First four bytes are Track header 37 | magic = midifile.read(4) 38 | if magic != b'MTrk': 39 | raise TypeError("Bad track header in MIDI file: ",magic) 40 | # next four bytes are track size 41 | trksz = unpack(">L", midifile.read(4))[0] 42 | return trksz 43 | 44 | def parse_track(self, midifile, track): 45 | self.RunningStatus = None 46 | trksz = self.parse_track_header(midifile) 47 | trackdata = iter(midifile.read(trksz)) 48 | while True: 49 | try: 50 | event = self.parse_midi_event(trackdata) 51 | track.append(event) 52 | except StopIteration: 53 | break 54 | 55 | def parse_midi_event(self, trackdata): 56 | # first datum is varlen representing delta-time 57 | tick = read_varlen(trackdata) 58 | # next byte is status message 59 | stsmsg = next(trackdata) 60 | # is the event a MetaEvent? 61 | if MetaEvent.is_event(stsmsg): 62 | cmd = next(trackdata) 63 | if cmd not in EventRegistry.MetaEvents: 64 | raise Warning("Unknown Meta MIDI Event: " + repr(cmd)) 65 | cls = EventRegistry.MetaEvents[cmd] 66 | datalen = read_varlen(trackdata) 67 | data = [next(trackdata) for x in range(datalen)] 68 | return cls(tick=tick, data=data) 69 | # is this event a Sysex Event? 70 | elif SysexEvent.is_event(stsmsg): 71 | data = [] 72 | while True: 73 | datum = next(trackdata) 74 | if datum == 0xF7: 75 | break 76 | data.append(datum) 77 | return SysexEvent(tick=tick, data=data) 78 | # not a Meta MIDI event or a Sysex event, must be a general message 79 | else: 80 | key = stsmsg & 0xF0 81 | if key not in EventRegistry.Events: 82 | assert self.RunningStatus, ("Bad byte value", tick, stsmsg, bytes(trackdata)) 83 | data = [] 84 | key = self.RunningStatus & 0xF0 85 | cls = EventRegistry.Events[key] 86 | channel = self.RunningStatus & 0x0F 87 | data.append(stsmsg) 88 | data += [next(trackdata) for x in range(cls.length - 1)] 89 | return cls(tick=tick, channel=channel, data=data) 90 | else: 91 | self.RunningStatus = stsmsg 92 | cls = EventRegistry.Events[key] 93 | channel = self.RunningStatus & 0x0F 94 | data = [next(trackdata) for x in range(cls.length)] 95 | return cls(tick=tick, channel=channel, data=data) 96 | raise Warning("Unknown MIDI Event: " + repr(stsmsg)) 97 | 98 | class FileWriter(object): 99 | RunningStatus = None 100 | def __init__(self,file): 101 | self.file = file 102 | def write(self, pattern): 103 | self.write_file_header(pattern,len(pattern)) 104 | for track in pattern: 105 | self.write_track(track) 106 | 107 | def write_file_header(self, pattern, length=None): 108 | if length is None: 109 | length = len(pattern) 110 | # First four bytes are MIDI header 111 | packdata = pack(">LHHH", 6, 112 | pattern.format, 113 | length, 114 | pattern.resolution) 115 | self.file.write(b'MThd' + packdata) 116 | 117 | 118 | def write_track(self, track): 119 | hlen = len(self.encode_track_header(0)) 120 | buf = bytearray(b'0'*hlen) 121 | for event in track: 122 | buf.extend(self.encode_midi_event(event)) 123 | buf[:hlen] = self.encode_track_header(len(buf)-hlen) 124 | self.file.write(buf) 125 | 126 | def write_track_header(self,track=None): 127 | trklen = 1 if track is None else track if isinstance(track,int) else len(track) 128 | self.file.write(self.encode_track_header(trklen)) 129 | 130 | def encode_track_header(self, trklen): 131 | return b'MTrk' + pack(">L", trklen) 132 | 133 | def write_midi_event(self, event): 134 | # be sure to write the track and pattern headers first 135 | # can stream to timidity or fluidsynth this way 136 | self.file.write(self.encode_midi_event(event)) 137 | 138 | def encode_midi_event(self, event): 139 | ret = bytearray() 140 | #assert hasattr(event,'tick'), event 141 | assert isinstance(event.tick,int), event.tick 142 | ret.extend(write_varlen(event.tick)) 143 | # is the event a MetaEvent? 144 | if isinstance(event, MetaEvent): 145 | ret.append(event.statusmsg) 146 | ret.append(event.metacommand) 147 | ret.extend(write_varlen(len(event.data))) 148 | ret.extend(event.data) 149 | # is this event a Sysex Event? 150 | elif isinstance(event, SysexEvent): 151 | ret.append(0xF0) 152 | ret.extend(event.data) 153 | ret.append(0xF7) 154 | # not a Meta MIDI event or a Sysex event, must be a general message 155 | elif isinstance(event, Event): 156 | # why in the heeeeeeeeelp would you not write the status message 157 | # here? doesn't matter if it's the same as last time. the byte 158 | # needs to be there! 159 | 160 | ret.append(event.statusmsg | event.channel) 161 | ret.extend(event.data) 162 | else: 163 | raise ValueError("Unknown MIDI Event: " + str(event)) 164 | return ret 165 | 166 | def write_midifile(midifile, pattern): 167 | if type(midifile) in (str, str): 168 | with open(midifile, 'wb') as out: 169 | return write_midifile(out,pattern) 170 | writer = FileWriter(midifile) 171 | return writer.write(pattern) 172 | 173 | def read_midifile(midifile): 174 | if type(midifile) in (str, bytes): 175 | with open(midifile, 'rb') as inp: 176 | return read_midifile(inp) 177 | reader = FileReader() 178 | return reader.read(midifile) 179 | -------------------------------------------------------------------------------- /src/sequencer.py: -------------------------------------------------------------------------------- 1 | class TempoMap(list): 2 | def __init__(self, stream): 3 | self.stream = stream 4 | 5 | def add_and_update(self, event): 6 | self.add(event) 7 | self.update() 8 | 9 | def add(self, event): 10 | # get tempo in microseconds per beat 11 | tempo = event.mpqn 12 | # convert into milliseconds per beat 13 | tempo = tempo / 1000.0 14 | # generate ms per tick 15 | event.mpt = tempo / self.stream.resolution 16 | self.append(event) 17 | 18 | def update(self): 19 | self.sort() 20 | # adjust running time 21 | last = None 22 | for event in self: 23 | if last: 24 | event.msdelay = last.msdelay + \ 25 | int(last.mpt * (event.tick - last.tick)) 26 | last = event 27 | 28 | def get_tempo(self, offset=0): 29 | last = self[0] 30 | for tm in self[1:]: 31 | if tm.tick > offset: 32 | return last 33 | last = tm 34 | return last 35 | 36 | class EventStreamIterator(object): 37 | def __init__(self, stream, window): 38 | self.stream = stream 39 | self.trackpool = stream.trackpool 40 | self.window_length = window 41 | self.window_edge = 0 42 | self.leftover = None 43 | self.events = self.stream.iterevents() 44 | # First, need to look ahead to see when the 45 | # tempo markers end 46 | self.ttpts = [] 47 | for tempo in stream.tempomap[1:]: 48 | self.ttpts.append(tempo.tick) 49 | # Finally, add the end of track tick. 50 | self.ttpts.append(stream.endoftrack.tick) 51 | self.ttpts = iter(self.ttpts) 52 | # Setup next tempo timepoint 53 | self.ttp = self.ttpts.next() 54 | self.tempomap = iter(self.stream.tempomap) 55 | self.tempo = self.tempomap.next() 56 | self.endoftrack = False 57 | 58 | def __iter__(self): 59 | return self 60 | 61 | def __next_edge(self): 62 | if self.endoftrack: 63 | raise StopIteration 64 | lastedge = self.window_edge 65 | self.window_edge += int(self.window_length / self.tempo.mpt) 66 | if self.window_edge > self.ttp: 67 | # We're past the tempo-marker. 68 | oldttp = self.ttp 69 | try: 70 | self.ttp = self.ttpts.next() 71 | except StopIteration: 72 | # End of Track! 73 | self.window_edge = self.ttp 74 | self.endoftrack = True 75 | return 76 | # Calculate the next window edge, taking into 77 | # account the tempo change. 78 | msused = (oldttp - lastedge) * self.tempo.mpt 79 | msleft = self.window_length - msused 80 | self.tempo = self.tempomap.next() 81 | ticksleft = msleft / self.tempo.mpt 82 | self.window_edge = ticksleft + self.tempo.tick 83 | 84 | def next(self): 85 | ret = [] 86 | self.__next_edge() 87 | if self.leftover: 88 | if self.leftover.tick > self.window_edge: 89 | return ret 90 | ret.append(self.leftover) 91 | self.leftover = None 92 | for event in self.events: 93 | if event.tick > self.window_edge: 94 | self.leftover = event 95 | return ret 96 | ret.append(event) 97 | return ret 98 | 99 | -------------------------------------------------------------------------------- /src/sequencer_alsa/.gitignore: -------------------------------------------------------------------------------- 1 | sequencer_alsa.py 2 | sequencer_alsa_wrap.c 3 | -------------------------------------------------------------------------------- /src/sequencer_alsa/__init__.py: -------------------------------------------------------------------------------- 1 | try: 2 | from sequencer import * 3 | except ImportError: 4 | pass 5 | -------------------------------------------------------------------------------- /src/sequencer_alsa/sequencer.py: -------------------------------------------------------------------------------- 1 | import select 2 | import sequencer_alsa as S 3 | import midi 4 | 5 | __SWIG_NS_SET__ = set(['__class__', '__del__', '__delattr__', '__dict__', '__doc__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__swig_getmethods__', '__swig_setmethods__', '__weakref__', 'this', 'thisown']) 6 | 7 | def stringify(name, obj, indent=0): 8 | retstr = '' 9 | datafields = False 10 | if getattr(obj, 'this', False): 11 | datafields = dir(obj) 12 | # filter unwanted names 13 | datafields = list(set(datafields) - __SWIG_NS_SET__) 14 | retstr += '%s%s ::\n' % (' ' * indent, name) 15 | for key in datafields: 16 | value = getattr(obj, key, "n/a") 17 | retstr += stringify(key, value, indent+1) 18 | else: 19 | retstr += '%s%s: %s\n' % (' ' * indent, name, obj) 20 | return retstr 21 | 22 | class Sequencer(object): 23 | SEQUENCER_TYPE = "alsa" 24 | __ARGUMENTS__ = { 25 | 'alsa_sequencer_name':'__sequencer__', 26 | 'alsa_sequencer_stream':S.SND_SEQ_OPEN_DUPLEX, 27 | 'alsa_sequencer_mode':S.SND_SEQ_NONBLOCK, 28 | 'alsa_sequencer_type':'default', 29 | 'alsa_port_name':'__port__', 30 | 'alsa_port_caps':S.SND_SEQ_PORT_CAP_READ, 31 | 'alsa_port_type':S.SND_SEQ_PORT_TYPE_MIDI_GENERIC, 32 | 'alsa_queue_name':'__queue__', 33 | 'sequencer_tempo':120, 34 | 'sequencer_resolution':1000, 35 | } 36 | DefaultArguments = {} 37 | 38 | def __init__(self, **ns): 39 | # seed with baseline arguments 40 | self.__dict__.update(self.__ARGUMENTS__) 41 | # update with default arguments from concrete class 42 | self.__dict__.update(self.DefaultArguments) 43 | # apply user arguments 44 | self.__dict__.update(ns) 45 | self.client = None 46 | self._queue_running = False 47 | self._poll_descriptors = [] 48 | self.init() 49 | 50 | def __del__(self): 51 | if self.client: 52 | S.snd_seq_close(self.client) 53 | 54 | def init(self): 55 | self._init_handle() 56 | self._init_port() 57 | self._init_queue() 58 | 59 | def set_nonblock(self, nonblock=True): 60 | if nonblock: 61 | self.alsa_sequencer_mode = S.SND_SEQ_NONBLOCK 62 | else: 63 | self.alsa_sequencer_mode = 0 64 | S.snd_seq_nonblock(self.client, self.alsa_sequencer_mode) 65 | 66 | def get_nonblock(self): 67 | if self.alsa_sequencer_mode == S.SND_SEQ_NONBLOCK: 68 | return True 69 | else: 70 | return False 71 | 72 | def _error(self, errcode): 73 | strerr = S.snd_strerror(errcode) 74 | msg = "ALSAError[%d]: %s" % (errcode, strerr) 75 | raise RuntimeError, msg 76 | 77 | def _init_handle(self): 78 | ret = S.open_client(self.alsa_sequencer_name, 79 | self.alsa_sequencer_type, 80 | self.alsa_sequencer_stream, 81 | self.alsa_sequencer_mode) 82 | if ret == None: 83 | # XXX: global error 84 | self._error(ret) 85 | self.client = ret 86 | self.client_id = S.snd_seq_client_id(self.client) 87 | self.output_buffer_size = S.snd_seq_get_output_buffer_size(self.client) 88 | self.input_buffer_size = S.snd_seq_get_input_buffer_size(self.client) 89 | self._set_poll_descriptors() 90 | 91 | def _init_port(self): 92 | err = S.snd_seq_create_simple_port(self.client, 93 | self.alsa_port_name, 94 | self.alsa_port_caps, 95 | self.alsa_port_type) 96 | if err < 0: self._error(err) 97 | self.port = err 98 | 99 | def _new_subscribe(self, sender, dest, read=True): 100 | subscribe = S.new_port_subscribe() 101 | if read: 102 | self.read_sender = sender 103 | self.read_dest = dest 104 | S.snd_seq_port_subscribe_set_sender(subscribe, self.read_sender) 105 | S.snd_seq_port_subscribe_set_dest(subscribe, self.read_dest) 106 | else: 107 | self.write_sender = sender 108 | self.write_dest = dest 109 | S.snd_seq_port_subscribe_set_sender(subscribe, self.write_sender) 110 | S.snd_seq_port_subscribe_set_dest(subscribe, self.write_dest) 111 | S.snd_seq_port_subscribe_set_queue(subscribe, self.queue) 112 | return subscribe 113 | 114 | def _subscribe_port(self, subscribe): 115 | err = S.snd_seq_subscribe_port(self.client, subscribe) 116 | if err < 0: self._error(err) 117 | 118 | def _my_address(self): 119 | addr = S.snd_seq_addr_t() 120 | addr.client = self.client_id 121 | addr.port = self.port 122 | return addr 123 | 124 | def _new_address(self, client, port): 125 | addr = S.snd_seq_addr_t() 126 | addr.client = int(client) 127 | addr.port = int(port) 128 | return addr 129 | 130 | def _init_queue(self): 131 | err = S.snd_seq_alloc_named_queue(self.client, self.alsa_queue_name) 132 | if err < 0: self._error(err) 133 | self.queue = err 134 | adjtempo = int(60.0 * 1000000.0 / self.sequencer_tempo) 135 | S.init_queue_tempo(self.client, self.queue, 136 | adjtempo, self.sequencer_resolution) 137 | 138 | def _control_queue(self, ctype, cvalue, event=None): 139 | err = S.snd_seq_control_queue(self.client, self.queue, ctype, cvalue, event) 140 | if err < 0: self._error(err) 141 | self.drain() 142 | 143 | def _set_event_broadcast(self, event): 144 | event.source.client = source.client 145 | event.source.port = source.port 146 | event.dest.client = S.SND_SEQ_ADDRESS_SUBSCRIBERS 147 | event.dest.port = S.SND_SEQ_ADDRESS_UNKNOWN 148 | 149 | def queue_get_tick_time(self): 150 | status = S.new_queue_status(self.client, self.queue) 151 | S.snd_seq_get_queue_status(self.client, self.queue, status) 152 | res = S.snd_seq_queue_status_get_tick_time(status) 153 | S.free_queue_status(status) 154 | return res 155 | 156 | def queue_get_real_time(self): 157 | status = S.new_queue_status(self.client, self.queue) 158 | S.snd_seq_get_queue_status(self.client, self.queue, status) 159 | res = S.snd_seq_queue_status_get_real_time(status) 160 | S.free_queue_status(status) 161 | return (res.tv_sec, res.tv_nsec) 162 | 163 | def change_tempo(self, tempo, event=None): 164 | adjbpm = int(60.0 * 1000000.0 / tempo) 165 | self._control_queue(S.SND_SEQ_EVENT_TEMPO, adjbpm, event) 166 | self.sequencer_tempo = tempo 167 | return True 168 | 169 | def start_sequencer(self, event=None): 170 | if not self._queue_running: 171 | self._control_queue(S.SND_SEQ_EVENT_START, 0, event) 172 | self._queue_running = True 173 | 174 | def continue_sequencer(self, event=None): 175 | if not self._queue_running: 176 | self._control_queue(S.SND_SEQ_EVENT_CONTINUE, 0, event) 177 | self._queue_running = True 178 | 179 | def stop_sequencer(self, event=None): 180 | if self._queue_running: 181 | self._control_queue(S.SND_SEQ_EVENT_STOP, 0, event) 182 | self._queue_running = False 183 | 184 | def drain(self): 185 | S.snd_seq_drain_output(self.client) 186 | 187 | def queue_eventlen(self): 188 | status = S.new_queue_status(self.client, self.queue) 189 | S.snd_seq_queue_status_get_events(status) 190 | 191 | def _set_poll_descriptors(self): 192 | self._poll_descriptors = S.client_poll_descriptors(self.client) 193 | 194 | def configure_poll(self, poll): 195 | for fd in self._poll_descriptors: 196 | poll.register(fd, select.POLLIN) 197 | 198 | def drop_output(self): 199 | S.snd_seq_drop_output_buffer(self.client) 200 | 201 | def output_pending(self): 202 | return S.snd_seq_event_output_pending(self.client) 203 | 204 | ## EVENT HANDLERS 205 | ## 206 | def event_write(self, event, direct=False, relative=False, tick=False): 207 | #print event.__class__, event 208 | ## Event Filter 209 | if isinstance(event, midi.EndOfTrackEvent): 210 | return 211 | seqev = S.snd_seq_event_t() 212 | ## common 213 | seqev.dest.client = self.write_dest.client 214 | seqev.dest.port = self.write_dest.port 215 | seqev.source.client = self.write_sender.client 216 | seqev.source.port = self.write_sender.port 217 | if direct: 218 | # no scheduling 219 | seqev.queue = S.SND_SEQ_QUEUE_DIRECT 220 | else: 221 | seqev.queue = self.queue 222 | seqev.flags &= (S.SND_SEQ_TIME_STAMP_MASK|S.SND_SEQ_TIME_MODE_MASK) 223 | if relative: 224 | seqev.flags |= S.SND_SEQ_TIME_MODE_REL 225 | else: 226 | seqev.flags |= S.SND_SEQ_TIME_MODE_ABS 227 | if tick: 228 | seqev.flags |= S.SND_SEQ_TIME_STAMP_TICK 229 | seqev.time.tick = event.tick 230 | else: 231 | seqev.flags |= S.SND_SEQ_TIME_STAMP_REAL 232 | sec = int(event.msdelay / 1000) 233 | nsec = int((event.msdelay - (sec * 1000)) * 1000000) 234 | seqev.time.time.tv_sec = sec 235 | seqev.time.time.tv_nsec = nsec 236 | 237 | ## Tempo Change 238 | if isinstance(event, midi.SetTempoEvent): 239 | adjtempo = int(60.0 * 1000000.0 / event.bpm) 240 | seqev.type = S.SND_SEQ_EVENT_TEMPO 241 | seqev.dest.client = S.SND_SEQ_CLIENT_SYSTEM 242 | seqev.dest.port = S.SND_SEQ_PORT_SYSTEM_TIMER 243 | seqev.data.queue.queue = self.queue 244 | seqev.data.queue.param.value = adjtempo 245 | ## Note Event 246 | elif isinstance(event, midi.NoteEvent): 247 | if isinstance(event, midi.NoteOnEvent): 248 | seqev.type = S.SND_SEQ_EVENT_NOTEON 249 | if isinstance(event, midi.NoteOffEvent): 250 | seqev.type = S.SND_SEQ_EVENT_NOTEOFF 251 | seqev.data.note.channel = event.channel 252 | seqev.data.note.note = event.pitch 253 | seqev.data.note.velocity = event.velocity 254 | ## Control Change 255 | elif isinstance(event, midi.ControlChangeEvent): 256 | seqev.type = S.SND_SEQ_EVENT_CONTROLLER 257 | seqev.data.control.channel = event.channel 258 | seqev.data.control.param = event.control 259 | seqev.data.control.value = event.value 260 | ## Program Change 261 | elif isinstance(event, midi.ProgramChangeEvent): 262 | seqev.type = S.SND_SEQ_EVENT_PGMCHANGE 263 | seqev.data.control.channel = event.channel 264 | seqev.data.control.value = event.value 265 | ## Pitch Bench 266 | elif isinstance(event, midi.PitchWheelEvent): 267 | seqev.type = S.SND_SEQ_EVENT_PITCHBEND 268 | seqev.data.control.channel = event.channel 269 | seqev.data.control.value = event.pitch 270 | ## Unknown 271 | else: 272 | print "Warning :: Unknown event type: %s" % event 273 | return None 274 | 275 | err = S.snd_seq_event_output(self.client, seqev) 276 | if (err < 0): self._error(err) 277 | self.drain() 278 | return self.output_buffer_size - err 279 | 280 | def event_read(self): 281 | ev = S.event_input(self.client) 282 | if ev and (ev < 0): self._error(ev) 283 | if ev and ev.type in (S.SND_SEQ_EVENT_NOTEON, S.SND_SEQ_EVENT_NOTEOFF): 284 | if ev.type == S.SND_SEQ_EVENT_NOTEON: 285 | mev = midi.NoteOnEvent() 286 | mev.channel = ev.data.note.channel 287 | mev.pitch = ev.data.note.note 288 | mev.velocity = ev.data.note.velocity 289 | elif ev.type == S.SND_SEQ_EVENT_NOTEOFF: 290 | mev = midi.NoteOffEvent() 291 | mev.channel = ev.data.note.channel 292 | mev.pitch = ev.data.note.note 293 | mev.velocity = ev.data.note.velocity 294 | if ev.time.time.tv_nsec: 295 | # convert to ms 296 | mev.msdeay = \ 297 | (ev.time.time.tv_nsec / 1e6) + (ev.time.time.tv_sec * 1e3) 298 | else: 299 | mev.tick = ev.time.tick 300 | return mev 301 | else: 302 | return None 303 | 304 | class SequencerHardware(Sequencer): 305 | SequencerName = "__hw__" 306 | SequencerStream = S.SND_SEQ_OPEN_DUPLEX 307 | SequencerType = "hw" 308 | SequencerMode = 0 309 | 310 | class Client(object): 311 | def __init__(self, client, name): 312 | self.client = client 313 | self.name = name 314 | self._ports = {} 315 | 316 | def __str__(self): 317 | retstr = '] client(%d) "%s"\n' % (self.client, self.name) 318 | for port in self: 319 | retstr += str(port) 320 | return retstr 321 | 322 | def add_port(self, port, name, caps): 323 | port = self.Port(port, name, caps) 324 | self._ports[name] = port 325 | 326 | def __iter__(self): 327 | return self._ports.itervalues() 328 | 329 | def __len__(self): 330 | return len(self._ports) 331 | 332 | def get_port(self, key): 333 | return self._ports[key] 334 | __getitem__ = get_port 335 | 336 | class Port(object): 337 | def __init__(self, port, name, caps): 338 | self.port = port 339 | self.name = name 340 | self.caps = caps 341 | self.caps_read = self.caps & S.SND_SEQ_PORT_CAP_READ 342 | self.caps_write = self.caps & S.SND_SEQ_PORT_CAP_WRITE 343 | self.caps_subs_read = self.caps & S.SND_SEQ_PORT_CAP_SUBS_READ 344 | self.caps_subs_write = self.caps & S.SND_SEQ_PORT_CAP_SUBS_WRITE 345 | 346 | def __str__(self): 347 | flags = [] 348 | if self.caps_read: flags.append('r') 349 | if self.caps_write: flags.append('w') 350 | if self.caps_subs_read: flags.append('sender') 351 | if self.caps_subs_write: flags.append('receiver') 352 | flags = str.join(', ', flags) 353 | retstr = '] port(%d) [%s] "%s"\n' % (self.port, flags, self.name) 354 | return retstr 355 | 356 | 357 | def init(self): 358 | self._clients = {} 359 | self._init_handle() 360 | self._query_clients() 361 | 362 | def __iter__(self): 363 | return self._clients.itervalues() 364 | 365 | def __len__(self): 366 | return len(self._clients) 367 | 368 | def get_client(self, key): 369 | return self._clients[key] 370 | __getitem__ = get_client 371 | 372 | def get_client_and_port(self, cname, pname): 373 | client = self[cname] 374 | port = client[pname] 375 | return (client.client, port.port) 376 | 377 | def __str__(self): 378 | retstr = '' 379 | for client in self: 380 | retstr += str(client) 381 | return retstr 382 | 383 | def _query_clients(self): 384 | self._clients = {} 385 | S.snd_seq_drop_output(self.client) 386 | cinfo = S.new_client_info() 387 | pinfo = S.new_port_info() 388 | S.snd_seq_client_info_set_client(cinfo, -1) 389 | # for each client 390 | while S.snd_seq_query_next_client(self.client, cinfo) >= 0: 391 | client = S.snd_seq_client_info_get_client(cinfo) 392 | cname = S.snd_seq_client_info_get_name(cinfo) 393 | cobj = self.Client(client, cname) 394 | self._clients[cname] = cobj 395 | # get port data 396 | S.snd_seq_port_info_set_client(pinfo, client) 397 | S.snd_seq_port_info_set_port(pinfo, -1) 398 | while (S.snd_seq_query_next_port(self.client, pinfo) >= 0): 399 | cap = S.snd_seq_port_info_get_capability(pinfo) 400 | client = S.snd_seq_port_info_get_client(pinfo) 401 | port = S.snd_seq_port_info_get_port(pinfo) 402 | pname = S.snd_seq_port_info_get_name(pinfo) 403 | cobj.add_port(port, pname, cap) 404 | 405 | class SequencerRead(Sequencer): 406 | DefaultArguments = { 407 | 'sequencer_name':'__SequencerRead__', 408 | 'sequencer_stream':not S.SND_SEQ_NONBLOCK, 409 | 'alsa_port_caps':S.SND_SEQ_PORT_CAP_WRITE | S.SND_SEQ_PORT_CAP_SUBS_WRITE, 410 | } 411 | 412 | def subscribe_port(self, client, port): 413 | sender = self._new_address(client, port) 414 | dest = self._my_address() 415 | subscribe = self._new_subscribe(sender, dest, read=True) 416 | S.snd_seq_port_subscribe_set_time_update(subscribe, True) 417 | #S.snd_seq_port_subscribe_set_time_real(subscribe, True) 418 | self._subscribe_port(subscribe) 419 | 420 | class SequencerWrite(Sequencer): 421 | DefaultArguments = { 422 | 'sequencer_name':'__SequencerWrite__', 423 | 'sequencer_stream':not S.SND_SEQ_NONBLOCK, 424 | 'alsa_port_caps':S.SND_SEQ_PORT_CAP_READ | S.SND_SEQ_PORT_CAP_SUBS_READ 425 | } 426 | 427 | def subscribe_port(self, client, port): 428 | sender = self._my_address() 429 | dest = self._new_address(client, port) 430 | subscribe = self._new_subscribe(sender, dest, read=False) 431 | self._subscribe_port(subscribe) 432 | 433 | class SequencerDuplex(Sequencer): 434 | DefaultArguments = { 435 | 'sequencer_name':'__SequencerWrite__', 436 | 'sequencer_stream':not S.SND_SEQ_NONBLOCK, 437 | 'alsa_port_caps':S.SND_SEQ_PORT_CAP_READ | S.SND_SEQ_PORT_CAP_SUBS_READ | 438 | S.SND_SEQ_PORT_CAP_WRITE | S.SND_SEQ_PORT_CAP_SUBS_WRITE 439 | } 440 | 441 | def subscribe_read_port(self, client, port): 442 | sender = self._new_address(client, port) 443 | dest = self._my_address() 444 | subscribe = self._new_subscribe(sender, dest, read=True) 445 | S.snd_seq_port_subscribe_set_time_update(subscribe, True) 446 | #S.snd_seq_port_subscribe_set_time_real(subscribe, True) 447 | self._subscribe_port(subscribe) 448 | 449 | def subscribe_write_port(self, client, port): 450 | sender = self._my_address() 451 | dest = self._new_address(client, port) 452 | subscribe = self._new_subscribe(sender, dest, read=False) 453 | self._subscribe_port(subscribe) 454 | 455 | -------------------------------------------------------------------------------- /src/sequencer_alsa/sequencer_alsa.i: -------------------------------------------------------------------------------- 1 | %module sequencer_alsa 2 | %feature("typemaps"); 3 | %feature("newobject"); 4 | 5 | %{ 6 | #include 7 | #include 8 | 9 | snd_seq_t* 10 | open_client(const char *name, const char *type, int stream, int mode) 11 | { 12 | snd_seq_t *handle; 13 | int err; 14 | err = snd_seq_open(&handle, type, stream, mode); 15 | if (err < 0) 16 | { 17 | /* XXX: set global error */ 18 | return NULL; 19 | } 20 | snd_seq_set_client_name(handle, name); 21 | return handle; 22 | } 23 | 24 | int 25 | init_queue_tempo(snd_seq_t *handle, int queue, int bpm, int ppq) 26 | { 27 | snd_seq_queue_tempo_t *tempo; 28 | snd_seq_queue_tempo_alloca(&tempo); 29 | snd_seq_queue_tempo_set_tempo(tempo, bpm); 30 | snd_seq_queue_tempo_set_ppq(tempo, ppq); 31 | return snd_seq_set_queue_tempo(handle, queue, tempo); 32 | } 33 | 34 | snd_seq_event_t* 35 | event_input(snd_seq_t *handle) 36 | { 37 | int err; 38 | snd_seq_event_t *ev; 39 | err = snd_seq_event_input(handle, &ev); 40 | if (err < 0) 41 | { 42 | /* XXX: does SWIG prevent us from raising an exception? */ 43 | /* PyErr_SetString(PyExc_IOError, snd_strerror(err)); */ 44 | return NULL; 45 | } 46 | return ev; 47 | } 48 | 49 | int snd_seq_control_queue_eventless(snd_seq_t *handle, 50 | int queue, int type, int value) 51 | { 52 | return snd_seq_control_queue(handle, queue, type, value, NULL); 53 | } 54 | 55 | 56 | static PyObject * 57 | client_poll_descriptors(snd_seq_t *handle) 58 | { 59 | PyObject *ret; 60 | int npfd, idx; 61 | struct pollfd *pfd; 62 | npfd = snd_seq_poll_descriptors_count(handle, POLLIN); 63 | pfd = (struct pollfd *)calloc(npfd, sizeof(struct pollfd)); 64 | snd_seq_poll_descriptors(handle, pfd, npfd, POLLIN); 65 | 66 | ret = PyList_New(0); 67 | for (idx = 0; idx < npfd; idx++) 68 | { 69 | PyList_Append(ret, PyInt_FromLong((long)(pfd[idx].fd))); 70 | } 71 | free(pfd); 72 | return ret; 73 | } 74 | 75 | snd_seq_queue_status_t* 76 | new_queue_status(snd_seq_t *handle, int queue) 77 | { 78 | snd_seq_queue_status_t *qstatus; 79 | int err; 80 | err = snd_seq_queue_status_malloc(&qstatus); 81 | if (err < 0){ 82 | return NULL; 83 | } 84 | return qstatus; 85 | } 86 | 87 | void 88 | free_queue_status(snd_seq_queue_status_t *qstatus) 89 | { 90 | snd_seq_queue_status_free(qstatus); 91 | } 92 | 93 | snd_seq_client_info_t* 94 | new_client_info(void) 95 | { 96 | snd_seq_client_info_t *cinfo; 97 | int err; 98 | err = snd_seq_client_info_malloc(&cinfo); 99 | if (err < 0){ 100 | return NULL; 101 | } 102 | return cinfo; 103 | } 104 | 105 | snd_seq_port_info_t* 106 | new_port_info(void) 107 | { 108 | snd_seq_port_info_t *pinfo; 109 | int err; 110 | err = snd_seq_port_info_malloc(&pinfo); 111 | if (err < 0){ 112 | return NULL; 113 | } 114 | return pinfo; 115 | } 116 | 117 | snd_seq_port_subscribe_t* 118 | new_port_subscribe(void) 119 | { 120 | snd_seq_port_subscribe_t *subs; 121 | int err; 122 | err = snd_seq_port_subscribe_malloc(&subs); 123 | if (err < 0){ 124 | return NULL; 125 | } 126 | return subs; 127 | } 128 | %} 129 | 130 | snd_seq_t *open_client(const char *name, const char *type, int stream, int mode); 131 | 132 | snd_seq_port_subscribe_t *new_port_subscribe(); 133 | 134 | snd_seq_queue_status_t *new_queue_status(snd_seq_t *handle, int queue); 135 | void free_queue_status(snd_seq_queue_status_t *qstatus); 136 | 137 | snd_seq_port_info_t *new_port_info(); 138 | 139 | snd_seq_client_info_t *new_client_info(); 140 | 141 | snd_seq_event_t *event_input(snd_seq_t *handle); 142 | int snd_seq_control_queue_eventless(snd_seq_t *handle, int queue, int type, int value); 143 | int init_queue_tempo(snd_seq_t *handle, int queue, int bpm, int ppq); 144 | PyObject *client_poll_descriptors(snd_seq_t *handle); 145 | 146 | %typemap(out) ssize_t { $result = PyInt_FromLong($1); } 147 | %typemap(in) ssize_t { $1 = PyInt_AsLong($input); } 148 | 149 | #define __attribute__(x) 150 | 151 | %include alsa/seq.h 152 | %include alsa/seqmid.h 153 | %include alsa/seq_event.h 154 | %include alsa/seq_midi_event.h 155 | %include alsa/error.h 156 | -------------------------------------------------------------------------------- /src/sequencer_osx/CoreMIDI.framework: -------------------------------------------------------------------------------- 1 | /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreMIDI.framework -------------------------------------------------------------------------------- /src/sequencer_osx/_sequencer_osx.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sniperwrb/python-midi/ec8071b56500dbf58d5a5650ca81990d855dc49f/src/sequencer_osx/_sequencer_osx.so -------------------------------------------------------------------------------- /src/sequencer_osx/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sniperwrb/python-midi/ec8071b56500dbf58d5a5650ca81990d855dc49f/src/sequencer_osx/a.out -------------------------------------------------------------------------------- /src/sequencer_osx/backup.i: -------------------------------------------------------------------------------- 1 | %module sequencer_osx 2 | %feature("typemaps"); 3 | %feature("newobject"); 4 | 5 | %{ 6 | #include 7 | #include 8 | 9 | /* MIDIClientCreate */ 10 | MIDIClientRef *_MIDIClientCreate(const char *cName) 11 | { 12 | OSStatus err; 13 | CFStringRef ClientName; 14 | MIDIClientRef *client; 15 | 16 | /* allocate client handle */ 17 | client = (MIDIClientRef *)malloc(sizeof(MIDIClientRef)); 18 | if(!client) 19 | { 20 | PyErr_SetString(PyExc_SystemError, "Expecting a string"); 21 | return NULL; 22 | } 23 | 24 | /* create client handle */ 25 | ClientName = CFStringCreateWithCString(NULL, cName, kCFStringEncodingASCII); 26 | err = MIDIClientCreate(ClientName, NULL, NULL, client); 27 | if(err != noErr) 28 | { 29 | PyErr_SetString(PyExc_SystemError, "Error during MIDIClientCreate."); 30 | return NULL; 31 | } 32 | return client; 33 | } 34 | 35 | /* MIDIClientDispose */ 36 | void _MIDIClientDispose(MIDIClientRef *client) 37 | { 38 | OSStatus err; 39 | err = MIDIClientDispose(*client); 40 | free(client); 41 | if(err != noErr) 42 | { 43 | PyErr_SetString(PyExc_SystemError, "Error during MIDIClientDispose.."); 44 | } 45 | } 46 | 47 | /* MIDISourceCreate */ 48 | MIDIEndpointRef *_MIDISourceCreate(MIDIClientRef *client, CFStringRef name) 49 | { 50 | OSStatus err; 51 | CFStringRef ClientName; 52 | 53 | /* allocate client handle */ 54 | MIDIClientRef *client = (MIDIClientRef *)malloc(sizeof(MIDIClientRef)); 55 | if(!client) 56 | { 57 | PyErr_SetString(PyExc_SystemError, "Expecting a string"); 58 | return NULL; 59 | } 60 | 61 | MIDISourceCreate(*client, 62 | MIDIClientRef client, CFStringRef name, MIDIEndpointRef * outSrc ); 63 | 64 | /* create client handle */ 65 | ClientName = CFStringCreateWithCString(NULL, cName, kCFStringEncodingASCII); 66 | err = MIDIClientCreate(ClientName, NULL, NULL, client); 67 | if(err != noErr) 68 | { 69 | PyErr_SetString(PyExc_SystemError, "Error during MIDIClientCreate."); 70 | return NULL; 71 | } 72 | return client; 73 | } 74 | 75 | /* MIDIGetNumberOfDevices */ 76 | unsigned long _MIDIGetNumberOfDevices() 77 | { 78 | return (unsigned long) MIDIGetNumberOfDevices(); 79 | } 80 | 81 | %} 82 | 83 | %typemap(in) CFStringRef 84 | { 85 | if (!PyString_Check($input)) 86 | { 87 | PyErr_SetString(PyExc_ValueError, "Expecting a string"); 88 | return NULL; 89 | } 90 | $1 = CFStringCreateWithCString(NULL, PyString_AsString($input), kCFStringEncodingASCII); 91 | } 92 | 93 | %typemap(freearg) CFStringRef 94 | { 95 | CFRelease($1); 96 | } 97 | 98 | %typemap(arginit) CFStringRef 99 | { 100 | $1 = NULL; 101 | } 102 | 103 | %typemap(out) CFStringRef 104 | { 105 | unsigned int len = CFStringGetLength($1); 106 | char *buffer = malloc(len + 1); 107 | if (CFStringGetCString($1, buffer, len + 1, kCFStringEncodingASCII)) 108 | { 109 | $result = PyString_FromStringAndSize(buffer, len); 110 | free(buffer); 111 | CFRelease($1); 112 | } else 113 | { 114 | PyErr_SetString(PyExc_ValueError, "Can't convert string"); 115 | CFRelease($1); 116 | return NULL; 117 | } 118 | } 119 | 120 | unsigned long _MIDIGetNumberOfDevices(); 121 | MIDIClientRef *_MIDIClientCreate(const char *cName); 122 | void _MIDIClientDispose(MIDIClientRef *client); 123 | 124 | -------------------------------------------------------------------------------- /src/sequencer_osx/cfstring-typemaps-example-1.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sniperwrb/python-midi/ec8071b56500dbf58d5a5650ca81990d855dc49f/src/sequencer_osx/cfstring-typemaps-example-1.0.tar.gz -------------------------------------------------------------------------------- /src/sequencer_osx/cfstring-typemaps-example-1.0/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.0 2 | Name: cfstring-typemaps-example 3 | Version: 1.0 4 | Summary: UNKNOWN 5 | Home-page: UNKNOWN 6 | Author: UNKNOWN 7 | Author-email: UNKNOWN 8 | License: UNKNOWN 9 | Description: UNKNOWN 10 | Platform: UNKNOWN 11 | -------------------------------------------------------------------------------- /src/sequencer_osx/cfstring-typemaps-example-1.0/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | CFStringRef uppercase(CFStringRef s) 4 | { 5 | CFLocaleRef localeRef = CFLocaleCopyCurrent(); 6 | 7 | CFMutableStringRef ms = CFStringCreateMutableCopy(NULL, 0, s); 8 | CFStringUppercase(ms, localeRef); 9 | 10 | CFRelease(localeRef); 11 | 12 | return ms; 13 | } 14 | -------------------------------------------------------------------------------- /src/sequencer_osx/cfstring-typemaps-example-1.0/example.i: -------------------------------------------------------------------------------- 1 | /* File : example.i */ 2 | %module example 3 | 4 | %{ 5 | #include 6 | %} 7 | 8 | %typemap(in) CFStringRef { 9 | if (!PyString_Check($input)) { 10 | PyErr_SetString(PyExc_ValueError, "Expecting a string"); 11 | return NULL; 12 | } 13 | $1 = CFStringCreateWithCString(NULL, PyString_AsString($input), kCFStringEncodingASCII); 14 | } 15 | 16 | %typemap(freearg) CFStringRef { 17 | CFRelease($1); 18 | } 19 | 20 | %typemap(arginit) CFStringRef { 21 | $1 = NULL; 22 | } 23 | 24 | %typemap(out) CFStringRef { 25 | unsigned int len = CFStringGetLength($1); 26 | char *buffer = malloc(len + 1); 27 | if (CFStringGetCString($1, buffer, len + 1, kCFStringEncodingASCII)) { 28 | $result = PyString_FromStringAndSize(buffer, len); 29 | free(buffer); 30 | CFRelease($1); 31 | } 32 | else { 33 | PyErr_SetString(PyExc_ValueError, "Can't convert string"); 34 | CFRelease($1); 35 | return NULL; 36 | } 37 | } 38 | 39 | extern CFStringRef uppercase(CFStringRef s); 40 | -------------------------------------------------------------------------------- /src/sequencer_osx/cfstring-typemaps-example-1.0/setup.py: -------------------------------------------------------------------------------- 1 | import distutils 2 | from distutils.core import setup, Extension 3 | 4 | setup(name = "cfstring-typemaps-example", 5 | version = "1.0", 6 | ext_modules = [Extension("_example", 7 | ["example.i","example.c"], 8 | extra_link_args=['-framework','CoreFoundation'])]) 9 | -------------------------------------------------------------------------------- /src/sequencer_osx/make.sh: -------------------------------------------------------------------------------- 1 | swig -python sequencer_osx.i 2 | gcc -shared -framework CoreFoundation -framework CoreMIDI -I/usr/local/include/python2.6 -L/usr/local/lib -lpython sequencer_osx_wrap.c -o _sequencer_osx.so 3 | -------------------------------------------------------------------------------- /src/sequencer_osx/sequencer_osx.i: -------------------------------------------------------------------------------- 1 | %module sequencer_osx 2 | %feature("typemaps"); 3 | %feature("newobject"); 4 | 5 | %{ 6 | #include 7 | #include 8 | 9 | /* MIDIClientCreate */ 10 | MIDIClientRef _MIDIClientCreate(CFStringRef clientName) 11 | { 12 | OSStatus err; 13 | MIDIClientRef client; 14 | 15 | /* create client handle */ 16 | err = MIDIClientCreate(clientName, NULL, NULL, &client); 17 | if(err != noErr) 18 | { 19 | PyErr_SetString(PyExc_SystemError, "Error during MIDIClientCreate."); 20 | return 0; 21 | } 22 | return client; 23 | } 24 | 25 | /* MIDIClientDispose */ 26 | void _MIDIClientDispose(MIDIClientRef client) 27 | { 28 | OSStatus err; 29 | err = MIDIClientDispose(client); 30 | if(err != noErr) 31 | { 32 | PyErr_SetString(PyExc_SystemError, "Error during MIDIClientDispose."); 33 | } 34 | } 35 | 36 | /* MIDISourceCreate */ 37 | MIDIEndpointRef _MIDISourceCreate(MIDIClientRef client, CFStringRef sourceName) 38 | { 39 | OSStatus err; 40 | MIDIEndpointRef outSrc; 41 | err = MIDISourceCreate(client, sourceName, &outSrc); 42 | if(err != noErr) 43 | { 44 | PyErr_SetString(PyExc_SystemError, "Error during MIDISourceCreate."); 45 | return 0; 46 | } 47 | return outSrc; 48 | } 49 | 50 | /* MIDIOutputPortCreate */ 51 | MIDIPortRef _MIDIOutputPortCreate(MIDIClientRef client, CFStringRef portName) 52 | { 53 | OSStatus err; 54 | MIDIPortRef outPort; 55 | err = MIDIOutputPortCreate(client, portName, &outPort); 56 | if(err != noErr) 57 | { 58 | PyErr_SetString(PyExc_SystemError, "Error during MIDIOutputPortCreate."); 59 | return 0; 60 | } 61 | return outPort; 62 | } 63 | 64 | /* MIDIPortConnectSource */ 65 | void _MIDIPortConnectSource(MIDIPortRef port, MIDIEndpointRef endpoint) 66 | { 67 | OSStatus err; 68 | MIDIPortRef outPort; 69 | err = MIDIPortConnectSource(port, endpoint, NULL); 70 | if(err != noErr) 71 | { 72 | PyErr_SetString(PyExc_SystemError, "Error during MIDIPortConnectSource."); 73 | } 74 | } 75 | 76 | /* 77 | void _MIDISend(MIDIEndpointRef *midi_source, unsigned char val) 78 | { 79 | MIDIPacketList pktlist; 80 | MIDIPacket p; 81 | Byte data[3]; 82 | p_head = MIDIPacketListInit(&pktlist); 83 | data[0] = 176; // Control change 84 | data[1] = 1; // Modulation 85 | data[2] = val; // Value 86 | MIDIPacketListAdd( &pktlist, sizeof(p), p_head, 0, 3, data); 87 | MIDIReceived(*midi_source, &pktlist); 88 | } 89 | */ 90 | 91 | 92 | 93 | /* MIDIGetNumberOfDevices */ 94 | unsigned long _MIDIGetNumberOfDevices() 95 | { 96 | return (unsigned long) MIDIGetNumberOfDevices(); 97 | } 98 | 99 | %} 100 | 101 | %typemap(in) CFStringRef 102 | { 103 | if (!PyString_Check($input)) 104 | { 105 | PyErr_SetString(PyExc_ValueError, "Expecting a string"); 106 | return NULL; 107 | } 108 | $1 = CFStringCreateWithCString(NULL, PyString_AsString($input), kCFStringEncodingASCII); 109 | } 110 | 111 | %typemap(freearg) MIDIClientRef* 112 | { 113 | OSStatus err; 114 | err = MIDIClientDispose($1); 115 | if(err != noErr) 116 | { 117 | PyErr_SetString(PyExc_SystemError, "Error during MIDIClientDispose."); 118 | } 119 | } 120 | 121 | %typemap(freearg) CFStringRef 122 | { 123 | CFRelease($1); 124 | } 125 | 126 | %typemap(arginit) CFStringRef 127 | { 128 | $1 = NULL; 129 | } 130 | 131 | %typemap(out) CFStringRef 132 | { 133 | unsigned int len = CFStringGetLength($1); 134 | char *buffer = malloc(len + 1); 135 | if (CFStringGetCString($1, buffer, len + 1, kCFStringEncodingASCII)) 136 | { 137 | $result = PyString_FromStringAndSize(buffer, len); 138 | free(buffer); 139 | CFRelease($1); 140 | } else 141 | { 142 | PyErr_SetString(PyExc_ValueError, "Can't convert string"); 143 | CFRelease($1); 144 | return NULL; 145 | } 146 | } 147 | 148 | unsigned long _MIDIGetNumberOfDevices(); 149 | MIDIClientRef _MIDIClientCreate(CFStringRef clientName); 150 | void _MIDIClientDispose(MIDIClientRef client); 151 | MIDIEndpointRef _MIDISourceCreate(MIDIClientRef client, CFStringRef sourceName); 152 | MIDIPortRef _MIDIOutputPortCreate(MIDIClientRef client, CFStringRef portName); 153 | void _MIDIPortConnectSource(MIDIPortRef port, MIDIEndpointRef endpoint); 154 | 155 | -------------------------------------------------------------------------------- /src/sequencer_osx/sequencer_osx.py: -------------------------------------------------------------------------------- 1 | # This file was automatically generated by SWIG (http://www.swig.org). 2 | # Version 1.3.31 3 | # 4 | # Don't modify this file, modify the SWIG interface instead. 5 | # This file is compatible with both classic and new-style classes. 6 | 7 | import _sequencer_osx 8 | import new 9 | new_instancemethod = new.instancemethod 10 | try: 11 | _swig_property = property 12 | except NameError: 13 | pass # Python < 2.2 doesn't have 'property'. 14 | def _swig_setattr_nondynamic(self,class_type,name,value,static=1): 15 | if (name == "thisown"): return self.this.own(value) 16 | if (name == "this"): 17 | if type(value).__name__ == 'PySwigObject': 18 | self.__dict__[name] = value 19 | return 20 | method = class_type.__swig_setmethods__.get(name,None) 21 | if method: return method(self,value) 22 | if (not static) or hasattr(self,name): 23 | self.__dict__[name] = value 24 | else: 25 | raise AttributeError("You cannot add attributes to %s" % self) 26 | 27 | def _swig_setattr(self,class_type,name,value): 28 | return _swig_setattr_nondynamic(self,class_type,name,value,0) 29 | 30 | def _swig_getattr(self,class_type,name): 31 | if (name == "thisown"): return self.this.own() 32 | method = class_type.__swig_getmethods__.get(name,None) 33 | if method: return method(self) 34 | raise AttributeError,name 35 | 36 | def _swig_repr(self): 37 | try: strthis = "proxy of " + self.this.__repr__() 38 | except: strthis = "" 39 | return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,) 40 | 41 | import types 42 | try: 43 | _object = types.ObjectType 44 | _newclass = 1 45 | except AttributeError: 46 | class _object : pass 47 | _newclass = 0 48 | del types 49 | 50 | 51 | _MIDIGetNumberOfDevices = _sequencer_osx._MIDIGetNumberOfDevices 52 | _MIDIClientCreate = _sequencer_osx._MIDIClientCreate 53 | _MIDIClientDispose = _sequencer_osx._MIDIClientDispose 54 | _MIDISourceCreate = _sequencer_osx._MIDISourceCreate 55 | _MIDIOutputPortCreate = _sequencer_osx._MIDIOutputPortCreate 56 | _MIDIPortConnectSource = _sequencer_osx._MIDIPortConnectSource 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/sequencer_osx/sequencer_osx_wrap.c: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------------- 2 | * This file was automatically generated by SWIG (http://www.swig.org). 3 | * Version 1.3.31 4 | * 5 | * This file is not intended to be easily readable and contains a number of 6 | * coding conventions designed to improve portability and efficiency. Do not make 7 | * changes to this file unless you know what you are doing--modify the SWIG 8 | * interface file instead. 9 | * ----------------------------------------------------------------------------- */ 10 | 11 | #define SWIGPYTHON 12 | #define SWIG_PYTHON_DIRECTOR_NO_VTABLE 13 | /* ----------------------------------------------------------------------------- 14 | * This section contains generic SWIG labels for method/variable 15 | * declarations/attributes, and other compiler dependent labels. 16 | * ----------------------------------------------------------------------------- */ 17 | 18 | /* template workaround for compilers that cannot correctly implement the C++ standard */ 19 | #ifndef SWIGTEMPLATEDISAMBIGUATOR 20 | # if defined(__SUNPRO_CC) 21 | # if (__SUNPRO_CC <= 0x560) 22 | # define SWIGTEMPLATEDISAMBIGUATOR template 23 | # else 24 | # define SWIGTEMPLATEDISAMBIGUATOR 25 | # endif 26 | # else 27 | # define SWIGTEMPLATEDISAMBIGUATOR 28 | # endif 29 | #endif 30 | 31 | /* inline attribute */ 32 | #ifndef SWIGINLINE 33 | # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__)) 34 | # define SWIGINLINE inline 35 | # else 36 | # define SWIGINLINE 37 | # endif 38 | #endif 39 | 40 | /* attribute recognised by some compilers to avoid 'unused' warnings */ 41 | #ifndef SWIGUNUSED 42 | # if defined(__GNUC__) 43 | # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) 44 | # define SWIGUNUSED __attribute__ ((__unused__)) 45 | # else 46 | # define SWIGUNUSED 47 | # endif 48 | # elif defined(__ICC) 49 | # define SWIGUNUSED __attribute__ ((__unused__)) 50 | # else 51 | # define SWIGUNUSED 52 | # endif 53 | #endif 54 | 55 | #ifndef SWIGUNUSEDPARM 56 | # ifdef __cplusplus 57 | # define SWIGUNUSEDPARM(p) 58 | # else 59 | # define SWIGUNUSEDPARM(p) p SWIGUNUSED 60 | # endif 61 | #endif 62 | 63 | /* internal SWIG method */ 64 | #ifndef SWIGINTERN 65 | # define SWIGINTERN static SWIGUNUSED 66 | #endif 67 | 68 | /* internal inline SWIG method */ 69 | #ifndef SWIGINTERNINLINE 70 | # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE 71 | #endif 72 | 73 | /* exporting methods */ 74 | #if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) 75 | # ifndef GCC_HASCLASSVISIBILITY 76 | # define GCC_HASCLASSVISIBILITY 77 | # endif 78 | #endif 79 | 80 | #ifndef SWIGEXPORT 81 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 82 | # if defined(STATIC_LINKED) 83 | # define SWIGEXPORT 84 | # else 85 | # define SWIGEXPORT __declspec(dllexport) 86 | # endif 87 | # else 88 | # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) 89 | # define SWIGEXPORT __attribute__ ((visibility("default"))) 90 | # else 91 | # define SWIGEXPORT 92 | # endif 93 | # endif 94 | #endif 95 | 96 | /* calling conventions for Windows */ 97 | #ifndef SWIGSTDCALL 98 | # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 99 | # define SWIGSTDCALL __stdcall 100 | # else 101 | # define SWIGSTDCALL 102 | # endif 103 | #endif 104 | 105 | /* Deal with Microsoft's attempt at deprecating C standard runtime functions */ 106 | #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) 107 | # define _CRT_SECURE_NO_DEPRECATE 108 | #endif 109 | 110 | 111 | /* Python.h has to appear first */ 112 | #include 113 | 114 | /* ----------------------------------------------------------------------------- 115 | * swigrun.swg 116 | * 117 | * This file contains generic CAPI SWIG runtime support for pointer 118 | * type checking. 119 | * ----------------------------------------------------------------------------- */ 120 | 121 | /* This should only be incremented when either the layout of swig_type_info changes, 122 | or for whatever reason, the runtime changes incompatibly */ 123 | #define SWIG_RUNTIME_VERSION "3" 124 | 125 | /* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ 126 | #ifdef SWIG_TYPE_TABLE 127 | # define SWIG_QUOTE_STRING(x) #x 128 | # define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) 129 | # define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) 130 | #else 131 | # define SWIG_TYPE_TABLE_NAME 132 | #endif 133 | 134 | /* 135 | You can use the SWIGRUNTIME and SWIGRUNTIMEINLINE macros for 136 | creating a static or dynamic library from the swig runtime code. 137 | In 99.9% of the cases, swig just needs to declare them as 'static'. 138 | 139 | But only do this if is strictly necessary, ie, if you have problems 140 | with your compiler or so. 141 | */ 142 | 143 | #ifndef SWIGRUNTIME 144 | # define SWIGRUNTIME SWIGINTERN 145 | #endif 146 | 147 | #ifndef SWIGRUNTIMEINLINE 148 | # define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE 149 | #endif 150 | 151 | /* Generic buffer size */ 152 | #ifndef SWIG_BUFFER_SIZE 153 | # define SWIG_BUFFER_SIZE 1024 154 | #endif 155 | 156 | /* Flags for pointer conversions */ 157 | #define SWIG_POINTER_DISOWN 0x1 158 | 159 | /* Flags for new pointer objects */ 160 | #define SWIG_POINTER_OWN 0x1 161 | 162 | 163 | /* 164 | Flags/methods for returning states. 165 | 166 | The swig conversion methods, as ConvertPtr, return and integer 167 | that tells if the conversion was successful or not. And if not, 168 | an error code can be returned (see swigerrors.swg for the codes). 169 | 170 | Use the following macros/flags to set or process the returning 171 | states. 172 | 173 | In old swig versions, you usually write code as: 174 | 175 | if (SWIG_ConvertPtr(obj,vptr,ty.flags) != -1) { 176 | // success code 177 | } else { 178 | //fail code 179 | } 180 | 181 | Now you can be more explicit as: 182 | 183 | int res = SWIG_ConvertPtr(obj,vptr,ty.flags); 184 | if (SWIG_IsOK(res)) { 185 | // success code 186 | } else { 187 | // fail code 188 | } 189 | 190 | that seems to be the same, but now you can also do 191 | 192 | Type *ptr; 193 | int res = SWIG_ConvertPtr(obj,(void **)(&ptr),ty.flags); 194 | if (SWIG_IsOK(res)) { 195 | // success code 196 | if (SWIG_IsNewObj(res) { 197 | ... 198 | delete *ptr; 199 | } else { 200 | ... 201 | } 202 | } else { 203 | // fail code 204 | } 205 | 206 | I.e., now SWIG_ConvertPtr can return new objects and you can 207 | identify the case and take care of the deallocation. Of course that 208 | requires also to SWIG_ConvertPtr to return new result values, as 209 | 210 | int SWIG_ConvertPtr(obj, ptr,...) { 211 | if () { 212 | if () { 213 | *ptr = ; 214 | return SWIG_NEWOBJ; 215 | } else { 216 | *ptr = ; 217 | return SWIG_OLDOBJ; 218 | } 219 | } else { 220 | return SWIG_BADOBJ; 221 | } 222 | } 223 | 224 | Of course, returning the plain '0(success)/-1(fail)' still works, but you can be 225 | more explicit by returning SWIG_BADOBJ, SWIG_ERROR or any of the 226 | swig errors code. 227 | 228 | Finally, if the SWIG_CASTRANK_MODE is enabled, the result code 229 | allows to return the 'cast rank', for example, if you have this 230 | 231 | int food(double) 232 | int fooi(int); 233 | 234 | and you call 235 | 236 | food(1) // cast rank '1' (1 -> 1.0) 237 | fooi(1) // cast rank '0' 238 | 239 | just use the SWIG_AddCast()/SWIG_CheckState() 240 | 241 | 242 | */ 243 | #define SWIG_OK (0) 244 | #define SWIG_ERROR (-1) 245 | #define SWIG_IsOK(r) (r >= 0) 246 | #define SWIG_ArgError(r) ((r != SWIG_ERROR) ? r : SWIG_TypeError) 247 | 248 | /* The CastRankLimit says how many bits are used for the cast rank */ 249 | #define SWIG_CASTRANKLIMIT (1 << 8) 250 | /* The NewMask denotes the object was created (using new/malloc) */ 251 | #define SWIG_NEWOBJMASK (SWIG_CASTRANKLIMIT << 1) 252 | /* The TmpMask is for in/out typemaps that use temporal objects */ 253 | #define SWIG_TMPOBJMASK (SWIG_NEWOBJMASK << 1) 254 | /* Simple returning values */ 255 | #define SWIG_BADOBJ (SWIG_ERROR) 256 | #define SWIG_OLDOBJ (SWIG_OK) 257 | #define SWIG_NEWOBJ (SWIG_OK | SWIG_NEWOBJMASK) 258 | #define SWIG_TMPOBJ (SWIG_OK | SWIG_TMPOBJMASK) 259 | /* Check, add and del mask methods */ 260 | #define SWIG_AddNewMask(r) (SWIG_IsOK(r) ? (r | SWIG_NEWOBJMASK) : r) 261 | #define SWIG_DelNewMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_NEWOBJMASK) : r) 262 | #define SWIG_IsNewObj(r) (SWIG_IsOK(r) && (r & SWIG_NEWOBJMASK)) 263 | #define SWIG_AddTmpMask(r) (SWIG_IsOK(r) ? (r | SWIG_TMPOBJMASK) : r) 264 | #define SWIG_DelTmpMask(r) (SWIG_IsOK(r) ? (r & ~SWIG_TMPOBJMASK) : r) 265 | #define SWIG_IsTmpObj(r) (SWIG_IsOK(r) && (r & SWIG_TMPOBJMASK)) 266 | 267 | 268 | /* Cast-Rank Mode */ 269 | #if defined(SWIG_CASTRANK_MODE) 270 | # ifndef SWIG_TypeRank 271 | # define SWIG_TypeRank unsigned long 272 | # endif 273 | # ifndef SWIG_MAXCASTRANK /* Default cast allowed */ 274 | # define SWIG_MAXCASTRANK (2) 275 | # endif 276 | # define SWIG_CASTRANKMASK ((SWIG_CASTRANKLIMIT) -1) 277 | # define SWIG_CastRank(r) (r & SWIG_CASTRANKMASK) 278 | SWIGINTERNINLINE int SWIG_AddCast(int r) { 279 | return SWIG_IsOK(r) ? ((SWIG_CastRank(r) < SWIG_MAXCASTRANK) ? (r + 1) : SWIG_ERROR) : r; 280 | } 281 | SWIGINTERNINLINE int SWIG_CheckState(int r) { 282 | return SWIG_IsOK(r) ? SWIG_CastRank(r) + 1 : 0; 283 | } 284 | #else /* no cast-rank mode */ 285 | # define SWIG_AddCast 286 | # define SWIG_CheckState(r) (SWIG_IsOK(r) ? 1 : 0) 287 | #endif 288 | 289 | 290 | 291 | 292 | #include 293 | 294 | #ifdef __cplusplus 295 | extern "C" { 296 | #endif 297 | 298 | typedef void *(*swig_converter_func)(void *); 299 | typedef struct swig_type_info *(*swig_dycast_func)(void **); 300 | 301 | /* Structure to store inforomation on one type */ 302 | typedef struct swig_type_info { 303 | const char *name; /* mangled name of this type */ 304 | const char *str; /* human readable name of this type */ 305 | swig_dycast_func dcast; /* dynamic cast function down a hierarchy */ 306 | struct swig_cast_info *cast; /* linked list of types that can cast into this type */ 307 | void *clientdata; /* language specific type data */ 308 | int owndata; /* flag if the structure owns the clientdata */ 309 | } swig_type_info; 310 | 311 | /* Structure to store a type and conversion function used for casting */ 312 | typedef struct swig_cast_info { 313 | swig_type_info *type; /* pointer to type that is equivalent to this type */ 314 | swig_converter_func converter; /* function to cast the void pointers */ 315 | struct swig_cast_info *next; /* pointer to next cast in linked list */ 316 | struct swig_cast_info *prev; /* pointer to the previous cast */ 317 | } swig_cast_info; 318 | 319 | /* Structure used to store module information 320 | * Each module generates one structure like this, and the runtime collects 321 | * all of these structures and stores them in a circularly linked list.*/ 322 | typedef struct swig_module_info { 323 | swig_type_info **types; /* Array of pointers to swig_type_info structures that are in this module */ 324 | size_t size; /* Number of types in this module */ 325 | struct swig_module_info *next; /* Pointer to next element in circularly linked list */ 326 | swig_type_info **type_initial; /* Array of initially generated type structures */ 327 | swig_cast_info **cast_initial; /* Array of initially generated casting structures */ 328 | void *clientdata; /* Language specific module data */ 329 | } swig_module_info; 330 | 331 | /* 332 | Compare two type names skipping the space characters, therefore 333 | "char*" == "char *" and "Class" == "Class", etc. 334 | 335 | Return 0 when the two name types are equivalent, as in 336 | strncmp, but skipping ' '. 337 | */ 338 | SWIGRUNTIME int 339 | SWIG_TypeNameComp(const char *f1, const char *l1, 340 | const char *f2, const char *l2) { 341 | for (;(f1 != l1) && (f2 != l2); ++f1, ++f2) { 342 | while ((*f1 == ' ') && (f1 != l1)) ++f1; 343 | while ((*f2 == ' ') && (f2 != l2)) ++f2; 344 | if (*f1 != *f2) return (*f1 > *f2) ? 1 : -1; 345 | } 346 | return (l1 - f1) - (l2 - f2); 347 | } 348 | 349 | /* 350 | Check type equivalence in a name list like ||... 351 | Return 0 if not equal, 1 if equal 352 | */ 353 | SWIGRUNTIME int 354 | SWIG_TypeEquiv(const char *nb, const char *tb) { 355 | int equiv = 0; 356 | const char* te = tb + strlen(tb); 357 | const char* ne = nb; 358 | while (!equiv && *ne) { 359 | for (nb = ne; *ne; ++ne) { 360 | if (*ne == '|') break; 361 | } 362 | equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; 363 | if (*ne) ++ne; 364 | } 365 | return equiv; 366 | } 367 | 368 | /* 369 | Check type equivalence in a name list like ||... 370 | Return 0 if equal, -1 if nb < tb, 1 if nb > tb 371 | */ 372 | SWIGRUNTIME int 373 | SWIG_TypeCompare(const char *nb, const char *tb) { 374 | int equiv = 0; 375 | const char* te = tb + strlen(tb); 376 | const char* ne = nb; 377 | while (!equiv && *ne) { 378 | for (nb = ne; *ne; ++ne) { 379 | if (*ne == '|') break; 380 | } 381 | equiv = (SWIG_TypeNameComp(nb, ne, tb, te) == 0) ? 1 : 0; 382 | if (*ne) ++ne; 383 | } 384 | return equiv; 385 | } 386 | 387 | 388 | /* think of this as a c++ template<> or a scheme macro */ 389 | #define SWIG_TypeCheck_Template(comparison, ty) \ 390 | if (ty) { \ 391 | swig_cast_info *iter = ty->cast; \ 392 | while (iter) { \ 393 | if (comparison) { \ 394 | if (iter == ty->cast) return iter; \ 395 | /* Move iter to the top of the linked list */ \ 396 | iter->prev->next = iter->next; \ 397 | if (iter->next) \ 398 | iter->next->prev = iter->prev; \ 399 | iter->next = ty->cast; \ 400 | iter->prev = 0; \ 401 | if (ty->cast) ty->cast->prev = iter; \ 402 | ty->cast = iter; \ 403 | return iter; \ 404 | } \ 405 | iter = iter->next; \ 406 | } \ 407 | } \ 408 | return 0 409 | 410 | /* 411 | Check the typename 412 | */ 413 | SWIGRUNTIME swig_cast_info * 414 | SWIG_TypeCheck(const char *c, swig_type_info *ty) { 415 | SWIG_TypeCheck_Template(strcmp(iter->type->name, c) == 0, ty); 416 | } 417 | 418 | /* Same as previous function, except strcmp is replaced with a pointer comparison */ 419 | SWIGRUNTIME swig_cast_info * 420 | SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *into) { 421 | SWIG_TypeCheck_Template(iter->type == from, into); 422 | } 423 | 424 | /* 425 | Cast a pointer up an inheritance hierarchy 426 | */ 427 | SWIGRUNTIMEINLINE void * 428 | SWIG_TypeCast(swig_cast_info *ty, void *ptr) { 429 | return ((!ty) || (!ty->converter)) ? ptr : (*ty->converter)(ptr); 430 | } 431 | 432 | /* 433 | Dynamic pointer casting. Down an inheritance hierarchy 434 | */ 435 | SWIGRUNTIME swig_type_info * 436 | SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { 437 | swig_type_info *lastty = ty; 438 | if (!ty || !ty->dcast) return ty; 439 | while (ty && (ty->dcast)) { 440 | ty = (*ty->dcast)(ptr); 441 | if (ty) lastty = ty; 442 | } 443 | return lastty; 444 | } 445 | 446 | /* 447 | Return the name associated with this type 448 | */ 449 | SWIGRUNTIMEINLINE const char * 450 | SWIG_TypeName(const swig_type_info *ty) { 451 | return ty->name; 452 | } 453 | 454 | /* 455 | Return the pretty name associated with this type, 456 | that is an unmangled type name in a form presentable to the user. 457 | */ 458 | SWIGRUNTIME const char * 459 | SWIG_TypePrettyName(const swig_type_info *type) { 460 | /* The "str" field contains the equivalent pretty names of the 461 | type, separated by vertical-bar characters. We choose 462 | to print the last name, as it is often (?) the most 463 | specific. */ 464 | if (!type) return NULL; 465 | if (type->str != NULL) { 466 | const char *last_name = type->str; 467 | const char *s; 468 | for (s = type->str; *s; s++) 469 | if (*s == '|') last_name = s+1; 470 | return last_name; 471 | } 472 | else 473 | return type->name; 474 | } 475 | 476 | /* 477 | Set the clientdata field for a type 478 | */ 479 | SWIGRUNTIME void 480 | SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { 481 | swig_cast_info *cast = ti->cast; 482 | /* if (ti->clientdata == clientdata) return; */ 483 | ti->clientdata = clientdata; 484 | 485 | while (cast) { 486 | if (!cast->converter) { 487 | swig_type_info *tc = cast->type; 488 | if (!tc->clientdata) { 489 | SWIG_TypeClientData(tc, clientdata); 490 | } 491 | } 492 | cast = cast->next; 493 | } 494 | } 495 | SWIGRUNTIME void 496 | SWIG_TypeNewClientData(swig_type_info *ti, void *clientdata) { 497 | SWIG_TypeClientData(ti, clientdata); 498 | ti->owndata = 1; 499 | } 500 | 501 | /* 502 | Search for a swig_type_info structure only by mangled name 503 | Search is a O(log #types) 504 | 505 | We start searching at module start, and finish searching when start == end. 506 | Note: if start == end at the beginning of the function, we go all the way around 507 | the circular list. 508 | */ 509 | SWIGRUNTIME swig_type_info * 510 | SWIG_MangledTypeQueryModule(swig_module_info *start, 511 | swig_module_info *end, 512 | const char *name) { 513 | swig_module_info *iter = start; 514 | do { 515 | if (iter->size) { 516 | register size_t l = 0; 517 | register size_t r = iter->size - 1; 518 | do { 519 | /* since l+r >= 0, we can (>> 1) instead (/ 2) */ 520 | register size_t i = (l + r) >> 1; 521 | const char *iname = iter->types[i]->name; 522 | if (iname) { 523 | register int compare = strcmp(name, iname); 524 | if (compare == 0) { 525 | return iter->types[i]; 526 | } else if (compare < 0) { 527 | if (i) { 528 | r = i - 1; 529 | } else { 530 | break; 531 | } 532 | } else if (compare > 0) { 533 | l = i + 1; 534 | } 535 | } else { 536 | break; /* should never happen */ 537 | } 538 | } while (l <= r); 539 | } 540 | iter = iter->next; 541 | } while (iter != end); 542 | return 0; 543 | } 544 | 545 | /* 546 | Search for a swig_type_info structure for either a mangled name or a human readable name. 547 | It first searches the mangled names of the types, which is a O(log #types) 548 | If a type is not found it then searches the human readable names, which is O(#types). 549 | 550 | We start searching at module start, and finish searching when start == end. 551 | Note: if start == end at the beginning of the function, we go all the way around 552 | the circular list. 553 | */ 554 | SWIGRUNTIME swig_type_info * 555 | SWIG_TypeQueryModule(swig_module_info *start, 556 | swig_module_info *end, 557 | const char *name) { 558 | /* STEP 1: Search the name field using binary search */ 559 | swig_type_info *ret = SWIG_MangledTypeQueryModule(start, end, name); 560 | if (ret) { 561 | return ret; 562 | } else { 563 | /* STEP 2: If the type hasn't been found, do a complete search 564 | of the str field (the human readable name) */ 565 | swig_module_info *iter = start; 566 | do { 567 | register size_t i = 0; 568 | for (; i < iter->size; ++i) { 569 | if (iter->types[i]->str && (SWIG_TypeEquiv(iter->types[i]->str, name))) 570 | return iter->types[i]; 571 | } 572 | iter = iter->next; 573 | } while (iter != end); 574 | } 575 | 576 | /* neither found a match */ 577 | return 0; 578 | } 579 | 580 | /* 581 | Pack binary data into a string 582 | */ 583 | SWIGRUNTIME char * 584 | SWIG_PackData(char *c, void *ptr, size_t sz) { 585 | static const char hex[17] = "0123456789abcdef"; 586 | register const unsigned char *u = (unsigned char *) ptr; 587 | register const unsigned char *eu = u + sz; 588 | for (; u != eu; ++u) { 589 | register unsigned char uu = *u; 590 | *(c++) = hex[(uu & 0xf0) >> 4]; 591 | *(c++) = hex[uu & 0xf]; 592 | } 593 | return c; 594 | } 595 | 596 | /* 597 | Unpack binary data from a string 598 | */ 599 | SWIGRUNTIME const char * 600 | SWIG_UnpackData(const char *c, void *ptr, size_t sz) { 601 | register unsigned char *u = (unsigned char *) ptr; 602 | register const unsigned char *eu = u + sz; 603 | for (; u != eu; ++u) { 604 | register char d = *(c++); 605 | register unsigned char uu; 606 | if ((d >= '0') && (d <= '9')) 607 | uu = ((d - '0') << 4); 608 | else if ((d >= 'a') && (d <= 'f')) 609 | uu = ((d - ('a'-10)) << 4); 610 | else 611 | return (char *) 0; 612 | d = *(c++); 613 | if ((d >= '0') && (d <= '9')) 614 | uu |= (d - '0'); 615 | else if ((d >= 'a') && (d <= 'f')) 616 | uu |= (d - ('a'-10)); 617 | else 618 | return (char *) 0; 619 | *u = uu; 620 | } 621 | return c; 622 | } 623 | 624 | /* 625 | Pack 'void *' into a string buffer. 626 | */ 627 | SWIGRUNTIME char * 628 | SWIG_PackVoidPtr(char *buff, void *ptr, const char *name, size_t bsz) { 629 | char *r = buff; 630 | if ((2*sizeof(void *) + 2) > bsz) return 0; 631 | *(r++) = '_'; 632 | r = SWIG_PackData(r,&ptr,sizeof(void *)); 633 | if (strlen(name) + 1 > (bsz - (r - buff))) return 0; 634 | strcpy(r,name); 635 | return buff; 636 | } 637 | 638 | SWIGRUNTIME const char * 639 | SWIG_UnpackVoidPtr(const char *c, void **ptr, const char *name) { 640 | if (*c != '_') { 641 | if (strcmp(c,"NULL") == 0) { 642 | *ptr = (void *) 0; 643 | return name; 644 | } else { 645 | return 0; 646 | } 647 | } 648 | return SWIG_UnpackData(++c,ptr,sizeof(void *)); 649 | } 650 | 651 | SWIGRUNTIME char * 652 | SWIG_PackDataName(char *buff, void *ptr, size_t sz, const char *name, size_t bsz) { 653 | char *r = buff; 654 | size_t lname = (name ? strlen(name) : 0); 655 | if ((2*sz + 2 + lname) > bsz) return 0; 656 | *(r++) = '_'; 657 | r = SWIG_PackData(r,ptr,sz); 658 | if (lname) { 659 | strncpy(r,name,lname+1); 660 | } else { 661 | *r = 0; 662 | } 663 | return buff; 664 | } 665 | 666 | SWIGRUNTIME const char * 667 | SWIG_UnpackDataName(const char *c, void *ptr, size_t sz, const char *name) { 668 | if (*c != '_') { 669 | if (strcmp(c,"NULL") == 0) { 670 | memset(ptr,0,sz); 671 | return name; 672 | } else { 673 | return 0; 674 | } 675 | } 676 | return SWIG_UnpackData(++c,ptr,sz); 677 | } 678 | 679 | #ifdef __cplusplus 680 | } 681 | #endif 682 | 683 | /* Errors in SWIG */ 684 | #define SWIG_UnknownError -1 685 | #define SWIG_IOError -2 686 | #define SWIG_RuntimeError -3 687 | #define SWIG_IndexError -4 688 | #define SWIG_TypeError -5 689 | #define SWIG_DivisionByZero -6 690 | #define SWIG_OverflowError -7 691 | #define SWIG_SyntaxError -8 692 | #define SWIG_ValueError -9 693 | #define SWIG_SystemError -10 694 | #define SWIG_AttributeError -11 695 | #define SWIG_MemoryError -12 696 | #define SWIG_NullReferenceError -13 697 | 698 | 699 | 700 | 701 | /* Add PyOS_snprintf for old Pythons */ 702 | #if PY_VERSION_HEX < 0x02020000 703 | # if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM) 704 | # define PyOS_snprintf _snprintf 705 | # else 706 | # define PyOS_snprintf snprintf 707 | # endif 708 | #endif 709 | 710 | /* A crude PyString_FromFormat implementation for old Pythons */ 711 | #if PY_VERSION_HEX < 0x02020000 712 | 713 | #ifndef SWIG_PYBUFFER_SIZE 714 | # define SWIG_PYBUFFER_SIZE 1024 715 | #endif 716 | 717 | static PyObject * 718 | PyString_FromFormat(const char *fmt, ...) { 719 | va_list ap; 720 | char buf[SWIG_PYBUFFER_SIZE * 2]; 721 | int res; 722 | va_start(ap, fmt); 723 | res = vsnprintf(buf, sizeof(buf), fmt, ap); 724 | va_end(ap); 725 | return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf); 726 | } 727 | #endif 728 | 729 | /* Add PyObject_Del for old Pythons */ 730 | #if PY_VERSION_HEX < 0x01060000 731 | # define PyObject_Del(op) PyMem_DEL((op)) 732 | #endif 733 | #ifndef PyObject_DEL 734 | # define PyObject_DEL PyObject_Del 735 | #endif 736 | 737 | /* A crude PyExc_StopIteration exception for old Pythons */ 738 | #if PY_VERSION_HEX < 0x02020000 739 | # ifndef PyExc_StopIteration 740 | # define PyExc_StopIteration PyExc_RuntimeError 741 | # endif 742 | # ifndef PyObject_GenericGetAttr 743 | # define PyObject_GenericGetAttr 0 744 | # endif 745 | #endif 746 | /* Py_NotImplemented is defined in 2.1 and up. */ 747 | #if PY_VERSION_HEX < 0x02010000 748 | # ifndef Py_NotImplemented 749 | # define Py_NotImplemented PyExc_RuntimeError 750 | # endif 751 | #endif 752 | 753 | 754 | /* A crude PyString_AsStringAndSize implementation for old Pythons */ 755 | #if PY_VERSION_HEX < 0x02010000 756 | # ifndef PyString_AsStringAndSize 757 | # define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;} 758 | # endif 759 | #endif 760 | 761 | /* PySequence_Size for old Pythons */ 762 | #if PY_VERSION_HEX < 0x02000000 763 | # ifndef PySequence_Size 764 | # define PySequence_Size PySequence_Length 765 | # endif 766 | #endif 767 | 768 | 769 | /* PyBool_FromLong for old Pythons */ 770 | #if PY_VERSION_HEX < 0x02030000 771 | static 772 | PyObject *PyBool_FromLong(long ok) 773 | { 774 | PyObject *result = ok ? Py_True : Py_False; 775 | Py_INCREF(result); 776 | return result; 777 | } 778 | #endif 779 | 780 | /* Py_ssize_t for old Pythons */ 781 | /* This code is as recommended by: */ 782 | /* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */ 783 | #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) 784 | typedef int Py_ssize_t; 785 | # define PY_SSIZE_T_MAX INT_MAX 786 | # define PY_SSIZE_T_MIN INT_MIN 787 | #endif 788 | 789 | /* ----------------------------------------------------------------------------- 790 | * error manipulation 791 | * ----------------------------------------------------------------------------- */ 792 | 793 | SWIGRUNTIME PyObject* 794 | SWIG_Python_ErrorType(int code) { 795 | PyObject* type = 0; 796 | switch(code) { 797 | case SWIG_MemoryError: 798 | type = PyExc_MemoryError; 799 | break; 800 | case SWIG_IOError: 801 | type = PyExc_IOError; 802 | break; 803 | case SWIG_RuntimeError: 804 | type = PyExc_RuntimeError; 805 | break; 806 | case SWIG_IndexError: 807 | type = PyExc_IndexError; 808 | break; 809 | case SWIG_TypeError: 810 | type = PyExc_TypeError; 811 | break; 812 | case SWIG_DivisionByZero: 813 | type = PyExc_ZeroDivisionError; 814 | break; 815 | case SWIG_OverflowError: 816 | type = PyExc_OverflowError; 817 | break; 818 | case SWIG_SyntaxError: 819 | type = PyExc_SyntaxError; 820 | break; 821 | case SWIG_ValueError: 822 | type = PyExc_ValueError; 823 | break; 824 | case SWIG_SystemError: 825 | type = PyExc_SystemError; 826 | break; 827 | case SWIG_AttributeError: 828 | type = PyExc_AttributeError; 829 | break; 830 | default: 831 | type = PyExc_RuntimeError; 832 | } 833 | return type; 834 | } 835 | 836 | 837 | SWIGRUNTIME void 838 | SWIG_Python_AddErrorMsg(const char* mesg) 839 | { 840 | PyObject *type = 0; 841 | PyObject *value = 0; 842 | PyObject *traceback = 0; 843 | 844 | if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback); 845 | if (value) { 846 | PyObject *old_str = PyObject_Str(value); 847 | PyErr_Clear(); 848 | Py_XINCREF(type); 849 | PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); 850 | Py_DECREF(old_str); 851 | Py_DECREF(value); 852 | } else { 853 | PyErr_Format(PyExc_RuntimeError, mesg); 854 | } 855 | } 856 | 857 | 858 | 859 | #if defined(SWIG_PYTHON_NO_THREADS) 860 | # if defined(SWIG_PYTHON_THREADS) 861 | # undef SWIG_PYTHON_THREADS 862 | # endif 863 | #endif 864 | #if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */ 865 | # if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL) 866 | # if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */ 867 | # define SWIG_PYTHON_USE_GIL 868 | # endif 869 | # endif 870 | # if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */ 871 | # ifndef SWIG_PYTHON_INITIALIZE_THREADS 872 | # define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads() 873 | # endif 874 | # ifdef __cplusplus /* C++ code */ 875 | class SWIG_Python_Thread_Block { 876 | bool status; 877 | PyGILState_STATE state; 878 | public: 879 | void end() { if (status) { PyGILState_Release(state); status = false;} } 880 | SWIG_Python_Thread_Block() : status(true), state(PyGILState_Ensure()) {} 881 | ~SWIG_Python_Thread_Block() { end(); } 882 | }; 883 | class SWIG_Python_Thread_Allow { 884 | bool status; 885 | PyThreadState *save; 886 | public: 887 | void end() { if (status) { PyEval_RestoreThread(save); status = false; }} 888 | SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} 889 | ~SWIG_Python_Thread_Allow() { end(); } 890 | }; 891 | # define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block 892 | # define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() 893 | # define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow 894 | # define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() 895 | # else /* C code */ 896 | # define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() 897 | # define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) 898 | # define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread() 899 | # define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow) 900 | # endif 901 | # else /* Old thread way, not implemented, user must provide it */ 902 | # if !defined(SWIG_PYTHON_INITIALIZE_THREADS) 903 | # define SWIG_PYTHON_INITIALIZE_THREADS 904 | # endif 905 | # if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) 906 | # define SWIG_PYTHON_THREAD_BEGIN_BLOCK 907 | # endif 908 | # if !defined(SWIG_PYTHON_THREAD_END_BLOCK) 909 | # define SWIG_PYTHON_THREAD_END_BLOCK 910 | # endif 911 | # if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) 912 | # define SWIG_PYTHON_THREAD_BEGIN_ALLOW 913 | # endif 914 | # if !defined(SWIG_PYTHON_THREAD_END_ALLOW) 915 | # define SWIG_PYTHON_THREAD_END_ALLOW 916 | # endif 917 | # endif 918 | #else /* No thread support */ 919 | # define SWIG_PYTHON_INITIALIZE_THREADS 920 | # define SWIG_PYTHON_THREAD_BEGIN_BLOCK 921 | # define SWIG_PYTHON_THREAD_END_BLOCK 922 | # define SWIG_PYTHON_THREAD_BEGIN_ALLOW 923 | # define SWIG_PYTHON_THREAD_END_ALLOW 924 | #endif 925 | 926 | /* ----------------------------------------------------------------------------- 927 | * Python API portion that goes into the runtime 928 | * ----------------------------------------------------------------------------- */ 929 | 930 | #ifdef __cplusplus 931 | extern "C" { 932 | #if 0 933 | } /* cc-mode */ 934 | #endif 935 | #endif 936 | 937 | /* ----------------------------------------------------------------------------- 938 | * Constant declarations 939 | * ----------------------------------------------------------------------------- */ 940 | 941 | /* Constant Types */ 942 | #define SWIG_PY_POINTER 4 943 | #define SWIG_PY_BINARY 5 944 | 945 | /* Constant information structure */ 946 | typedef struct swig_const_info { 947 | int type; 948 | char *name; 949 | long lvalue; 950 | double dvalue; 951 | void *pvalue; 952 | swig_type_info **ptype; 953 | } swig_const_info; 954 | 955 | #ifdef __cplusplus 956 | #if 0 957 | { /* cc-mode */ 958 | #endif 959 | } 960 | #endif 961 | 962 | 963 | /* ----------------------------------------------------------------------------- 964 | * See the LICENSE file for information on copyright, usage and redistribution 965 | * of SWIG, and the README file for authors - http://www.swig.org/release.html. 966 | * 967 | * pyrun.swg 968 | * 969 | * This file contains the runtime support for Python modules 970 | * and includes code for managing global variables and pointer 971 | * type checking. 972 | * 973 | * ----------------------------------------------------------------------------- */ 974 | 975 | /* Common SWIG API */ 976 | 977 | /* for raw pointers */ 978 | #define SWIG_Python_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, 0) 979 | #define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags) 980 | #define SWIG_ConvertPtrAndOwn(obj,pptr,type,flags,own) SWIG_Python_ConvertPtrAndOwn(obj, pptr, type, flags, own) 981 | #define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags) 982 | #define SWIG_CheckImplicit(ty) SWIG_Python_CheckImplicit(ty) 983 | #define SWIG_AcquirePtr(ptr, src) SWIG_Python_AcquirePtr(ptr, src) 984 | #define swig_owntype int 985 | 986 | /* for raw packed data */ 987 | #define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) 988 | #define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) 989 | 990 | /* for class or struct pointers */ 991 | #define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags) 992 | #define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags) 993 | 994 | /* for C or C++ function pointers */ 995 | #define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertFunctionPtr(obj, pptr, type) 996 | #define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0) 997 | 998 | /* for C++ member pointers, ie, member methods */ 999 | #define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty) 1000 | #define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type) 1001 | 1002 | 1003 | /* Runtime API */ 1004 | 1005 | #define SWIG_GetModule(clientdata) SWIG_Python_GetModule() 1006 | #define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer) 1007 | #define SWIG_NewClientData(obj) PySwigClientData_New(obj) 1008 | 1009 | #define SWIG_SetErrorObj SWIG_Python_SetErrorObj 1010 | #define SWIG_SetErrorMsg SWIG_Python_SetErrorMsg 1011 | #define SWIG_ErrorType(code) SWIG_Python_ErrorType(code) 1012 | #define SWIG_Error(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code), msg) 1013 | #define SWIG_fail goto fail 1014 | 1015 | 1016 | /* Runtime API implementation */ 1017 | 1018 | /* Error manipulation */ 1019 | 1020 | SWIGINTERN void 1021 | SWIG_Python_SetErrorObj(PyObject *errtype, PyObject *obj) { 1022 | SWIG_PYTHON_THREAD_BEGIN_BLOCK; 1023 | PyErr_SetObject(errtype, obj); 1024 | Py_DECREF(obj); 1025 | SWIG_PYTHON_THREAD_END_BLOCK; 1026 | } 1027 | 1028 | SWIGINTERN void 1029 | SWIG_Python_SetErrorMsg(PyObject *errtype, const char *msg) { 1030 | SWIG_PYTHON_THREAD_BEGIN_BLOCK; 1031 | PyErr_SetString(errtype, (char *) msg); 1032 | SWIG_PYTHON_THREAD_END_BLOCK; 1033 | } 1034 | 1035 | #define SWIG_Python_Raise(obj, type, desc) SWIG_Python_SetErrorObj(SWIG_Python_ExceptionType(desc), obj) 1036 | 1037 | /* Set a constant value */ 1038 | 1039 | SWIGINTERN void 1040 | SWIG_Python_SetConstant(PyObject *d, const char *name, PyObject *obj) { 1041 | PyDict_SetItemString(d, (char*) name, obj); 1042 | Py_DECREF(obj); 1043 | } 1044 | 1045 | /* Append a value to the result obj */ 1046 | 1047 | SWIGINTERN PyObject* 1048 | SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) { 1049 | #if !defined(SWIG_PYTHON_OUTPUT_TUPLE) 1050 | if (!result) { 1051 | result = obj; 1052 | } else if (result == Py_None) { 1053 | Py_DECREF(result); 1054 | result = obj; 1055 | } else { 1056 | if (!PyList_Check(result)) { 1057 | PyObject *o2 = result; 1058 | result = PyList_New(1); 1059 | PyList_SetItem(result, 0, o2); 1060 | } 1061 | PyList_Append(result,obj); 1062 | Py_DECREF(obj); 1063 | } 1064 | return result; 1065 | #else 1066 | PyObject* o2; 1067 | PyObject* o3; 1068 | if (!result) { 1069 | result = obj; 1070 | } else if (result == Py_None) { 1071 | Py_DECREF(result); 1072 | result = obj; 1073 | } else { 1074 | if (!PyTuple_Check(result)) { 1075 | o2 = result; 1076 | result = PyTuple_New(1); 1077 | PyTuple_SET_ITEM(result, 0, o2); 1078 | } 1079 | o3 = PyTuple_New(1); 1080 | PyTuple_SET_ITEM(o3, 0, obj); 1081 | o2 = result; 1082 | result = PySequence_Concat(o2, o3); 1083 | Py_DECREF(o2); 1084 | Py_DECREF(o3); 1085 | } 1086 | return result; 1087 | #endif 1088 | } 1089 | 1090 | /* Unpack the argument tuple */ 1091 | 1092 | SWIGINTERN int 1093 | SWIG_Python_UnpackTuple(PyObject *args, const char *name, int min, int max, PyObject **objs) 1094 | { 1095 | if (!args) { 1096 | if (!min && !max) { 1097 | return 1; 1098 | } else { 1099 | PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got none", 1100 | name, (min == max ? "" : "at least "), min); 1101 | return 0; 1102 | } 1103 | } 1104 | if (!PyTuple_Check(args)) { 1105 | PyErr_SetString(PyExc_SystemError, "UnpackTuple() argument list is not a tuple"); 1106 | return 0; 1107 | } else { 1108 | register int l = PyTuple_GET_SIZE(args); 1109 | if (l < min) { 1110 | PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", 1111 | name, (min == max ? "" : "at least "), min, l); 1112 | return 0; 1113 | } else if (l > max) { 1114 | PyErr_Format(PyExc_TypeError, "%s expected %s%d arguments, got %d", 1115 | name, (min == max ? "" : "at most "), max, l); 1116 | return 0; 1117 | } else { 1118 | register int i; 1119 | for (i = 0; i < l; ++i) { 1120 | objs[i] = PyTuple_GET_ITEM(args, i); 1121 | } 1122 | for (; l < max; ++l) { 1123 | objs[l] = 0; 1124 | } 1125 | return i + 1; 1126 | } 1127 | } 1128 | } 1129 | 1130 | /* A functor is a function object with one single object argument */ 1131 | #if PY_VERSION_HEX >= 0x02020000 1132 | #define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunctionObjArgs(functor, obj, NULL); 1133 | #else 1134 | #define SWIG_Python_CallFunctor(functor, obj) PyObject_CallFunction(functor, "O", obj); 1135 | #endif 1136 | 1137 | /* 1138 | Helper for static pointer initialization for both C and C++ code, for example 1139 | static PyObject *SWIG_STATIC_POINTER(MyVar) = NewSomething(...); 1140 | */ 1141 | #ifdef __cplusplus 1142 | #define SWIG_STATIC_POINTER(var) var 1143 | #else 1144 | #define SWIG_STATIC_POINTER(var) var = 0; if (!var) var 1145 | #endif 1146 | 1147 | /* ----------------------------------------------------------------------------- 1148 | * Pointer declarations 1149 | * ----------------------------------------------------------------------------- */ 1150 | 1151 | /* Flags for new pointer objects */ 1152 | #define SWIG_POINTER_NOSHADOW (SWIG_POINTER_OWN << 1) 1153 | #define SWIG_POINTER_NEW (SWIG_POINTER_NOSHADOW | SWIG_POINTER_OWN) 1154 | 1155 | #define SWIG_POINTER_IMPLICIT_CONV (SWIG_POINTER_DISOWN << 1) 1156 | 1157 | #ifdef __cplusplus 1158 | extern "C" { 1159 | #if 0 1160 | } /* cc-mode */ 1161 | #endif 1162 | #endif 1163 | 1164 | /* How to access Py_None */ 1165 | #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) 1166 | # ifndef SWIG_PYTHON_NO_BUILD_NONE 1167 | # ifndef SWIG_PYTHON_BUILD_NONE 1168 | # define SWIG_PYTHON_BUILD_NONE 1169 | # endif 1170 | # endif 1171 | #endif 1172 | 1173 | #ifdef SWIG_PYTHON_BUILD_NONE 1174 | # ifdef Py_None 1175 | # undef Py_None 1176 | # define Py_None SWIG_Py_None() 1177 | # endif 1178 | SWIGRUNTIMEINLINE PyObject * 1179 | _SWIG_Py_None(void) 1180 | { 1181 | PyObject *none = Py_BuildValue((char*)""); 1182 | Py_DECREF(none); 1183 | return none; 1184 | } 1185 | SWIGRUNTIME PyObject * 1186 | SWIG_Py_None(void) 1187 | { 1188 | static PyObject *SWIG_STATIC_POINTER(none) = _SWIG_Py_None(); 1189 | return none; 1190 | } 1191 | #endif 1192 | 1193 | /* The python void return value */ 1194 | 1195 | SWIGRUNTIMEINLINE PyObject * 1196 | SWIG_Py_Void(void) 1197 | { 1198 | PyObject *none = Py_None; 1199 | Py_INCREF(none); 1200 | return none; 1201 | } 1202 | 1203 | /* PySwigClientData */ 1204 | 1205 | typedef struct { 1206 | PyObject *klass; 1207 | PyObject *newraw; 1208 | PyObject *newargs; 1209 | PyObject *destroy; 1210 | int delargs; 1211 | int implicitconv; 1212 | } PySwigClientData; 1213 | 1214 | SWIGRUNTIMEINLINE int 1215 | SWIG_Python_CheckImplicit(swig_type_info *ty) 1216 | { 1217 | PySwigClientData *data = (PySwigClientData *)ty->clientdata; 1218 | return data ? data->implicitconv : 0; 1219 | } 1220 | 1221 | SWIGRUNTIMEINLINE PyObject * 1222 | SWIG_Python_ExceptionType(swig_type_info *desc) { 1223 | PySwigClientData *data = desc ? (PySwigClientData *) desc->clientdata : 0; 1224 | PyObject *klass = data ? data->klass : 0; 1225 | return (klass ? klass : PyExc_RuntimeError); 1226 | } 1227 | 1228 | 1229 | SWIGRUNTIME PySwigClientData * 1230 | PySwigClientData_New(PyObject* obj) 1231 | { 1232 | if (!obj) { 1233 | return 0; 1234 | } else { 1235 | PySwigClientData *data = (PySwigClientData *)malloc(sizeof(PySwigClientData)); 1236 | /* the klass element */ 1237 | data->klass = obj; 1238 | Py_INCREF(data->klass); 1239 | /* the newraw method and newargs arguments used to create a new raw instance */ 1240 | if (PyClass_Check(obj)) { 1241 | data->newraw = 0; 1242 | data->newargs = obj; 1243 | Py_INCREF(obj); 1244 | } else { 1245 | #if (PY_VERSION_HEX < 0x02020000) 1246 | data->newraw = 0; 1247 | #else 1248 | data->newraw = PyObject_GetAttrString(data->klass, (char *)"__new__"); 1249 | #endif 1250 | if (data->newraw) { 1251 | Py_INCREF(data->newraw); 1252 | data->newargs = PyTuple_New(1); 1253 | PyTuple_SetItem(data->newargs, 0, obj); 1254 | } else { 1255 | data->newargs = obj; 1256 | } 1257 | Py_INCREF(data->newargs); 1258 | } 1259 | /* the destroy method, aka as the C++ delete method */ 1260 | data->destroy = PyObject_GetAttrString(data->klass, (char *)"__swig_destroy__"); 1261 | if (PyErr_Occurred()) { 1262 | PyErr_Clear(); 1263 | data->destroy = 0; 1264 | } 1265 | if (data->destroy) { 1266 | int flags; 1267 | Py_INCREF(data->destroy); 1268 | flags = PyCFunction_GET_FLAGS(data->destroy); 1269 | #ifdef METH_O 1270 | data->delargs = !(flags & (METH_O)); 1271 | #else 1272 | data->delargs = 0; 1273 | #endif 1274 | } else { 1275 | data->delargs = 0; 1276 | } 1277 | data->implicitconv = 0; 1278 | return data; 1279 | } 1280 | } 1281 | 1282 | SWIGRUNTIME void 1283 | PySwigClientData_Del(PySwigClientData* data) 1284 | { 1285 | Py_XDECREF(data->newraw); 1286 | Py_XDECREF(data->newargs); 1287 | Py_XDECREF(data->destroy); 1288 | } 1289 | 1290 | /* =============== PySwigObject =====================*/ 1291 | 1292 | typedef struct { 1293 | PyObject_HEAD 1294 | void *ptr; 1295 | swig_type_info *ty; 1296 | int own; 1297 | PyObject *next; 1298 | } PySwigObject; 1299 | 1300 | SWIGRUNTIME PyObject * 1301 | PySwigObject_long(PySwigObject *v) 1302 | { 1303 | return PyLong_FromVoidPtr(v->ptr); 1304 | } 1305 | 1306 | SWIGRUNTIME PyObject * 1307 | PySwigObject_format(const char* fmt, PySwigObject *v) 1308 | { 1309 | PyObject *res = NULL; 1310 | PyObject *args = PyTuple_New(1); 1311 | if (args) { 1312 | if (PyTuple_SetItem(args, 0, PySwigObject_long(v)) == 0) { 1313 | PyObject *ofmt = PyString_FromString(fmt); 1314 | if (ofmt) { 1315 | res = PyString_Format(ofmt,args); 1316 | Py_DECREF(ofmt); 1317 | } 1318 | Py_DECREF(args); 1319 | } 1320 | } 1321 | return res; 1322 | } 1323 | 1324 | SWIGRUNTIME PyObject * 1325 | PySwigObject_oct(PySwigObject *v) 1326 | { 1327 | return PySwigObject_format("%o",v); 1328 | } 1329 | 1330 | SWIGRUNTIME PyObject * 1331 | PySwigObject_hex(PySwigObject *v) 1332 | { 1333 | return PySwigObject_format("%x",v); 1334 | } 1335 | 1336 | SWIGRUNTIME PyObject * 1337 | #ifdef METH_NOARGS 1338 | PySwigObject_repr(PySwigObject *v) 1339 | #else 1340 | PySwigObject_repr(PySwigObject *v, PyObject *args) 1341 | #endif 1342 | { 1343 | const char *name = SWIG_TypePrettyName(v->ty); 1344 | PyObject *hex = PySwigObject_hex(v); 1345 | PyObject *repr = PyString_FromFormat("", name, PyString_AsString(hex)); 1346 | Py_DECREF(hex); 1347 | if (v->next) { 1348 | #ifdef METH_NOARGS 1349 | PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next); 1350 | #else 1351 | PyObject *nrep = PySwigObject_repr((PySwigObject *)v->next, args); 1352 | #endif 1353 | PyString_ConcatAndDel(&repr,nrep); 1354 | } 1355 | return repr; 1356 | } 1357 | 1358 | SWIGRUNTIME int 1359 | PySwigObject_print(PySwigObject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) 1360 | { 1361 | #ifdef METH_NOARGS 1362 | PyObject *repr = PySwigObject_repr(v); 1363 | #else 1364 | PyObject *repr = PySwigObject_repr(v, NULL); 1365 | #endif 1366 | if (repr) { 1367 | fputs(PyString_AsString(repr), fp); 1368 | Py_DECREF(repr); 1369 | return 0; 1370 | } else { 1371 | return 1; 1372 | } 1373 | } 1374 | 1375 | SWIGRUNTIME PyObject * 1376 | PySwigObject_str(PySwigObject *v) 1377 | { 1378 | char result[SWIG_BUFFER_SIZE]; 1379 | return SWIG_PackVoidPtr(result, v->ptr, v->ty->name, sizeof(result)) ? 1380 | PyString_FromString(result) : 0; 1381 | } 1382 | 1383 | SWIGRUNTIME int 1384 | PySwigObject_compare(PySwigObject *v, PySwigObject *w) 1385 | { 1386 | void *i = v->ptr; 1387 | void *j = w->ptr; 1388 | return (i < j) ? -1 : ((i > j) ? 1 : 0); 1389 | } 1390 | 1391 | SWIGRUNTIME PyTypeObject* _PySwigObject_type(void); 1392 | 1393 | SWIGRUNTIME PyTypeObject* 1394 | PySwigObject_type(void) { 1395 | static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigObject_type(); 1396 | return type; 1397 | } 1398 | 1399 | SWIGRUNTIMEINLINE int 1400 | PySwigObject_Check(PyObject *op) { 1401 | return ((op)->ob_type == PySwigObject_type()) 1402 | || (strcmp((op)->ob_type->tp_name,"PySwigObject") == 0); 1403 | } 1404 | 1405 | SWIGRUNTIME PyObject * 1406 | PySwigObject_New(void *ptr, swig_type_info *ty, int own); 1407 | 1408 | SWIGRUNTIME void 1409 | PySwigObject_dealloc(PyObject *v) 1410 | { 1411 | PySwigObject *sobj = (PySwigObject *) v; 1412 | PyObject *next = sobj->next; 1413 | if (sobj->own) { 1414 | swig_type_info *ty = sobj->ty; 1415 | PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; 1416 | PyObject *destroy = data ? data->destroy : 0; 1417 | if (destroy) { 1418 | /* destroy is always a VARARGS method */ 1419 | PyObject *res; 1420 | if (data->delargs) { 1421 | /* we need to create a temporal object to carry the destroy operation */ 1422 | PyObject *tmp = PySwigObject_New(sobj->ptr, ty, 0); 1423 | res = SWIG_Python_CallFunctor(destroy, tmp); 1424 | Py_DECREF(tmp); 1425 | } else { 1426 | PyCFunction meth = PyCFunction_GET_FUNCTION(destroy); 1427 | PyObject *mself = PyCFunction_GET_SELF(destroy); 1428 | res = ((*meth)(mself, v)); 1429 | } 1430 | Py_XDECREF(res); 1431 | } else { 1432 | const char *name = SWIG_TypePrettyName(ty); 1433 | #if !defined(SWIG_PYTHON_SILENT_MEMLEAK) 1434 | printf("swig/python detected a memory leak of type '%s', no destructor found.\n", name); 1435 | #endif 1436 | } 1437 | } 1438 | Py_XDECREF(next); 1439 | PyObject_DEL(v); 1440 | } 1441 | 1442 | SWIGRUNTIME PyObject* 1443 | PySwigObject_append(PyObject* v, PyObject* next) 1444 | { 1445 | PySwigObject *sobj = (PySwigObject *) v; 1446 | #ifndef METH_O 1447 | PyObject *tmp = 0; 1448 | if (!PyArg_ParseTuple(next,(char *)"O:append", &tmp)) return NULL; 1449 | next = tmp; 1450 | #endif 1451 | if (!PySwigObject_Check(next)) { 1452 | return NULL; 1453 | } 1454 | sobj->next = next; 1455 | Py_INCREF(next); 1456 | return SWIG_Py_Void(); 1457 | } 1458 | 1459 | SWIGRUNTIME PyObject* 1460 | #ifdef METH_NOARGS 1461 | PySwigObject_next(PyObject* v) 1462 | #else 1463 | PySwigObject_next(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) 1464 | #endif 1465 | { 1466 | PySwigObject *sobj = (PySwigObject *) v; 1467 | if (sobj->next) { 1468 | Py_INCREF(sobj->next); 1469 | return sobj->next; 1470 | } else { 1471 | return SWIG_Py_Void(); 1472 | } 1473 | } 1474 | 1475 | SWIGINTERN PyObject* 1476 | #ifdef METH_NOARGS 1477 | PySwigObject_disown(PyObject *v) 1478 | #else 1479 | PySwigObject_disown(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) 1480 | #endif 1481 | { 1482 | PySwigObject *sobj = (PySwigObject *)v; 1483 | sobj->own = 0; 1484 | return SWIG_Py_Void(); 1485 | } 1486 | 1487 | SWIGINTERN PyObject* 1488 | #ifdef METH_NOARGS 1489 | PySwigObject_acquire(PyObject *v) 1490 | #else 1491 | PySwigObject_acquire(PyObject* v, PyObject *SWIGUNUSEDPARM(args)) 1492 | #endif 1493 | { 1494 | PySwigObject *sobj = (PySwigObject *)v; 1495 | sobj->own = SWIG_POINTER_OWN; 1496 | return SWIG_Py_Void(); 1497 | } 1498 | 1499 | SWIGINTERN PyObject* 1500 | PySwigObject_own(PyObject *v, PyObject *args) 1501 | { 1502 | PyObject *val = 0; 1503 | #if (PY_VERSION_HEX < 0x02020000) 1504 | if (!PyArg_ParseTuple(args,(char *)"|O:own",&val)) 1505 | #else 1506 | if (!PyArg_UnpackTuple(args, (char *)"own", 0, 1, &val)) 1507 | #endif 1508 | { 1509 | return NULL; 1510 | } 1511 | else 1512 | { 1513 | PySwigObject *sobj = (PySwigObject *)v; 1514 | PyObject *obj = PyBool_FromLong(sobj->own); 1515 | if (val) { 1516 | #ifdef METH_NOARGS 1517 | if (PyObject_IsTrue(val)) { 1518 | PySwigObject_acquire(v); 1519 | } else { 1520 | PySwigObject_disown(v); 1521 | } 1522 | #else 1523 | if (PyObject_IsTrue(val)) { 1524 | PySwigObject_acquire(v,args); 1525 | } else { 1526 | PySwigObject_disown(v,args); 1527 | } 1528 | #endif 1529 | } 1530 | return obj; 1531 | } 1532 | } 1533 | 1534 | #ifdef METH_O 1535 | static PyMethodDef 1536 | swigobject_methods[] = { 1537 | {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_NOARGS, (char *)"releases ownership of the pointer"}, 1538 | {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_NOARGS, (char *)"aquires ownership of the pointer"}, 1539 | {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, 1540 | {(char *)"append", (PyCFunction)PySwigObject_append, METH_O, (char *)"appends another 'this' object"}, 1541 | {(char *)"next", (PyCFunction)PySwigObject_next, METH_NOARGS, (char *)"returns the next 'this' object"}, 1542 | {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_NOARGS, (char *)"returns object representation"}, 1543 | {0, 0, 0, 0} 1544 | }; 1545 | #else 1546 | static PyMethodDef 1547 | swigobject_methods[] = { 1548 | {(char *)"disown", (PyCFunction)PySwigObject_disown, METH_VARARGS, (char *)"releases ownership of the pointer"}, 1549 | {(char *)"acquire", (PyCFunction)PySwigObject_acquire, METH_VARARGS, (char *)"aquires ownership of the pointer"}, 1550 | {(char *)"own", (PyCFunction)PySwigObject_own, METH_VARARGS, (char *)"returns/sets ownership of the pointer"}, 1551 | {(char *)"append", (PyCFunction)PySwigObject_append, METH_VARARGS, (char *)"appends another 'this' object"}, 1552 | {(char *)"next", (PyCFunction)PySwigObject_next, METH_VARARGS, (char *)"returns the next 'this' object"}, 1553 | {(char *)"__repr__",(PyCFunction)PySwigObject_repr, METH_VARARGS, (char *)"returns object representation"}, 1554 | {0, 0, 0, 0} 1555 | }; 1556 | #endif 1557 | 1558 | #if PY_VERSION_HEX < 0x02020000 1559 | SWIGINTERN PyObject * 1560 | PySwigObject_getattr(PySwigObject *sobj,char *name) 1561 | { 1562 | return Py_FindMethod(swigobject_methods, (PyObject *)sobj, name); 1563 | } 1564 | #endif 1565 | 1566 | SWIGRUNTIME PyTypeObject* 1567 | _PySwigObject_type(void) { 1568 | static char swigobject_doc[] = "Swig object carries a C/C++ instance pointer"; 1569 | 1570 | static PyNumberMethods PySwigObject_as_number = { 1571 | (binaryfunc)0, /*nb_add*/ 1572 | (binaryfunc)0, /*nb_subtract*/ 1573 | (binaryfunc)0, /*nb_multiply*/ 1574 | (binaryfunc)0, /*nb_divide*/ 1575 | (binaryfunc)0, /*nb_remainder*/ 1576 | (binaryfunc)0, /*nb_divmod*/ 1577 | (ternaryfunc)0,/*nb_power*/ 1578 | (unaryfunc)0, /*nb_negative*/ 1579 | (unaryfunc)0, /*nb_positive*/ 1580 | (unaryfunc)0, /*nb_absolute*/ 1581 | (inquiry)0, /*nb_nonzero*/ 1582 | 0, /*nb_invert*/ 1583 | 0, /*nb_lshift*/ 1584 | 0, /*nb_rshift*/ 1585 | 0, /*nb_and*/ 1586 | 0, /*nb_xor*/ 1587 | 0, /*nb_or*/ 1588 | (coercion)0, /*nb_coerce*/ 1589 | (unaryfunc)PySwigObject_long, /*nb_int*/ 1590 | (unaryfunc)PySwigObject_long, /*nb_long*/ 1591 | (unaryfunc)0, /*nb_float*/ 1592 | (unaryfunc)PySwigObject_oct, /*nb_oct*/ 1593 | (unaryfunc)PySwigObject_hex, /*nb_hex*/ 1594 | #if PY_VERSION_HEX >= 0x02020000 1595 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_true_divide */ 1596 | #elif PY_VERSION_HEX >= 0x02000000 1597 | 0,0,0,0,0,0,0,0,0,0,0 /* nb_inplace_add -> nb_inplace_or */ 1598 | #endif 1599 | }; 1600 | 1601 | static PyTypeObject pyswigobject_type; 1602 | static int type_init = 0; 1603 | if (!type_init) { 1604 | const PyTypeObject tmp 1605 | = { 1606 | PyObject_HEAD_INIT(NULL) 1607 | 0, /* ob_size */ 1608 | (char *)"PySwigObject", /* tp_name */ 1609 | sizeof(PySwigObject), /* tp_basicsize */ 1610 | 0, /* tp_itemsize */ 1611 | (destructor)PySwigObject_dealloc, /* tp_dealloc */ 1612 | (printfunc)PySwigObject_print, /* tp_print */ 1613 | #if PY_VERSION_HEX < 0x02020000 1614 | (getattrfunc)PySwigObject_getattr, /* tp_getattr */ 1615 | #else 1616 | (getattrfunc)0, /* tp_getattr */ 1617 | #endif 1618 | (setattrfunc)0, /* tp_setattr */ 1619 | (cmpfunc)PySwigObject_compare, /* tp_compare */ 1620 | (reprfunc)PySwigObject_repr, /* tp_repr */ 1621 | &PySwigObject_as_number, /* tp_as_number */ 1622 | 0, /* tp_as_sequence */ 1623 | 0, /* tp_as_mapping */ 1624 | (hashfunc)0, /* tp_hash */ 1625 | (ternaryfunc)0, /* tp_call */ 1626 | (reprfunc)PySwigObject_str, /* tp_str */ 1627 | PyObject_GenericGetAttr, /* tp_getattro */ 1628 | 0, /* tp_setattro */ 1629 | 0, /* tp_as_buffer */ 1630 | Py_TPFLAGS_DEFAULT, /* tp_flags */ 1631 | swigobject_doc, /* tp_doc */ 1632 | 0, /* tp_traverse */ 1633 | 0, /* tp_clear */ 1634 | 0, /* tp_richcompare */ 1635 | 0, /* tp_weaklistoffset */ 1636 | #if PY_VERSION_HEX >= 0x02020000 1637 | 0, /* tp_iter */ 1638 | 0, /* tp_iternext */ 1639 | swigobject_methods, /* tp_methods */ 1640 | 0, /* tp_members */ 1641 | 0, /* tp_getset */ 1642 | 0, /* tp_base */ 1643 | 0, /* tp_dict */ 1644 | 0, /* tp_descr_get */ 1645 | 0, /* tp_descr_set */ 1646 | 0, /* tp_dictoffset */ 1647 | 0, /* tp_init */ 1648 | 0, /* tp_alloc */ 1649 | 0, /* tp_new */ 1650 | 0, /* tp_free */ 1651 | 0, /* tp_is_gc */ 1652 | 0, /* tp_bases */ 1653 | 0, /* tp_mro */ 1654 | 0, /* tp_cache */ 1655 | 0, /* tp_subclasses */ 1656 | 0, /* tp_weaklist */ 1657 | #endif 1658 | #if PY_VERSION_HEX >= 0x02030000 1659 | 0, /* tp_del */ 1660 | #endif 1661 | #ifdef COUNT_ALLOCS 1662 | 0,0,0,0 /* tp_alloc -> tp_next */ 1663 | #endif 1664 | }; 1665 | pyswigobject_type = tmp; 1666 | pyswigobject_type.ob_type = &PyType_Type; 1667 | type_init = 1; 1668 | } 1669 | return &pyswigobject_type; 1670 | } 1671 | 1672 | SWIGRUNTIME PyObject * 1673 | PySwigObject_New(void *ptr, swig_type_info *ty, int own) 1674 | { 1675 | PySwigObject *sobj = PyObject_NEW(PySwigObject, PySwigObject_type()); 1676 | if (sobj) { 1677 | sobj->ptr = ptr; 1678 | sobj->ty = ty; 1679 | sobj->own = own; 1680 | sobj->next = 0; 1681 | } 1682 | return (PyObject *)sobj; 1683 | } 1684 | 1685 | /* ----------------------------------------------------------------------------- 1686 | * Implements a simple Swig Packed type, and use it instead of string 1687 | * ----------------------------------------------------------------------------- */ 1688 | 1689 | typedef struct { 1690 | PyObject_HEAD 1691 | void *pack; 1692 | swig_type_info *ty; 1693 | size_t size; 1694 | } PySwigPacked; 1695 | 1696 | SWIGRUNTIME int 1697 | PySwigPacked_print(PySwigPacked *v, FILE *fp, int SWIGUNUSEDPARM(flags)) 1698 | { 1699 | char result[SWIG_BUFFER_SIZE]; 1700 | fputs("pack, v->size, 0, sizeof(result))) { 1702 | fputs("at ", fp); 1703 | fputs(result, fp); 1704 | } 1705 | fputs(v->ty->name,fp); 1706 | fputs(">", fp); 1707 | return 0; 1708 | } 1709 | 1710 | SWIGRUNTIME PyObject * 1711 | PySwigPacked_repr(PySwigPacked *v) 1712 | { 1713 | char result[SWIG_BUFFER_SIZE]; 1714 | if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))) { 1715 | return PyString_FromFormat("", result, v->ty->name); 1716 | } else { 1717 | return PyString_FromFormat("", v->ty->name); 1718 | } 1719 | } 1720 | 1721 | SWIGRUNTIME PyObject * 1722 | PySwigPacked_str(PySwigPacked *v) 1723 | { 1724 | char result[SWIG_BUFFER_SIZE]; 1725 | if (SWIG_PackDataName(result, v->pack, v->size, 0, sizeof(result))){ 1726 | return PyString_FromFormat("%s%s", result, v->ty->name); 1727 | } else { 1728 | return PyString_FromString(v->ty->name); 1729 | } 1730 | } 1731 | 1732 | SWIGRUNTIME int 1733 | PySwigPacked_compare(PySwigPacked *v, PySwigPacked *w) 1734 | { 1735 | size_t i = v->size; 1736 | size_t j = w->size; 1737 | int s = (i < j) ? -1 : ((i > j) ? 1 : 0); 1738 | return s ? s : strncmp((char *)v->pack, (char *)w->pack, 2*v->size); 1739 | } 1740 | 1741 | SWIGRUNTIME PyTypeObject* _PySwigPacked_type(void); 1742 | 1743 | SWIGRUNTIME PyTypeObject* 1744 | PySwigPacked_type(void) { 1745 | static PyTypeObject *SWIG_STATIC_POINTER(type) = _PySwigPacked_type(); 1746 | return type; 1747 | } 1748 | 1749 | SWIGRUNTIMEINLINE int 1750 | PySwigPacked_Check(PyObject *op) { 1751 | return ((op)->ob_type == _PySwigPacked_type()) 1752 | || (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0); 1753 | } 1754 | 1755 | SWIGRUNTIME void 1756 | PySwigPacked_dealloc(PyObject *v) 1757 | { 1758 | if (PySwigPacked_Check(v)) { 1759 | PySwigPacked *sobj = (PySwigPacked *) v; 1760 | free(sobj->pack); 1761 | } 1762 | PyObject_DEL(v); 1763 | } 1764 | 1765 | SWIGRUNTIME PyTypeObject* 1766 | _PySwigPacked_type(void) { 1767 | static char swigpacked_doc[] = "Swig object carries a C/C++ instance pointer"; 1768 | static PyTypeObject pyswigpacked_type; 1769 | static int type_init = 0; 1770 | if (!type_init) { 1771 | const PyTypeObject tmp 1772 | = { 1773 | PyObject_HEAD_INIT(NULL) 1774 | 0, /* ob_size */ 1775 | (char *)"PySwigPacked", /* tp_name */ 1776 | sizeof(PySwigPacked), /* tp_basicsize */ 1777 | 0, /* tp_itemsize */ 1778 | (destructor)PySwigPacked_dealloc, /* tp_dealloc */ 1779 | (printfunc)PySwigPacked_print, /* tp_print */ 1780 | (getattrfunc)0, /* tp_getattr */ 1781 | (setattrfunc)0, /* tp_setattr */ 1782 | (cmpfunc)PySwigPacked_compare, /* tp_compare */ 1783 | (reprfunc)PySwigPacked_repr, /* tp_repr */ 1784 | 0, /* tp_as_number */ 1785 | 0, /* tp_as_sequence */ 1786 | 0, /* tp_as_mapping */ 1787 | (hashfunc)0, /* tp_hash */ 1788 | (ternaryfunc)0, /* tp_call */ 1789 | (reprfunc)PySwigPacked_str, /* tp_str */ 1790 | PyObject_GenericGetAttr, /* tp_getattro */ 1791 | 0, /* tp_setattro */ 1792 | 0, /* tp_as_buffer */ 1793 | Py_TPFLAGS_DEFAULT, /* tp_flags */ 1794 | swigpacked_doc, /* tp_doc */ 1795 | 0, /* tp_traverse */ 1796 | 0, /* tp_clear */ 1797 | 0, /* tp_richcompare */ 1798 | 0, /* tp_weaklistoffset */ 1799 | #if PY_VERSION_HEX >= 0x02020000 1800 | 0, /* tp_iter */ 1801 | 0, /* tp_iternext */ 1802 | 0, /* tp_methods */ 1803 | 0, /* tp_members */ 1804 | 0, /* tp_getset */ 1805 | 0, /* tp_base */ 1806 | 0, /* tp_dict */ 1807 | 0, /* tp_descr_get */ 1808 | 0, /* tp_descr_set */ 1809 | 0, /* tp_dictoffset */ 1810 | 0, /* tp_init */ 1811 | 0, /* tp_alloc */ 1812 | 0, /* tp_new */ 1813 | 0, /* tp_free */ 1814 | 0, /* tp_is_gc */ 1815 | 0, /* tp_bases */ 1816 | 0, /* tp_mro */ 1817 | 0, /* tp_cache */ 1818 | 0, /* tp_subclasses */ 1819 | 0, /* tp_weaklist */ 1820 | #endif 1821 | #if PY_VERSION_HEX >= 0x02030000 1822 | 0, /* tp_del */ 1823 | #endif 1824 | #ifdef COUNT_ALLOCS 1825 | 0,0,0,0 /* tp_alloc -> tp_next */ 1826 | #endif 1827 | }; 1828 | pyswigpacked_type = tmp; 1829 | pyswigpacked_type.ob_type = &PyType_Type; 1830 | type_init = 1; 1831 | } 1832 | return &pyswigpacked_type; 1833 | } 1834 | 1835 | SWIGRUNTIME PyObject * 1836 | PySwigPacked_New(void *ptr, size_t size, swig_type_info *ty) 1837 | { 1838 | PySwigPacked *sobj = PyObject_NEW(PySwigPacked, PySwigPacked_type()); 1839 | if (sobj) { 1840 | void *pack = malloc(size); 1841 | if (pack) { 1842 | memcpy(pack, ptr, size); 1843 | sobj->pack = pack; 1844 | sobj->ty = ty; 1845 | sobj->size = size; 1846 | } else { 1847 | PyObject_DEL((PyObject *) sobj); 1848 | sobj = 0; 1849 | } 1850 | } 1851 | return (PyObject *) sobj; 1852 | } 1853 | 1854 | SWIGRUNTIME swig_type_info * 1855 | PySwigPacked_UnpackData(PyObject *obj, void *ptr, size_t size) 1856 | { 1857 | if (PySwigPacked_Check(obj)) { 1858 | PySwigPacked *sobj = (PySwigPacked *)obj; 1859 | if (sobj->size != size) return 0; 1860 | memcpy(ptr, sobj->pack, size); 1861 | return sobj->ty; 1862 | } else { 1863 | return 0; 1864 | } 1865 | } 1866 | 1867 | /* ----------------------------------------------------------------------------- 1868 | * pointers/data manipulation 1869 | * ----------------------------------------------------------------------------- */ 1870 | 1871 | SWIGRUNTIMEINLINE PyObject * 1872 | _SWIG_This(void) 1873 | { 1874 | return PyString_FromString("this"); 1875 | } 1876 | 1877 | SWIGRUNTIME PyObject * 1878 | SWIG_This(void) 1879 | { 1880 | static PyObject *SWIG_STATIC_POINTER(swig_this) = _SWIG_This(); 1881 | return swig_this; 1882 | } 1883 | 1884 | /* #define SWIG_PYTHON_SLOW_GETSET_THIS */ 1885 | 1886 | SWIGRUNTIME PySwigObject * 1887 | SWIG_Python_GetSwigThis(PyObject *pyobj) 1888 | { 1889 | if (PySwigObject_Check(pyobj)) { 1890 | return (PySwigObject *) pyobj; 1891 | } else { 1892 | PyObject *obj = 0; 1893 | #if (!defined(SWIG_PYTHON_SLOW_GETSET_THIS) && (PY_VERSION_HEX >= 0x02030000)) 1894 | if (PyInstance_Check(pyobj)) { 1895 | obj = _PyInstance_Lookup(pyobj, SWIG_This()); 1896 | } else { 1897 | PyObject **dictptr = _PyObject_GetDictPtr(pyobj); 1898 | if (dictptr != NULL) { 1899 | PyObject *dict = *dictptr; 1900 | obj = dict ? PyDict_GetItem(dict, SWIG_This()) : 0; 1901 | } else { 1902 | #ifdef PyWeakref_CheckProxy 1903 | if (PyWeakref_CheckProxy(pyobj)) { 1904 | PyObject *wobj = PyWeakref_GET_OBJECT(pyobj); 1905 | return wobj ? SWIG_Python_GetSwigThis(wobj) : 0; 1906 | } 1907 | #endif 1908 | obj = PyObject_GetAttr(pyobj,SWIG_This()); 1909 | if (obj) { 1910 | Py_DECREF(obj); 1911 | } else { 1912 | if (PyErr_Occurred()) PyErr_Clear(); 1913 | return 0; 1914 | } 1915 | } 1916 | } 1917 | #else 1918 | obj = PyObject_GetAttr(pyobj,SWIG_This()); 1919 | if (obj) { 1920 | Py_DECREF(obj); 1921 | } else { 1922 | if (PyErr_Occurred()) PyErr_Clear(); 1923 | return 0; 1924 | } 1925 | #endif 1926 | if (obj && !PySwigObject_Check(obj)) { 1927 | /* a PyObject is called 'this', try to get the 'real this' 1928 | PySwigObject from it */ 1929 | return SWIG_Python_GetSwigThis(obj); 1930 | } 1931 | return (PySwigObject *)obj; 1932 | } 1933 | } 1934 | 1935 | /* Acquire a pointer value */ 1936 | 1937 | SWIGRUNTIME int 1938 | SWIG_Python_AcquirePtr(PyObject *obj, int own) { 1939 | if (own) { 1940 | PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); 1941 | if (sobj) { 1942 | int oldown = sobj->own; 1943 | sobj->own = own; 1944 | return oldown; 1945 | } 1946 | } 1947 | return 0; 1948 | } 1949 | 1950 | /* Convert a pointer value */ 1951 | 1952 | SWIGRUNTIME int 1953 | SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int flags, int *own) { 1954 | if (!obj) return SWIG_ERROR; 1955 | if (obj == Py_None) { 1956 | if (ptr) *ptr = 0; 1957 | return SWIG_OK; 1958 | } else { 1959 | PySwigObject *sobj = SWIG_Python_GetSwigThis(obj); 1960 | while (sobj) { 1961 | void *vptr = sobj->ptr; 1962 | if (ty) { 1963 | swig_type_info *to = sobj->ty; 1964 | if (to == ty) { 1965 | /* no type cast needed */ 1966 | if (ptr) *ptr = vptr; 1967 | break; 1968 | } else { 1969 | swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); 1970 | if (!tc) { 1971 | sobj = (PySwigObject *)sobj->next; 1972 | } else { 1973 | if (ptr) *ptr = SWIG_TypeCast(tc,vptr); 1974 | break; 1975 | } 1976 | } 1977 | } else { 1978 | if (ptr) *ptr = vptr; 1979 | break; 1980 | } 1981 | } 1982 | if (sobj) { 1983 | if (own) *own = sobj->own; 1984 | if (flags & SWIG_POINTER_DISOWN) { 1985 | sobj->own = 0; 1986 | } 1987 | return SWIG_OK; 1988 | } else { 1989 | int res = SWIG_ERROR; 1990 | if (flags & SWIG_POINTER_IMPLICIT_CONV) { 1991 | PySwigClientData *data = ty ? (PySwigClientData *) ty->clientdata : 0; 1992 | if (data && !data->implicitconv) { 1993 | PyObject *klass = data->klass; 1994 | if (klass) { 1995 | PyObject *impconv; 1996 | data->implicitconv = 1; /* avoid recursion and call 'explicit' constructors*/ 1997 | impconv = SWIG_Python_CallFunctor(klass, obj); 1998 | data->implicitconv = 0; 1999 | if (PyErr_Occurred()) { 2000 | PyErr_Clear(); 2001 | impconv = 0; 2002 | } 2003 | if (impconv) { 2004 | PySwigObject *iobj = SWIG_Python_GetSwigThis(impconv); 2005 | if (iobj) { 2006 | void *vptr; 2007 | res = SWIG_Python_ConvertPtrAndOwn((PyObject*)iobj, &vptr, ty, 0, 0); 2008 | if (SWIG_IsOK(res)) { 2009 | if (ptr) { 2010 | *ptr = vptr; 2011 | /* transfer the ownership to 'ptr' */ 2012 | iobj->own = 0; 2013 | res = SWIG_AddCast(res); 2014 | res = SWIG_AddNewMask(res); 2015 | } else { 2016 | res = SWIG_AddCast(res); 2017 | } 2018 | } 2019 | } 2020 | Py_DECREF(impconv); 2021 | } 2022 | } 2023 | } 2024 | } 2025 | return res; 2026 | } 2027 | } 2028 | } 2029 | 2030 | /* Convert a function ptr value */ 2031 | 2032 | SWIGRUNTIME int 2033 | SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) { 2034 | if (!PyCFunction_Check(obj)) { 2035 | return SWIG_ConvertPtr(obj, ptr, ty, 0); 2036 | } else { 2037 | void *vptr = 0; 2038 | 2039 | /* here we get the method pointer for callbacks */ 2040 | const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc); 2041 | const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0; 2042 | if (desc) { 2043 | desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0; 2044 | if (!desc) return SWIG_ERROR; 2045 | } 2046 | if (ty) { 2047 | swig_cast_info *tc = SWIG_TypeCheck(desc,ty); 2048 | if (!tc) return SWIG_ERROR; 2049 | *ptr = SWIG_TypeCast(tc,vptr); 2050 | } else { 2051 | *ptr = vptr; 2052 | } 2053 | return SWIG_OK; 2054 | } 2055 | } 2056 | 2057 | /* Convert a packed value value */ 2058 | 2059 | SWIGRUNTIME int 2060 | SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) { 2061 | swig_type_info *to = PySwigPacked_UnpackData(obj, ptr, sz); 2062 | if (!to) return SWIG_ERROR; 2063 | if (ty) { 2064 | if (to != ty) { 2065 | /* check type cast? */ 2066 | swig_cast_info *tc = SWIG_TypeCheck(to->name,ty); 2067 | if (!tc) return SWIG_ERROR; 2068 | } 2069 | } 2070 | return SWIG_OK; 2071 | } 2072 | 2073 | /* ----------------------------------------------------------------------------- 2074 | * Create a new pointer object 2075 | * ----------------------------------------------------------------------------- */ 2076 | 2077 | /* 2078 | Create a new instance object, whitout calling __init__, and set the 2079 | 'this' attribute. 2080 | */ 2081 | 2082 | SWIGRUNTIME PyObject* 2083 | SWIG_Python_NewShadowInstance(PySwigClientData *data, PyObject *swig_this) 2084 | { 2085 | #if (PY_VERSION_HEX >= 0x02020000) 2086 | PyObject *inst = 0; 2087 | PyObject *newraw = data->newraw; 2088 | if (newraw) { 2089 | inst = PyObject_Call(newraw, data->newargs, NULL); 2090 | if (inst) { 2091 | #if !defined(SWIG_PYTHON_SLOW_GETSET_THIS) 2092 | PyObject **dictptr = _PyObject_GetDictPtr(inst); 2093 | if (dictptr != NULL) { 2094 | PyObject *dict = *dictptr; 2095 | if (dict == NULL) { 2096 | dict = PyDict_New(); 2097 | *dictptr = dict; 2098 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2099 | } 2100 | } 2101 | #else 2102 | PyObject *key = SWIG_This(); 2103 | PyObject_SetAttr(inst, key, swig_this); 2104 | #endif 2105 | } 2106 | } else { 2107 | PyObject *dict = PyDict_New(); 2108 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2109 | inst = PyInstance_NewRaw(data->newargs, dict); 2110 | Py_DECREF(dict); 2111 | } 2112 | return inst; 2113 | #else 2114 | #if (PY_VERSION_HEX >= 0x02010000) 2115 | PyObject *inst; 2116 | PyObject *dict = PyDict_New(); 2117 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2118 | inst = PyInstance_NewRaw(data->newargs, dict); 2119 | Py_DECREF(dict); 2120 | return (PyObject *) inst; 2121 | #else 2122 | PyInstanceObject *inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type); 2123 | if (inst == NULL) { 2124 | return NULL; 2125 | } 2126 | inst->in_class = (PyClassObject *)data->newargs; 2127 | Py_INCREF(inst->in_class); 2128 | inst->in_dict = PyDict_New(); 2129 | if (inst->in_dict == NULL) { 2130 | Py_DECREF(inst); 2131 | return NULL; 2132 | } 2133 | #ifdef Py_TPFLAGS_HAVE_WEAKREFS 2134 | inst->in_weakreflist = NULL; 2135 | #endif 2136 | #ifdef Py_TPFLAGS_GC 2137 | PyObject_GC_Init(inst); 2138 | #endif 2139 | PyDict_SetItem(inst->in_dict, SWIG_This(), swig_this); 2140 | return (PyObject *) inst; 2141 | #endif 2142 | #endif 2143 | } 2144 | 2145 | SWIGRUNTIME void 2146 | SWIG_Python_SetSwigThis(PyObject *inst, PyObject *swig_this) 2147 | { 2148 | PyObject *dict; 2149 | #if (PY_VERSION_HEX >= 0x02020000) && !defined(SWIG_PYTHON_SLOW_GETSET_THIS) 2150 | PyObject **dictptr = _PyObject_GetDictPtr(inst); 2151 | if (dictptr != NULL) { 2152 | dict = *dictptr; 2153 | if (dict == NULL) { 2154 | dict = PyDict_New(); 2155 | *dictptr = dict; 2156 | } 2157 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2158 | return; 2159 | } 2160 | #endif 2161 | dict = PyObject_GetAttrString(inst, (char*)"__dict__"); 2162 | PyDict_SetItem(dict, SWIG_This(), swig_this); 2163 | Py_DECREF(dict); 2164 | } 2165 | 2166 | 2167 | SWIGINTERN PyObject * 2168 | SWIG_Python_InitShadowInstance(PyObject *args) { 2169 | PyObject *obj[2]; 2170 | if (!SWIG_Python_UnpackTuple(args,(char*)"swiginit", 2, 2, obj)) { 2171 | return NULL; 2172 | } else { 2173 | PySwigObject *sthis = SWIG_Python_GetSwigThis(obj[0]); 2174 | if (sthis) { 2175 | PySwigObject_append((PyObject*) sthis, obj[1]); 2176 | } else { 2177 | SWIG_Python_SetSwigThis(obj[0], obj[1]); 2178 | } 2179 | return SWIG_Py_Void(); 2180 | } 2181 | } 2182 | 2183 | /* Create a new pointer object */ 2184 | 2185 | SWIGRUNTIME PyObject * 2186 | SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) { 2187 | if (!ptr) { 2188 | return SWIG_Py_Void(); 2189 | } else { 2190 | int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; 2191 | PyObject *robj = PySwigObject_New(ptr, type, own); 2192 | PySwigClientData *clientdata = type ? (PySwigClientData *)(type->clientdata) : 0; 2193 | if (clientdata && !(flags & SWIG_POINTER_NOSHADOW)) { 2194 | PyObject *inst = SWIG_Python_NewShadowInstance(clientdata, robj); 2195 | if (inst) { 2196 | Py_DECREF(robj); 2197 | robj = inst; 2198 | } 2199 | } 2200 | return robj; 2201 | } 2202 | } 2203 | 2204 | /* Create a new packed object */ 2205 | 2206 | SWIGRUNTIMEINLINE PyObject * 2207 | SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { 2208 | return ptr ? PySwigPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); 2209 | } 2210 | 2211 | /* -----------------------------------------------------------------------------* 2212 | * Get type list 2213 | * -----------------------------------------------------------------------------*/ 2214 | 2215 | #ifdef SWIG_LINK_RUNTIME 2216 | void *SWIG_ReturnGlobalTypeList(void *); 2217 | #endif 2218 | 2219 | SWIGRUNTIME swig_module_info * 2220 | SWIG_Python_GetModule(void) { 2221 | static void *type_pointer = (void *)0; 2222 | /* first check if module already created */ 2223 | if (!type_pointer) { 2224 | #ifdef SWIG_LINK_RUNTIME 2225 | type_pointer = SWIG_ReturnGlobalTypeList((void *)0); 2226 | #else 2227 | type_pointer = PyCObject_Import((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, 2228 | (char*)"type_pointer" SWIG_TYPE_TABLE_NAME); 2229 | if (PyErr_Occurred()) { 2230 | PyErr_Clear(); 2231 | type_pointer = (void *)0; 2232 | } 2233 | #endif 2234 | } 2235 | return (swig_module_info *) type_pointer; 2236 | } 2237 | 2238 | #if PY_MAJOR_VERSION < 2 2239 | /* PyModule_AddObject function was introduced in Python 2.0. The following function 2240 | is copied out of Python/modsupport.c in python version 2.3.4 */ 2241 | SWIGINTERN int 2242 | PyModule_AddObject(PyObject *m, char *name, PyObject *o) 2243 | { 2244 | PyObject *dict; 2245 | if (!PyModule_Check(m)) { 2246 | PyErr_SetString(PyExc_TypeError, 2247 | "PyModule_AddObject() needs module as first arg"); 2248 | return SWIG_ERROR; 2249 | } 2250 | if (!o) { 2251 | PyErr_SetString(PyExc_TypeError, 2252 | "PyModule_AddObject() needs non-NULL value"); 2253 | return SWIG_ERROR; 2254 | } 2255 | 2256 | dict = PyModule_GetDict(m); 2257 | if (dict == NULL) { 2258 | /* Internal error -- modules must have a dict! */ 2259 | PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__", 2260 | PyModule_GetName(m)); 2261 | return SWIG_ERROR; 2262 | } 2263 | if (PyDict_SetItemString(dict, name, o)) 2264 | return SWIG_ERROR; 2265 | Py_DECREF(o); 2266 | return SWIG_OK; 2267 | } 2268 | #endif 2269 | 2270 | SWIGRUNTIME void 2271 | SWIG_Python_DestroyModule(void *vptr) 2272 | { 2273 | swig_module_info *swig_module = (swig_module_info *) vptr; 2274 | swig_type_info **types = swig_module->types; 2275 | size_t i; 2276 | for (i =0; i < swig_module->size; ++i) { 2277 | swig_type_info *ty = types[i]; 2278 | if (ty->owndata) { 2279 | PySwigClientData *data = (PySwigClientData *) ty->clientdata; 2280 | if (data) PySwigClientData_Del(data); 2281 | } 2282 | } 2283 | Py_DECREF(SWIG_This()); 2284 | } 2285 | 2286 | SWIGRUNTIME void 2287 | SWIG_Python_SetModule(swig_module_info *swig_module) { 2288 | static PyMethodDef swig_empty_runtime_method_table[] = { {NULL, NULL, 0, NULL} };/* Sentinel */ 2289 | 2290 | PyObject *module = Py_InitModule((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION, 2291 | swig_empty_runtime_method_table); 2292 | PyObject *pointer = PyCObject_FromVoidPtr((void *) swig_module, SWIG_Python_DestroyModule); 2293 | if (pointer && module) { 2294 | PyModule_AddObject(module, (char*)"type_pointer" SWIG_TYPE_TABLE_NAME, pointer); 2295 | } else { 2296 | Py_XDECREF(pointer); 2297 | } 2298 | } 2299 | 2300 | /* The python cached type query */ 2301 | SWIGRUNTIME PyObject * 2302 | SWIG_Python_TypeCache(void) { 2303 | static PyObject *SWIG_STATIC_POINTER(cache) = PyDict_New(); 2304 | return cache; 2305 | } 2306 | 2307 | SWIGRUNTIME swig_type_info * 2308 | SWIG_Python_TypeQuery(const char *type) 2309 | { 2310 | PyObject *cache = SWIG_Python_TypeCache(); 2311 | PyObject *key = PyString_FromString(type); 2312 | PyObject *obj = PyDict_GetItem(cache, key); 2313 | swig_type_info *descriptor; 2314 | if (obj) { 2315 | descriptor = (swig_type_info *) PyCObject_AsVoidPtr(obj); 2316 | } else { 2317 | swig_module_info *swig_module = SWIG_Python_GetModule(); 2318 | descriptor = SWIG_TypeQueryModule(swig_module, swig_module, type); 2319 | if (descriptor) { 2320 | obj = PyCObject_FromVoidPtr(descriptor, NULL); 2321 | PyDict_SetItem(cache, key, obj); 2322 | Py_DECREF(obj); 2323 | } 2324 | } 2325 | Py_DECREF(key); 2326 | return descriptor; 2327 | } 2328 | 2329 | /* 2330 | For backward compatibility only 2331 | */ 2332 | #define SWIG_POINTER_EXCEPTION 0 2333 | #define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg) 2334 | #define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags) 2335 | 2336 | SWIGRUNTIME int 2337 | SWIG_Python_AddErrMesg(const char* mesg, int infront) 2338 | { 2339 | if (PyErr_Occurred()) { 2340 | PyObject *type = 0; 2341 | PyObject *value = 0; 2342 | PyObject *traceback = 0; 2343 | PyErr_Fetch(&type, &value, &traceback); 2344 | if (value) { 2345 | PyObject *old_str = PyObject_Str(value); 2346 | Py_XINCREF(type); 2347 | PyErr_Clear(); 2348 | if (infront) { 2349 | PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str)); 2350 | } else { 2351 | PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg); 2352 | } 2353 | Py_DECREF(old_str); 2354 | } 2355 | return 1; 2356 | } else { 2357 | return 0; 2358 | } 2359 | } 2360 | 2361 | SWIGRUNTIME int 2362 | SWIG_Python_ArgFail(int argnum) 2363 | { 2364 | if (PyErr_Occurred()) { 2365 | /* add information about failing argument */ 2366 | char mesg[256]; 2367 | PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum); 2368 | return SWIG_Python_AddErrMesg(mesg, 1); 2369 | } else { 2370 | return 0; 2371 | } 2372 | } 2373 | 2374 | SWIGRUNTIMEINLINE const char * 2375 | PySwigObject_GetDesc(PyObject *self) 2376 | { 2377 | PySwigObject *v = (PySwigObject *)self; 2378 | swig_type_info *ty = v ? v->ty : 0; 2379 | return ty ? ty->str : (char*)""; 2380 | } 2381 | 2382 | SWIGRUNTIME void 2383 | SWIG_Python_TypeError(const char *type, PyObject *obj) 2384 | { 2385 | if (type) { 2386 | #if defined(SWIG_COBJECT_TYPES) 2387 | if (obj && PySwigObject_Check(obj)) { 2388 | const char *otype = (const char *) PySwigObject_GetDesc(obj); 2389 | if (otype) { 2390 | PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received", 2391 | type, otype); 2392 | return; 2393 | } 2394 | } else 2395 | #endif 2396 | { 2397 | const char *otype = (obj ? obj->ob_type->tp_name : 0); 2398 | if (otype) { 2399 | PyObject *str = PyObject_Str(obj); 2400 | const char *cstr = str ? PyString_AsString(str) : 0; 2401 | if (cstr) { 2402 | PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received", 2403 | type, otype, cstr); 2404 | } else { 2405 | PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received", 2406 | type, otype); 2407 | } 2408 | Py_XDECREF(str); 2409 | return; 2410 | } 2411 | } 2412 | PyErr_Format(PyExc_TypeError, "a '%s' is expected", type); 2413 | } else { 2414 | PyErr_Format(PyExc_TypeError, "unexpected type is received"); 2415 | } 2416 | } 2417 | 2418 | 2419 | /* Convert a pointer value, signal an exception on a type mismatch */ 2420 | SWIGRUNTIME void * 2421 | SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { 2422 | void *result; 2423 | if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { 2424 | PyErr_Clear(); 2425 | if (flags & SWIG_POINTER_EXCEPTION) { 2426 | SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj); 2427 | SWIG_Python_ArgFail(argnum); 2428 | } 2429 | } 2430 | return result; 2431 | } 2432 | 2433 | 2434 | #ifdef __cplusplus 2435 | #if 0 2436 | { /* cc-mode */ 2437 | #endif 2438 | } 2439 | #endif 2440 | 2441 | 2442 | 2443 | #define SWIG_exception_fail(code, msg) do { SWIG_Error(code, msg); SWIG_fail; } while(0) 2444 | 2445 | #define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Error(SWIG_RuntimeError, msg); SWIG_fail; } else 2446 | 2447 | 2448 | 2449 | /* -------- TYPES TABLE (BEGIN) -------- */ 2450 | 2451 | #define SWIGTYPE_p_CFStringRef swig_types[0] 2452 | #define SWIGTYPE_p_MIDIClientRef swig_types[1] 2453 | #define SWIGTYPE_p_MIDIEndpointRef swig_types[2] 2454 | #define SWIGTYPE_p_MIDIPortRef swig_types[3] 2455 | #define SWIGTYPE_p_char swig_types[4] 2456 | static swig_type_info *swig_types[6]; 2457 | static swig_module_info swig_module = {swig_types, 5, 0, 0, 0, 0}; 2458 | #define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name) 2459 | #define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name) 2460 | 2461 | /* -------- TYPES TABLE (END) -------- */ 2462 | 2463 | #if (PY_VERSION_HEX <= 0x02000000) 2464 | # if !defined(SWIG_PYTHON_CLASSIC) 2465 | # error "This python version requires swig to be run with the '-classic' option" 2466 | # endif 2467 | #endif 2468 | 2469 | /*----------------------------------------------- 2470 | @(target):= _sequencer_osx.so 2471 | ------------------------------------------------*/ 2472 | #define SWIG_init init_sequencer_osx 2473 | 2474 | #define SWIG_name "_sequencer_osx" 2475 | 2476 | #define SWIGVERSION 0x010331 2477 | #define SWIG_VERSION SWIGVERSION 2478 | 2479 | 2480 | #define SWIG_as_voidptr(a) (void *)((const void *)(a)) 2481 | #define SWIG_as_voidptrptr(a) ((void)SWIG_as_voidptr(*a),(void**)(a)) 2482 | 2483 | 2484 | #include 2485 | #include 2486 | 2487 | /* MIDIClientCreate */ 2488 | MIDIClientRef _MIDIClientCreate(CFStringRef clientName) 2489 | { 2490 | OSStatus err; 2491 | MIDIClientRef client; 2492 | 2493 | /* create client handle */ 2494 | err = MIDIClientCreate(clientName, NULL, NULL, &client); 2495 | if(err != noErr) 2496 | { 2497 | PyErr_SetString(PyExc_SystemError, "Error during MIDIClientCreate."); 2498 | return 0; 2499 | } 2500 | return client; 2501 | } 2502 | 2503 | /* MIDIClientDispose */ 2504 | void _MIDIClientDispose(MIDIClientRef client) 2505 | { 2506 | OSStatus err; 2507 | err = MIDIClientDispose(client); 2508 | if(err != noErr) 2509 | { 2510 | PyErr_SetString(PyExc_SystemError, "Error during MIDIClientDispose."); 2511 | } 2512 | } 2513 | 2514 | /* MIDISourceCreate */ 2515 | MIDIEndpointRef _MIDISourceCreate(MIDIClientRef client, CFStringRef sourceName) 2516 | { 2517 | OSStatus err; 2518 | MIDIEndpointRef outSrc; 2519 | err = MIDISourceCreate(client, sourceName, &outSrc); 2520 | if(err != noErr) 2521 | { 2522 | PyErr_SetString(PyExc_SystemError, "Error during MIDISourceCreate."); 2523 | return 0; 2524 | } 2525 | return outSrc; 2526 | } 2527 | 2528 | /* MIDIOutputPortCreate */ 2529 | MIDIPortRef _MIDIOutputPortCreate(MIDIClientRef client, CFStringRef portName) 2530 | { 2531 | OSStatus err; 2532 | MIDIPortRef outPort; 2533 | err = MIDIOutputPortCreate(client, portName, &outPort); 2534 | if(err != noErr) 2535 | { 2536 | PyErr_SetString(PyExc_SystemError, "Error during MIDIOutputPortCreate."); 2537 | return 0; 2538 | } 2539 | return outPort; 2540 | } 2541 | 2542 | /* MIDIPortConnectSource */ 2543 | void _MIDIPortConnectSource(MIDIPortRef port, MIDIEndpointRef endpoint) 2544 | { 2545 | OSStatus err; 2546 | MIDIPortRef outPort; 2547 | err = MIDIPortConnectSource(port, endpoint, NULL); 2548 | if(err != noErr) 2549 | { 2550 | PyErr_SetString(PyExc_SystemError, "Error during MIDIPortConnectSource."); 2551 | } 2552 | } 2553 | 2554 | /* 2555 | void _MIDISend(MIDIEndpointRef *midi_source, unsigned char val) 2556 | { 2557 | MIDIPacketList pktlist; 2558 | MIDIPacket p; 2559 | Byte data[3]; 2560 | p_head = MIDIPacketListInit(&pktlist); 2561 | data[0] = 176; // Control change 2562 | data[1] = 1; // Modulation 2563 | data[2] = val; // Value 2564 | MIDIPacketListAdd( &pktlist, sizeof(p), p_head, 0, 3, data); 2565 | MIDIReceived(*midi_source, &pktlist); 2566 | } 2567 | */ 2568 | 2569 | 2570 | 2571 | /* MIDIGetNumberOfDevices */ 2572 | unsigned long _MIDIGetNumberOfDevices() 2573 | { 2574 | return (unsigned long) MIDIGetNumberOfDevices(); 2575 | } 2576 | 2577 | 2578 | 2579 | #define SWIG_From_long PyInt_FromLong 2580 | 2581 | 2582 | SWIGINTERNINLINE PyObject* 2583 | SWIG_From_unsigned_SS_long (unsigned long value) 2584 | { 2585 | return (value > LONG_MAX) ? 2586 | PyLong_FromUnsignedLong(value) : PyInt_FromLong((long)(value)); 2587 | } 2588 | 2589 | #ifdef __cplusplus 2590 | extern "C" { 2591 | #endif 2592 | SWIGINTERN PyObject *_wrap__MIDIGetNumberOfDevices(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { 2593 | PyObject *resultobj = 0; 2594 | unsigned long result; 2595 | 2596 | if (!PyArg_ParseTuple(args,(char *)":_MIDIGetNumberOfDevices")) SWIG_fail; 2597 | result = (unsigned long)_MIDIGetNumberOfDevices(); 2598 | resultobj = SWIG_From_unsigned_SS_long((unsigned long)(result)); 2599 | return resultobj; 2600 | fail: 2601 | return NULL; 2602 | } 2603 | 2604 | 2605 | SWIGINTERN PyObject *_wrap__MIDIClientCreate(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { 2606 | PyObject *resultobj = 0; 2607 | CFStringRef arg1 ; 2608 | MIDIClientRef result; 2609 | PyObject * obj0 = 0 ; 2610 | 2611 | { 2612 | arg1 = NULL; 2613 | } 2614 | if (!PyArg_ParseTuple(args,(char *)"O:_MIDIClientCreate",&obj0)) SWIG_fail; 2615 | { 2616 | if (!PyString_Check(obj0)) 2617 | { 2618 | PyErr_SetString(PyExc_ValueError, "Expecting a string"); 2619 | return NULL; 2620 | } 2621 | arg1 = CFStringCreateWithCString(NULL, PyString_AsString(obj0), kCFStringEncodingASCII); 2622 | } 2623 | result = _MIDIClientCreate(arg1); 2624 | resultobj = SWIG_NewPointerObj((MIDIClientRef *)memcpy((MIDIClientRef *)malloc(sizeof(MIDIClientRef)),&result,sizeof(MIDIClientRef)), SWIGTYPE_p_MIDIClientRef, SWIG_POINTER_OWN | 0 ); 2625 | { 2626 | CFRelease(arg1); 2627 | } 2628 | return resultobj; 2629 | fail: 2630 | { 2631 | CFRelease(arg1); 2632 | } 2633 | return NULL; 2634 | } 2635 | 2636 | 2637 | SWIGINTERN PyObject *_wrap__MIDIClientDispose(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { 2638 | PyObject *resultobj = 0; 2639 | MIDIClientRef arg1 ; 2640 | void *argp1 ; 2641 | int res1 = 0 ; 2642 | PyObject * obj0 = 0 ; 2643 | 2644 | if (!PyArg_ParseTuple(args,(char *)"O:_MIDIClientDispose",&obj0)) SWIG_fail; 2645 | { 2646 | res1 = SWIG_ConvertPtr(obj0, &argp1, SWIGTYPE_p_MIDIClientRef, 0 ); 2647 | if (!SWIG_IsOK(res1)) { 2648 | SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "_MIDIClientDispose" "', argument " "1"" of type '" "MIDIClientRef""'"); 2649 | } 2650 | if (!argp1) { 2651 | SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "_MIDIClientDispose" "', argument " "1"" of type '" "MIDIClientRef""'"); 2652 | } else { 2653 | arg1 = *((MIDIClientRef *)(argp1)); 2654 | } 2655 | } 2656 | _MIDIClientDispose(arg1); 2657 | resultobj = SWIG_Py_Void(); 2658 | return resultobj; 2659 | fail: 2660 | return NULL; 2661 | } 2662 | 2663 | 2664 | SWIGINTERN PyObject *_wrap__MIDISourceCreate(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { 2665 | PyObject *resultobj = 0; 2666 | MIDIClientRef arg1 ; 2667 | CFStringRef arg2 ; 2668 | MIDIEndpointRef result; 2669 | void *argp1 ; 2670 | int res1 = 0 ; 2671 | PyObject * obj0 = 0 ; 2672 | PyObject * obj1 = 0 ; 2673 | 2674 | { 2675 | arg2 = NULL; 2676 | } 2677 | if (!PyArg_ParseTuple(args,(char *)"OO:_MIDISourceCreate",&obj0,&obj1)) SWIG_fail; 2678 | { 2679 | res1 = SWIG_ConvertPtr(obj0, &argp1, SWIGTYPE_p_MIDIClientRef, 0 ); 2680 | if (!SWIG_IsOK(res1)) { 2681 | SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "_MIDISourceCreate" "', argument " "1"" of type '" "MIDIClientRef""'"); 2682 | } 2683 | if (!argp1) { 2684 | SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "_MIDISourceCreate" "', argument " "1"" of type '" "MIDIClientRef""'"); 2685 | } else { 2686 | arg1 = *((MIDIClientRef *)(argp1)); 2687 | } 2688 | } 2689 | { 2690 | if (!PyString_Check(obj1)) 2691 | { 2692 | PyErr_SetString(PyExc_ValueError, "Expecting a string"); 2693 | return NULL; 2694 | } 2695 | arg2 = CFStringCreateWithCString(NULL, PyString_AsString(obj1), kCFStringEncodingASCII); 2696 | } 2697 | result = _MIDISourceCreate(arg1,arg2); 2698 | resultobj = SWIG_NewPointerObj((MIDIEndpointRef *)memcpy((MIDIEndpointRef *)malloc(sizeof(MIDIEndpointRef)),&result,sizeof(MIDIEndpointRef)), SWIGTYPE_p_MIDIEndpointRef, SWIG_POINTER_OWN | 0 ); 2699 | { 2700 | CFRelease(arg2); 2701 | } 2702 | return resultobj; 2703 | fail: 2704 | { 2705 | CFRelease(arg2); 2706 | } 2707 | return NULL; 2708 | } 2709 | 2710 | 2711 | SWIGINTERN PyObject *_wrap__MIDIOutputPortCreate(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { 2712 | PyObject *resultobj = 0; 2713 | MIDIClientRef arg1 ; 2714 | CFStringRef arg2 ; 2715 | MIDIPortRef result; 2716 | void *argp1 ; 2717 | int res1 = 0 ; 2718 | PyObject * obj0 = 0 ; 2719 | PyObject * obj1 = 0 ; 2720 | 2721 | { 2722 | arg2 = NULL; 2723 | } 2724 | if (!PyArg_ParseTuple(args,(char *)"OO:_MIDIOutputPortCreate",&obj0,&obj1)) SWIG_fail; 2725 | { 2726 | res1 = SWIG_ConvertPtr(obj0, &argp1, SWIGTYPE_p_MIDIClientRef, 0 ); 2727 | if (!SWIG_IsOK(res1)) { 2728 | SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "_MIDIOutputPortCreate" "', argument " "1"" of type '" "MIDIClientRef""'"); 2729 | } 2730 | if (!argp1) { 2731 | SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "_MIDIOutputPortCreate" "', argument " "1"" of type '" "MIDIClientRef""'"); 2732 | } else { 2733 | arg1 = *((MIDIClientRef *)(argp1)); 2734 | } 2735 | } 2736 | { 2737 | if (!PyString_Check(obj1)) 2738 | { 2739 | PyErr_SetString(PyExc_ValueError, "Expecting a string"); 2740 | return NULL; 2741 | } 2742 | arg2 = CFStringCreateWithCString(NULL, PyString_AsString(obj1), kCFStringEncodingASCII); 2743 | } 2744 | result = _MIDIOutputPortCreate(arg1,arg2); 2745 | resultobj = SWIG_NewPointerObj((MIDIPortRef *)memcpy((MIDIPortRef *)malloc(sizeof(MIDIPortRef)),&result,sizeof(MIDIPortRef)), SWIGTYPE_p_MIDIPortRef, SWIG_POINTER_OWN | 0 ); 2746 | { 2747 | CFRelease(arg2); 2748 | } 2749 | return resultobj; 2750 | fail: 2751 | { 2752 | CFRelease(arg2); 2753 | } 2754 | return NULL; 2755 | } 2756 | 2757 | 2758 | SWIGINTERN PyObject *_wrap__MIDIPortConnectSource(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { 2759 | PyObject *resultobj = 0; 2760 | MIDIPortRef arg1 ; 2761 | MIDIEndpointRef arg2 ; 2762 | void *argp1 ; 2763 | int res1 = 0 ; 2764 | void *argp2 ; 2765 | int res2 = 0 ; 2766 | PyObject * obj0 = 0 ; 2767 | PyObject * obj1 = 0 ; 2768 | 2769 | if (!PyArg_ParseTuple(args,(char *)"OO:_MIDIPortConnectSource",&obj0,&obj1)) SWIG_fail; 2770 | { 2771 | res1 = SWIG_ConvertPtr(obj0, &argp1, SWIGTYPE_p_MIDIPortRef, 0 ); 2772 | if (!SWIG_IsOK(res1)) { 2773 | SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "_MIDIPortConnectSource" "', argument " "1"" of type '" "MIDIPortRef""'"); 2774 | } 2775 | if (!argp1) { 2776 | SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "_MIDIPortConnectSource" "', argument " "1"" of type '" "MIDIPortRef""'"); 2777 | } else { 2778 | arg1 = *((MIDIPortRef *)(argp1)); 2779 | } 2780 | } 2781 | { 2782 | res2 = SWIG_ConvertPtr(obj1, &argp2, SWIGTYPE_p_MIDIEndpointRef, 0 ); 2783 | if (!SWIG_IsOK(res2)) { 2784 | SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "_MIDIPortConnectSource" "', argument " "2"" of type '" "MIDIEndpointRef""'"); 2785 | } 2786 | if (!argp2) { 2787 | SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "_MIDIPortConnectSource" "', argument " "2"" of type '" "MIDIEndpointRef""'"); 2788 | } else { 2789 | arg2 = *((MIDIEndpointRef *)(argp2)); 2790 | } 2791 | } 2792 | _MIDIPortConnectSource(arg1,arg2); 2793 | resultobj = SWIG_Py_Void(); 2794 | return resultobj; 2795 | fail: 2796 | return NULL; 2797 | } 2798 | 2799 | 2800 | static PyMethodDef SwigMethods[] = { 2801 | { (char *)"_MIDIGetNumberOfDevices", _wrap__MIDIGetNumberOfDevices, METH_VARARGS, NULL}, 2802 | { (char *)"_MIDIClientCreate", _wrap__MIDIClientCreate, METH_VARARGS, NULL}, 2803 | { (char *)"_MIDIClientDispose", _wrap__MIDIClientDispose, METH_VARARGS, NULL}, 2804 | { (char *)"_MIDISourceCreate", _wrap__MIDISourceCreate, METH_VARARGS, NULL}, 2805 | { (char *)"_MIDIOutputPortCreate", _wrap__MIDIOutputPortCreate, METH_VARARGS, NULL}, 2806 | { (char *)"_MIDIPortConnectSource", _wrap__MIDIPortConnectSource, METH_VARARGS, NULL}, 2807 | { NULL, NULL, 0, NULL } 2808 | }; 2809 | 2810 | 2811 | /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */ 2812 | 2813 | static swig_type_info _swigt__p_CFStringRef = {"_p_CFStringRef", "CFStringRef *", 0, 0, (void*)0, 0}; 2814 | static swig_type_info _swigt__p_MIDIClientRef = {"_p_MIDIClientRef", "MIDIClientRef *", 0, 0, (void*)0, 0}; 2815 | static swig_type_info _swigt__p_MIDIEndpointRef = {"_p_MIDIEndpointRef", "MIDIEndpointRef *", 0, 0, (void*)0, 0}; 2816 | static swig_type_info _swigt__p_MIDIPortRef = {"_p_MIDIPortRef", "MIDIPortRef *", 0, 0, (void*)0, 0}; 2817 | static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0}; 2818 | 2819 | static swig_type_info *swig_type_initial[] = { 2820 | &_swigt__p_CFStringRef, 2821 | &_swigt__p_MIDIClientRef, 2822 | &_swigt__p_MIDIEndpointRef, 2823 | &_swigt__p_MIDIPortRef, 2824 | &_swigt__p_char, 2825 | }; 2826 | 2827 | static swig_cast_info _swigc__p_CFStringRef[] = { {&_swigt__p_CFStringRef, 0, 0, 0},{0, 0, 0, 0}}; 2828 | static swig_cast_info _swigc__p_MIDIClientRef[] = { {&_swigt__p_MIDIClientRef, 0, 0, 0},{0, 0, 0, 0}}; 2829 | static swig_cast_info _swigc__p_MIDIEndpointRef[] = { {&_swigt__p_MIDIEndpointRef, 0, 0, 0},{0, 0, 0, 0}}; 2830 | static swig_cast_info _swigc__p_MIDIPortRef[] = { {&_swigt__p_MIDIPortRef, 0, 0, 0},{0, 0, 0, 0}}; 2831 | static swig_cast_info _swigc__p_char[] = { {&_swigt__p_char, 0, 0, 0},{0, 0, 0, 0}}; 2832 | 2833 | static swig_cast_info *swig_cast_initial[] = { 2834 | _swigc__p_CFStringRef, 2835 | _swigc__p_MIDIClientRef, 2836 | _swigc__p_MIDIEndpointRef, 2837 | _swigc__p_MIDIPortRef, 2838 | _swigc__p_char, 2839 | }; 2840 | 2841 | 2842 | /* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */ 2843 | 2844 | static swig_const_info swig_const_table[] = { 2845 | {0, 0, 0, 0.0, 0, 0}}; 2846 | 2847 | #ifdef __cplusplus 2848 | } 2849 | #endif 2850 | /* ----------------------------------------------------------------------------- 2851 | * Type initialization: 2852 | * This problem is tough by the requirement that no dynamic 2853 | * memory is used. Also, since swig_type_info structures store pointers to 2854 | * swig_cast_info structures and swig_cast_info structures store pointers back 2855 | * to swig_type_info structures, we need some lookup code at initialization. 2856 | * The idea is that swig generates all the structures that are needed. 2857 | * The runtime then collects these partially filled structures. 2858 | * The SWIG_InitializeModule function takes these initial arrays out of 2859 | * swig_module, and does all the lookup, filling in the swig_module.types 2860 | * array with the correct data and linking the correct swig_cast_info 2861 | * structures together. 2862 | * 2863 | * The generated swig_type_info structures are assigned staticly to an initial 2864 | * array. We just loop through that array, and handle each type individually. 2865 | * First we lookup if this type has been already loaded, and if so, use the 2866 | * loaded structure instead of the generated one. Then we have to fill in the 2867 | * cast linked list. The cast data is initially stored in something like a 2868 | * two-dimensional array. Each row corresponds to a type (there are the same 2869 | * number of rows as there are in the swig_type_initial array). Each entry in 2870 | * a column is one of the swig_cast_info structures for that type. 2871 | * The cast_initial array is actually an array of arrays, because each row has 2872 | * a variable number of columns. So to actually build the cast linked list, 2873 | * we find the array of casts associated with the type, and loop through it 2874 | * adding the casts to the list. The one last trick we need to do is making 2875 | * sure the type pointer in the swig_cast_info struct is correct. 2876 | * 2877 | * First off, we lookup the cast->type name to see if it is already loaded. 2878 | * There are three cases to handle: 2879 | * 1) If the cast->type has already been loaded AND the type we are adding 2880 | * casting info to has not been loaded (it is in this module), THEN we 2881 | * replace the cast->type pointer with the type pointer that has already 2882 | * been loaded. 2883 | * 2) If BOTH types (the one we are adding casting info to, and the 2884 | * cast->type) are loaded, THEN the cast info has already been loaded by 2885 | * the previous module so we just ignore it. 2886 | * 3) Finally, if cast->type has not already been loaded, then we add that 2887 | * swig_cast_info to the linked list (because the cast->type) pointer will 2888 | * be correct. 2889 | * ----------------------------------------------------------------------------- */ 2890 | 2891 | #ifdef __cplusplus 2892 | extern "C" { 2893 | #if 0 2894 | } /* c-mode */ 2895 | #endif 2896 | #endif 2897 | 2898 | #if 0 2899 | #define SWIGRUNTIME_DEBUG 2900 | #endif 2901 | 2902 | 2903 | SWIGRUNTIME void 2904 | SWIG_InitializeModule(void *clientdata) { 2905 | size_t i; 2906 | swig_module_info *module_head, *iter; 2907 | int found; 2908 | 2909 | clientdata = clientdata; 2910 | 2911 | /* check to see if the circular list has been setup, if not, set it up */ 2912 | if (swig_module.next==0) { 2913 | /* Initialize the swig_module */ 2914 | swig_module.type_initial = swig_type_initial; 2915 | swig_module.cast_initial = swig_cast_initial; 2916 | swig_module.next = &swig_module; 2917 | } 2918 | 2919 | /* Try and load any already created modules */ 2920 | module_head = SWIG_GetModule(clientdata); 2921 | if (!module_head) { 2922 | /* This is the first module loaded for this interpreter */ 2923 | /* so set the swig module into the interpreter */ 2924 | SWIG_SetModule(clientdata, &swig_module); 2925 | module_head = &swig_module; 2926 | } else { 2927 | /* the interpreter has loaded a SWIG module, but has it loaded this one? */ 2928 | found=0; 2929 | iter=module_head; 2930 | do { 2931 | if (iter==&swig_module) { 2932 | found=1; 2933 | break; 2934 | } 2935 | iter=iter->next; 2936 | } while (iter!= module_head); 2937 | 2938 | /* if the is found in the list, then all is done and we may leave */ 2939 | if (found) return; 2940 | /* otherwise we must add out module into the list */ 2941 | swig_module.next = module_head->next; 2942 | module_head->next = &swig_module; 2943 | } 2944 | 2945 | /* Now work on filling in swig_module.types */ 2946 | #ifdef SWIGRUNTIME_DEBUG 2947 | printf("SWIG_InitializeModule: size %d\n", swig_module.size); 2948 | #endif 2949 | for (i = 0; i < swig_module.size; ++i) { 2950 | swig_type_info *type = 0; 2951 | swig_type_info *ret; 2952 | swig_cast_info *cast; 2953 | 2954 | #ifdef SWIGRUNTIME_DEBUG 2955 | printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); 2956 | #endif 2957 | 2958 | /* if there is another module already loaded */ 2959 | if (swig_module.next != &swig_module) { 2960 | type = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, swig_module.type_initial[i]->name); 2961 | } 2962 | if (type) { 2963 | /* Overwrite clientdata field */ 2964 | #ifdef SWIGRUNTIME_DEBUG 2965 | printf("SWIG_InitializeModule: found type %s\n", type->name); 2966 | #endif 2967 | if (swig_module.type_initial[i]->clientdata) { 2968 | type->clientdata = swig_module.type_initial[i]->clientdata; 2969 | #ifdef SWIGRUNTIME_DEBUG 2970 | printf("SWIG_InitializeModule: found and overwrite type %s \n", type->name); 2971 | #endif 2972 | } 2973 | } else { 2974 | type = swig_module.type_initial[i]; 2975 | } 2976 | 2977 | /* Insert casting types */ 2978 | cast = swig_module.cast_initial[i]; 2979 | while (cast->type) { 2980 | /* Don't need to add information already in the list */ 2981 | ret = 0; 2982 | #ifdef SWIGRUNTIME_DEBUG 2983 | printf("SWIG_InitializeModule: look cast %s\n", cast->type->name); 2984 | #endif 2985 | if (swig_module.next != &swig_module) { 2986 | ret = SWIG_MangledTypeQueryModule(swig_module.next, &swig_module, cast->type->name); 2987 | #ifdef SWIGRUNTIME_DEBUG 2988 | if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); 2989 | #endif 2990 | } 2991 | if (ret) { 2992 | if (type == swig_module.type_initial[i]) { 2993 | #ifdef SWIGRUNTIME_DEBUG 2994 | printf("SWIG_InitializeModule: skip old type %s\n", ret->name); 2995 | #endif 2996 | cast->type = ret; 2997 | ret = 0; 2998 | } else { 2999 | /* Check for casting already in the list */ 3000 | swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); 3001 | #ifdef SWIGRUNTIME_DEBUG 3002 | if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); 3003 | #endif 3004 | if (!ocast) ret = 0; 3005 | } 3006 | } 3007 | 3008 | if (!ret) { 3009 | #ifdef SWIGRUNTIME_DEBUG 3010 | printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); 3011 | #endif 3012 | if (type->cast) { 3013 | type->cast->prev = cast; 3014 | cast->next = type->cast; 3015 | } 3016 | type->cast = cast; 3017 | } 3018 | cast++; 3019 | } 3020 | /* Set entry in modules->types array equal to the type */ 3021 | swig_module.types[i] = type; 3022 | } 3023 | swig_module.types[i] = 0; 3024 | 3025 | #ifdef SWIGRUNTIME_DEBUG 3026 | printf("**** SWIG_InitializeModule: Cast List ******\n"); 3027 | for (i = 0; i < swig_module.size; ++i) { 3028 | int j = 0; 3029 | swig_cast_info *cast = swig_module.cast_initial[i]; 3030 | printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); 3031 | while (cast->type) { 3032 | printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); 3033 | cast++; 3034 | ++j; 3035 | } 3036 | printf("---- Total casts: %d\n",j); 3037 | } 3038 | printf("**** SWIG_InitializeModule: Cast List ******\n"); 3039 | #endif 3040 | } 3041 | 3042 | /* This function will propagate the clientdata field of type to 3043 | * any new swig_type_info structures that have been added into the list 3044 | * of equivalent types. It is like calling 3045 | * SWIG_TypeClientData(type, clientdata) a second time. 3046 | */ 3047 | SWIGRUNTIME void 3048 | SWIG_PropagateClientData(void) { 3049 | size_t i; 3050 | swig_cast_info *equiv; 3051 | static int init_run = 0; 3052 | 3053 | if (init_run) return; 3054 | init_run = 1; 3055 | 3056 | for (i = 0; i < swig_module.size; i++) { 3057 | if (swig_module.types[i]->clientdata) { 3058 | equiv = swig_module.types[i]->cast; 3059 | while (equiv) { 3060 | if (!equiv->converter) { 3061 | if (equiv->type && !equiv->type->clientdata) 3062 | SWIG_TypeClientData(equiv->type, swig_module.types[i]->clientdata); 3063 | } 3064 | equiv = equiv->next; 3065 | } 3066 | } 3067 | } 3068 | } 3069 | 3070 | #ifdef __cplusplus 3071 | #if 0 3072 | { 3073 | /* c-mode */ 3074 | #endif 3075 | } 3076 | #endif 3077 | 3078 | 3079 | 3080 | #ifdef __cplusplus 3081 | extern "C" { 3082 | #endif 3083 | 3084 | /* Python-specific SWIG API */ 3085 | #define SWIG_newvarlink() SWIG_Python_newvarlink() 3086 | #define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr) 3087 | #define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants) 3088 | 3089 | /* ----------------------------------------------------------------------------- 3090 | * global variable support code. 3091 | * ----------------------------------------------------------------------------- */ 3092 | 3093 | typedef struct swig_globalvar { 3094 | char *name; /* Name of global variable */ 3095 | PyObject *(*get_attr)(void); /* Return the current value */ 3096 | int (*set_attr)(PyObject *); /* Set the value */ 3097 | struct swig_globalvar *next; 3098 | } swig_globalvar; 3099 | 3100 | typedef struct swig_varlinkobject { 3101 | PyObject_HEAD 3102 | swig_globalvar *vars; 3103 | } swig_varlinkobject; 3104 | 3105 | SWIGINTERN PyObject * 3106 | swig_varlink_repr(swig_varlinkobject *SWIGUNUSEDPARM(v)) { 3107 | return PyString_FromString(""); 3108 | } 3109 | 3110 | SWIGINTERN PyObject * 3111 | swig_varlink_str(swig_varlinkobject *v) { 3112 | PyObject *str = PyString_FromString("("); 3113 | swig_globalvar *var; 3114 | for (var = v->vars; var; var=var->next) { 3115 | PyString_ConcatAndDel(&str,PyString_FromString(var->name)); 3116 | if (var->next) PyString_ConcatAndDel(&str,PyString_FromString(", ")); 3117 | } 3118 | PyString_ConcatAndDel(&str,PyString_FromString(")")); 3119 | return str; 3120 | } 3121 | 3122 | SWIGINTERN int 3123 | swig_varlink_print(swig_varlinkobject *v, FILE *fp, int SWIGUNUSEDPARM(flags)) { 3124 | PyObject *str = swig_varlink_str(v); 3125 | fprintf(fp,"Swig global variables "); 3126 | fprintf(fp,"%s\n", PyString_AsString(str)); 3127 | Py_DECREF(str); 3128 | return 0; 3129 | } 3130 | 3131 | SWIGINTERN void 3132 | swig_varlink_dealloc(swig_varlinkobject *v) { 3133 | swig_globalvar *var = v->vars; 3134 | while (var) { 3135 | swig_globalvar *n = var->next; 3136 | free(var->name); 3137 | free(var); 3138 | var = n; 3139 | } 3140 | } 3141 | 3142 | SWIGINTERN PyObject * 3143 | swig_varlink_getattr(swig_varlinkobject *v, char *n) { 3144 | PyObject *res = NULL; 3145 | swig_globalvar *var = v->vars; 3146 | while (var) { 3147 | if (strcmp(var->name,n) == 0) { 3148 | res = (*var->get_attr)(); 3149 | break; 3150 | } 3151 | var = var->next; 3152 | } 3153 | if (res == NULL && !PyErr_Occurred()) { 3154 | PyErr_SetString(PyExc_NameError,"Unknown C global variable"); 3155 | } 3156 | return res; 3157 | } 3158 | 3159 | SWIGINTERN int 3160 | swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) { 3161 | int res = 1; 3162 | swig_globalvar *var = v->vars; 3163 | while (var) { 3164 | if (strcmp(var->name,n) == 0) { 3165 | res = (*var->set_attr)(p); 3166 | break; 3167 | } 3168 | var = var->next; 3169 | } 3170 | if (res == 1 && !PyErr_Occurred()) { 3171 | PyErr_SetString(PyExc_NameError,"Unknown C global variable"); 3172 | } 3173 | return res; 3174 | } 3175 | 3176 | SWIGINTERN PyTypeObject* 3177 | swig_varlink_type(void) { 3178 | static char varlink__doc__[] = "Swig var link object"; 3179 | static PyTypeObject varlink_type; 3180 | static int type_init = 0; 3181 | if (!type_init) { 3182 | const PyTypeObject tmp 3183 | = { 3184 | PyObject_HEAD_INIT(NULL) 3185 | 0, /* Number of items in variable part (ob_size) */ 3186 | (char *)"swigvarlink", /* Type name (tp_name) */ 3187 | sizeof(swig_varlinkobject), /* Basic size (tp_basicsize) */ 3188 | 0, /* Itemsize (tp_itemsize) */ 3189 | (destructor) swig_varlink_dealloc, /* Deallocator (tp_dealloc) */ 3190 | (printfunc) swig_varlink_print, /* Print (tp_print) */ 3191 | (getattrfunc) swig_varlink_getattr, /* get attr (tp_getattr) */ 3192 | (setattrfunc) swig_varlink_setattr, /* Set attr (tp_setattr) */ 3193 | 0, /* tp_compare */ 3194 | (reprfunc) swig_varlink_repr, /* tp_repr */ 3195 | 0, /* tp_as_number */ 3196 | 0, /* tp_as_sequence */ 3197 | 0, /* tp_as_mapping */ 3198 | 0, /* tp_hash */ 3199 | 0, /* tp_call */ 3200 | (reprfunc)swig_varlink_str, /* tp_str */ 3201 | 0, /* tp_getattro */ 3202 | 0, /* tp_setattro */ 3203 | 0, /* tp_as_buffer */ 3204 | 0, /* tp_flags */ 3205 | varlink__doc__, /* tp_doc */ 3206 | 0, /* tp_traverse */ 3207 | 0, /* tp_clear */ 3208 | 0, /* tp_richcompare */ 3209 | 0, /* tp_weaklistoffset */ 3210 | #if PY_VERSION_HEX >= 0x02020000 3211 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* tp_iter -> tp_weaklist */ 3212 | #endif 3213 | #if PY_VERSION_HEX >= 0x02030000 3214 | 0, /* tp_del */ 3215 | #endif 3216 | #ifdef COUNT_ALLOCS 3217 | 0,0,0,0 /* tp_alloc -> tp_next */ 3218 | #endif 3219 | }; 3220 | varlink_type = tmp; 3221 | varlink_type.ob_type = &PyType_Type; 3222 | type_init = 1; 3223 | } 3224 | return &varlink_type; 3225 | } 3226 | 3227 | /* Create a variable linking object for use later */ 3228 | SWIGINTERN PyObject * 3229 | SWIG_Python_newvarlink(void) { 3230 | swig_varlinkobject *result = PyObject_NEW(swig_varlinkobject, swig_varlink_type()); 3231 | if (result) { 3232 | result->vars = 0; 3233 | } 3234 | return ((PyObject*) result); 3235 | } 3236 | 3237 | SWIGINTERN void 3238 | SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) { 3239 | swig_varlinkobject *v = (swig_varlinkobject *) p; 3240 | swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); 3241 | if (gv) { 3242 | size_t size = strlen(name)+1; 3243 | gv->name = (char *)malloc(size); 3244 | if (gv->name) { 3245 | strncpy(gv->name,name,size); 3246 | gv->get_attr = get_attr; 3247 | gv->set_attr = set_attr; 3248 | gv->next = v->vars; 3249 | } 3250 | } 3251 | v->vars = gv; 3252 | } 3253 | 3254 | SWIGINTERN PyObject * 3255 | SWIG_globals(void) { 3256 | static PyObject *_SWIG_globals = 0; 3257 | if (!_SWIG_globals) _SWIG_globals = SWIG_newvarlink(); 3258 | return _SWIG_globals; 3259 | } 3260 | 3261 | /* ----------------------------------------------------------------------------- 3262 | * constants/methods manipulation 3263 | * ----------------------------------------------------------------------------- */ 3264 | 3265 | /* Install Constants */ 3266 | SWIGINTERN void 3267 | SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { 3268 | PyObject *obj = 0; 3269 | size_t i; 3270 | for (i = 0; constants[i].type; ++i) { 3271 | switch(constants[i].type) { 3272 | case SWIG_PY_POINTER: 3273 | obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0); 3274 | break; 3275 | case SWIG_PY_BINARY: 3276 | obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype)); 3277 | break; 3278 | default: 3279 | obj = 0; 3280 | break; 3281 | } 3282 | if (obj) { 3283 | PyDict_SetItemString(d, constants[i].name, obj); 3284 | Py_DECREF(obj); 3285 | } 3286 | } 3287 | } 3288 | 3289 | /* -----------------------------------------------------------------------------*/ 3290 | /* Fix SwigMethods to carry the callback ptrs when needed */ 3291 | /* -----------------------------------------------------------------------------*/ 3292 | 3293 | SWIGINTERN void 3294 | SWIG_Python_FixMethods(PyMethodDef *methods, 3295 | swig_const_info *const_table, 3296 | swig_type_info **types, 3297 | swig_type_info **types_initial) { 3298 | size_t i; 3299 | for (i = 0; methods[i].ml_name; ++i) { 3300 | const char *c = methods[i].ml_doc; 3301 | if (c && (c = strstr(c, "swig_ptr: "))) { 3302 | int j; 3303 | swig_const_info *ci = 0; 3304 | const char *name = c + 10; 3305 | for (j = 0; const_table[j].type; ++j) { 3306 | if (strncmp(const_table[j].name, name, 3307 | strlen(const_table[j].name)) == 0) { 3308 | ci = &(const_table[j]); 3309 | break; 3310 | } 3311 | } 3312 | if (ci) { 3313 | size_t shift = (ci->ptype) - types; 3314 | swig_type_info *ty = types_initial[shift]; 3315 | size_t ldoc = (c - methods[i].ml_doc); 3316 | size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; 3317 | char *ndoc = (char*)malloc(ldoc + lptr + 10); 3318 | if (ndoc) { 3319 | char *buff = ndoc; 3320 | void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0; 3321 | if (ptr) { 3322 | strncpy(buff, methods[i].ml_doc, ldoc); 3323 | buff += ldoc; 3324 | strncpy(buff, "swig_ptr: ", 10); 3325 | buff += 10; 3326 | SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); 3327 | methods[i].ml_doc = ndoc; 3328 | } 3329 | } 3330 | } 3331 | } 3332 | } 3333 | } 3334 | 3335 | #ifdef __cplusplus 3336 | } 3337 | #endif 3338 | 3339 | /* -----------------------------------------------------------------------------* 3340 | * Partial Init method 3341 | * -----------------------------------------------------------------------------*/ 3342 | 3343 | #ifdef __cplusplus 3344 | extern "C" 3345 | #endif 3346 | SWIGEXPORT void SWIG_init(void) { 3347 | PyObject *m, *d; 3348 | 3349 | /* Fix SwigMethods to carry the callback ptrs when needed */ 3350 | SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_type_initial); 3351 | 3352 | m = Py_InitModule((char *) SWIG_name, SwigMethods); 3353 | d = PyModule_GetDict(m); 3354 | 3355 | SWIG_InitializeModule(0); 3356 | SWIG_InstallConstants(d,swig_const_table); 3357 | 3358 | 3359 | } 3360 | 3361 | -------------------------------------------------------------------------------- /src/sequencer_osx/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sniperwrb/python-midi/ec8071b56500dbf58d5a5650ca81990d855dc49f/src/sequencer_osx/test -------------------------------------------------------------------------------- /src/sequencer_osx/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | printf("%d\n", MIDIGetNumberOfDevices()); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /src/sequencer_osx/test.py: -------------------------------------------------------------------------------- 1 | import sequencer_osx 2 | print "MIDIGetNumberOfDevices:", sequencer_osx._MIDIGetNumberOfDevices() 3 | client = sequencer_osx._MIDIClientCreate("python") 4 | endpoint = sequencer_osx._MIDISourceCreate(client, "python-source") 5 | port = sequencer_osx._MIDIOutputPortCreate(client, "python-port") 6 | sequencer_osx._MIDIPortConnectSource(port, endpoint) 7 | print client, endpoint, endpoint 8 | raw_input() 9 | #sequencer_osx._MIDIClientDispose(handle) 10 | -------------------------------------------------------------------------------- /src/util.py: -------------------------------------------------------------------------------- 1 | 2 | def read_varlen(data): 3 | NEXTBYTE = 1 4 | value = 0 5 | while NEXTBYTE: 6 | chr = next(data) 7 | # is the hi-bit set? 8 | if not (chr & 0x80): 9 | # no next BYTE 10 | NEXTBYTE = 0 11 | # mask out the 8th bit 12 | chr = chr & 0x7f 13 | # shift last value up 7 bits 14 | value = value << 7 15 | # add new value 16 | value += chr 17 | return value 18 | 19 | def write_varlen(value): 20 | b1 = value & 0x7F 21 | value >>= 7 22 | if value: 23 | b2 = (value & 0x7F) | 0x80 24 | value >>= 7 25 | if value: 26 | b3 = (value & 0x7F) | 0x80 27 | value >>= 7 28 | if value: 29 | b4 = (value & 0x7F) | 0x80 30 | res = bytes((b4,b3,b2,b1)) 31 | else: 32 | res = bytes((b3,b2,b1)) 33 | else: 34 | res = bytes((b2,b1)) 35 | else: 36 | res = bytes((b1,)) 37 | return res 38 | 39 | -------------------------------------------------------------------------------- /tests/mary_test.py: -------------------------------------------------------------------------------- 1 | import midi 2 | 3 | MARY_MIDI = midi.Pattern(tracks=[[midi.TimeSignatureEvent(tick=0, data=[4, 2, 24, 8]), 4 | midi.KeySignatureEvent(tick=0, data=[0, 0]), 5 | midi.EndOfTrackEvent(tick=1, data=[])], 6 | [midi.ControlChangeEvent(tick=0, channel=0, data=[91, 58]), 7 | midi.ControlChangeEvent(tick=0, channel=0, data=[10, 69]), 8 | midi.ControlChangeEvent(tick=0, channel=0, data=[0, 0]), 9 | midi.ControlChangeEvent(tick=0, channel=0, data=[32, 0]), 10 | midi.ProgramChangeEvent(tick=0, channel=0, data=[24]), 11 | midi.NoteOnEvent(tick=0, channel=0, data=[64, 72]), 12 | midi.NoteOnEvent(tick=0, channel=0, data=[55, 70]), 13 | midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]), 14 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 72]), 15 | midi.NoteOnEvent(tick=231, channel=0, data=[62, 0]), 16 | midi.NoteOnEvent(tick=25, channel=0, data=[60, 71]), 17 | midi.NoteOnEvent(tick=231, channel=0, data=[60, 0]), 18 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 79]), 19 | midi.NoteOnEvent(tick=206, channel=0, data=[55, 0]), 20 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 0]), 21 | midi.NoteOnEvent(tick=25, channel=0, data=[64, 85]), 22 | midi.NoteOnEvent(tick=0, channel=0, data=[55, 79]), 23 | midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]), 24 | midi.NoteOnEvent(tick=25, channel=0, data=[64, 78]), 25 | midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]), 26 | midi.NoteOnEvent(tick=25, channel=0, data=[64, 74]), 27 | midi.NoteOnEvent(tick=462, channel=0, data=[55, 0]), 28 | midi.NoteOnEvent(tick=0, channel=0, data=[64, 0]), 29 | midi.NoteOnEvent(tick=50, channel=0, data=[62, 75]), 30 | midi.NoteOnEvent(tick=0, channel=0, data=[55, 77]), 31 | midi.NoteOnEvent(tick=231, channel=0, data=[62, 0]), 32 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 77]), 33 | midi.NoteOnEvent(tick=231, channel=0, data=[62, 0]), 34 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 75]), 35 | midi.NoteOnEvent(tick=462, channel=0, data=[55, 0]), 36 | midi.NoteOnEvent(tick=0, channel=0, data=[62, 0]), 37 | midi.NoteOnEvent(tick=50, channel=0, data=[64, 82]), 38 | midi.NoteOnEvent(tick=0, channel=0, data=[55, 79]), 39 | midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]), 40 | midi.NoteOnEvent(tick=25, channel=0, data=[67, 84]), 41 | midi.NoteOnEvent(tick=231, channel=0, data=[67, 0]), 42 | midi.NoteOnEvent(tick=25, channel=0, data=[67, 75]), 43 | midi.NoteOnEvent(tick=462, channel=0, data=[55, 0]), 44 | midi.NoteOnEvent(tick=0, channel=0, data=[67, 0]), 45 | midi.NoteOnEvent(tick=50, channel=0, data=[64, 73]), 46 | midi.NoteOnEvent(tick=0, channel=0, data=[55, 78]), 47 | midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]), 48 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 69]), 49 | midi.NoteOnEvent(tick=231, channel=0, data=[62, 0]), 50 | midi.NoteOnEvent(tick=25, channel=0, data=[60, 71]), 51 | midi.NoteOnEvent(tick=231, channel=0, data=[60, 0]), 52 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 80]), 53 | midi.NoteOnEvent(tick=206, channel=0, data=[55, 0]), 54 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 0]), 55 | midi.NoteOnEvent(tick=25, channel=0, data=[64, 84]), 56 | midi.NoteOnEvent(tick=0, channel=0, data=[55, 79]), 57 | midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]), 58 | midi.NoteOnEvent(tick=25, channel=0, data=[64, 76]), 59 | midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]), 60 | midi.NoteOnEvent(tick=25, channel=0, data=[64, 74]), 61 | midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]), 62 | midi.NoteOnEvent(tick=25, channel=0, data=[64, 77]), 63 | midi.NoteOnEvent(tick=206, channel=0, data=[55, 0]), 64 | midi.NoteOnEvent(tick=25, channel=0, data=[64, 0]), 65 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 75]), 66 | midi.NoteOnEvent(tick=0, channel=0, data=[55, 78]), 67 | midi.NoteOnEvent(tick=231, channel=0, data=[62, 0]), 68 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 74]), 69 | midi.NoteOnEvent(tick=231, channel=0, data=[62, 0]), 70 | midi.NoteOnEvent(tick=25, channel=0, data=[64, 81]), 71 | midi.NoteOnEvent(tick=231, channel=0, data=[64, 0]), 72 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 70]), 73 | midi.NoteOnEvent(tick=206, channel=0, data=[55, 0]), 74 | midi.NoteOnEvent(tick=25, channel=0, data=[62, 0]), 75 | midi.NoteOnEvent(tick=25, channel=0, data=[60, 73]), 76 | midi.NoteOnEvent(tick=0, channel=0, data=[52, 72]), 77 | midi.NoteOnEvent(tick=974, channel=0, data=[60, 0]), 78 | midi.NoteOnEvent(tick=0, channel=0, data=[52, 0]), 79 | midi.EndOfTrackEvent(tick=1, data=[])]]) 80 | -------------------------------------------------------------------------------- /tests/tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import midi 3 | import mary_test 4 | import time 5 | import os 6 | 7 | try: 8 | import midi.sequencer as sequencer 9 | except ImportError: 10 | sequencer = None 11 | 12 | def get_sequencer_type(): 13 | if sequencer == None: 14 | return None 15 | return sequencer.Sequencer.SEQUENCER_TYPE 16 | 17 | class TestMIDI(unittest.TestCase): 18 | def test_varlen(self): 19 | maxval = 0x0FFFFFFF 20 | for inval in xrange(0, maxval, maxval / 1000): 21 | datum = midi.write_varlen(inval) 22 | outval = midi.read_varlen(iter(datum)) 23 | self.assertEqual(inval, outval) 24 | 25 | def test_mary(self): 26 | midi.write_midifile("mary.mid", mary_test.MARY_MIDI) 27 | pattern1 = midi.read_midifile("mary.mid") 28 | midi.write_midifile("mary.mid", pattern1) 29 | pattern2 = midi.read_midifile("mary.mid") 30 | self.assertEqual(len(pattern1), len(pattern2)) 31 | for track_idx in range(len(pattern1)): 32 | self.assertEqual(len(pattern1[track_idx]), len(pattern2[track_idx])) 33 | for event_idx in range(len(pattern1[track_idx])): 34 | event1 = pattern1[track_idx][event_idx] 35 | event2 = pattern2[track_idx][event_idx] 36 | self.assertEqual(event1.tick, event2.tick) 37 | self.assertEqual(event1.data, event2.data) 38 | 39 | class TestSequencerALSA(unittest.TestCase): 40 | TEMPO = 120 41 | RESOLUTION = 1000 42 | 43 | def get_loop_client_port(self): 44 | hw = sequencer.SequencerHardware() 45 | ports = {port.name: port for port in hw} 46 | loop = ports.get("Midi Through", None) 47 | assert loop != None, "Could not find Midi Through port!" 48 | loop_port = loop.get_port("Midi Through Port-0") 49 | return (loop.client, loop_port.port) 50 | 51 | def get_reader_sequencer(self): 52 | (client, port) = self.get_loop_client_port() 53 | seq = sequencer.SequencerRead(sequencer_resolution=self.RESOLUTION) 54 | seq.subscribe_port(client, port) 55 | return seq 56 | 57 | def get_writer_sequencer(self): 58 | (client, port) = self.get_loop_client_port() 59 | seq = sequencer.SequencerWrite(sequencer_resolution=self.RESOLUTION) 60 | seq.subscribe_port(client, port) 61 | return seq 62 | 63 | @unittest.skipIf(get_sequencer_type() != "alsa", "ALSA Sequencer not found, skipping test") 64 | @unittest.skipIf(not os.path.exists("/dev/snd/seq"), "/dev/snd/seq is not available, skipping test") 65 | def test_loopback_sequencer(self): 66 | rseq = self.get_reader_sequencer() 67 | wseq = self.get_writer_sequencer() 68 | start_time = time.time() 69 | delay = 0.6 70 | rseq.start_sequencer() 71 | wseq.start_sequencer() 72 | tick = int((self.TEMPO / 60.0) * self.RESOLUTION * delay) 73 | send_event = midi.NoteOnEvent(tick=tick, velocity=20, pitch=midi.G_3) 74 | wseq.event_write(send_event, False, False, True) 75 | recv_event = rseq.event_read() 76 | while 1: 77 | now = time.time() 78 | recv_event = rseq.event_read() 79 | if recv_event is not None: 80 | break 81 | if (now - start_time) > (2 * delay): 82 | break 83 | time.sleep(.01) 84 | delta = now - start_time 85 | # make sure we received this event at the proper time 86 | self.assertGreaterEqual(delta, delay) 87 | # make sure this event is the one we transmitted 88 | self.assertEqual(send_event.data, recv_event.data) 89 | self.assertEqual(send_event.__class__, recv_event.__class__) 90 | 91 | if __name__ == '__main__': 92 | unittest.main() 93 | --------------------------------------------------------------------------------