repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
gccxml/pygccxml
pygccxml/parser/declarations_cache.py
configuration_signature
def configuration_signature(config): """ Return a signature for a configuration (xml_generator_configuration_t) object. This can then be used as a key in the cache. This method must take into account anything about a configuration that could cause the declarations generated to be different ...
python
def configuration_signature(config): """ Return a signature for a configuration (xml_generator_configuration_t) object. This can then be used as a key in the cache. This method must take into account anything about a configuration that could cause the declarations generated to be different ...
[ "def", "configuration_signature", "(", "config", ")", ":", "sig", "=", "hashlib", ".", "sha1", "(", ")", "if", "isinstance", "(", "config", ",", "cxx_parsers_cfg", ".", "xml_generator_configuration_t", ")", ":", "sig", ".", "update", "(", "str", "(", "config...
Return a signature for a configuration (xml_generator_configuration_t) object. This can then be used as a key in the cache. This method must take into account anything about a configuration that could cause the declarations generated to be different between runs.
[ "Return", "a", "signature", "for", "a", "configuration", "(", "xml_generator_configuration_t", ")", "object", "." ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/pygccxml/parser/declarations_cache.py#L37-L61
gccxml/pygccxml
pygccxml/parser/declarations_cache.py
file_cache_t.__load
def __load(file_name): """ Load pickled cache from file and return the object. """ if os.path.exists(file_name) and not os.path.isfile(file_name): raise RuntimeError( 'Cache should be initialized with valid full file name') if not os.path.exists(file_name): ...
python
def __load(file_name): """ Load pickled cache from file and return the object. """ if os.path.exists(file_name) and not os.path.isfile(file_name): raise RuntimeError( 'Cache should be initialized with valid full file name') if not os.path.exists(file_name): ...
[ "def", "__load", "(", "file_name", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "file_name", ")", "and", "not", "os", ".", "path", ".", "isfile", "(", "file_name", ")", ":", "raise", "RuntimeError", "(", "'Cache should be initialized with valid ful...
Load pickled cache from file and return the object.
[ "Load", "pickled", "cache", "from", "file", "and", "return", "the", "object", "." ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/pygccxml/parser/declarations_cache.py#L179-L212
gccxml/pygccxml
pygccxml/parser/declarations_cache.py
file_cache_t.update
def update(self, source_file, configuration, declarations, included_files): """ Update a cached record with the current key and value contents. """ record = record_t( source_signature=file_signature(source_file), config_signature=configuration_signature(configuration), ...
python
def update(self, source_file, configuration, declarations, included_files): """ Update a cached record with the current key and value contents. """ record = record_t( source_signature=file_signature(source_file), config_signature=configuration_signature(configuration), ...
[ "def", "update", "(", "self", ",", "source_file", ",", "configuration", ",", "declarations", ",", "included_files", ")", ":", "record", "=", "record_t", "(", "source_signature", "=", "file_signature", "(", "source_file", ")", ",", "config_signature", "=", "confi...
Update a cached record with the current key and value contents.
[ "Update", "a", "cached", "record", "with", "the", "current", "key", "and", "value", "contents", "." ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/pygccxml/parser/declarations_cache.py#L234-L250
gccxml/pygccxml
pygccxml/parser/declarations_cache.py
file_cache_t.cached_value
def cached_value(self, source_file, configuration): """ Attempt to lookup the cached declarations for the given file and configuration. Returns None if declaration not found or signature check fails. """ key = record_t.create_key(source_file, configuration) if ...
python
def cached_value(self, source_file, configuration): """ Attempt to lookup the cached declarations for the given file and configuration. Returns None if declaration not found or signature check fails. """ key = record_t.create_key(source_file, configuration) if ...
[ "def", "cached_value", "(", "self", ",", "source_file", ",", "configuration", ")", ":", "key", "=", "record_t", ".", "create_key", "(", "source_file", ",", "configuration", ")", "if", "key", "not", "in", "self", ".", "__cache", ":", "return", "None", "reco...
Attempt to lookup the cached declarations for the given file and configuration. Returns None if declaration not found or signature check fails.
[ "Attempt", "to", "lookup", "the", "cached", "declarations", "for", "the", "given", "file", "and", "configuration", "." ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/pygccxml/parser/declarations_cache.py#L252-L271
gccxml/pygccxml
pygccxml/parser/linker.py
linker_t.instance
def instance(self, inst): """ Called by __parse_xml_file in source_reader. """ self.__inst = inst # use inst, to reduce attribute access time if isinstance(inst, declarations.declaration_t) and \ inst.location is not None and \ inst.loca...
python
def instance(self, inst): """ Called by __parse_xml_file in source_reader. """ self.__inst = inst # use inst, to reduce attribute access time if isinstance(inst, declarations.declaration_t) and \ inst.location is not None and \ inst.loca...
[ "def", "instance", "(", "self", ",", "inst", ")", ":", "self", ".", "__inst", "=", "inst", "# use inst, to reduce attribute access time", "if", "isinstance", "(", "inst", ",", "declarations", ".", "declaration_t", ")", "and", "inst", ".", "location", "is", "no...
Called by __parse_xml_file in source_reader.
[ "Called", "by", "__parse_xml_file", "in", "source_reader", "." ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/pygccxml/parser/linker.py#L35-L47
gccxml/pygccxml
release_utils/utils.py
find_version
def find_version(file_path): """ Find the version of pygccxml. Used by setup.py and the sphinx's conf.py. Inspired by https://packaging.python.org/single_source_version/ Args: file_path (str): path to the file containing the version. """ with io.open( os.path.join( ...
python
def find_version(file_path): """ Find the version of pygccxml. Used by setup.py and the sphinx's conf.py. Inspired by https://packaging.python.org/single_source_version/ Args: file_path (str): path to the file containing the version. """ with io.open( os.path.join( ...
[ "def", "find_version", "(", "file_path", ")", ":", "with", "io", ".", "open", "(", "os", ".", "path", ".", "join", "(", "os", ".", "path", ".", "dirname", "(", "__file__", ")", ",", "os", ".", "path", ".", "normpath", "(", "file_path", ")", ")", ...
Find the version of pygccxml. Used by setup.py and the sphinx's conf.py. Inspired by https://packaging.python.org/single_source_version/ Args: file_path (str): path to the file containing the version.
[ "Find", "the", "version", "of", "pygccxml", "." ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/release_utils/utils.py#L12-L34
gccxml/pygccxml
pygccxml/parser/scanner.py
scanner_t.__read_byte_size
def __read_byte_size(decl, attrs): """Using duck typing to set the size instead of in constructor""" size = attrs.get(XML_AN_SIZE, 0) # Make sure the size is in bytes instead of bits decl.byte_size = int(size) / 8
python
def __read_byte_size(decl, attrs): """Using duck typing to set the size instead of in constructor""" size = attrs.get(XML_AN_SIZE, 0) # Make sure the size is in bytes instead of bits decl.byte_size = int(size) / 8
[ "def", "__read_byte_size", "(", "decl", ",", "attrs", ")", ":", "size", "=", "attrs", ".", "get", "(", "XML_AN_SIZE", ",", "0", ")", "# Make sure the size is in bytes instead of bits", "decl", ".", "byte_size", "=", "int", "(", "size", ")", "/", "8" ]
Using duck typing to set the size instead of in constructor
[ "Using", "duck", "typing", "to", "set", "the", "size", "instead", "of", "in", "constructor" ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/pygccxml/parser/scanner.py#L338-L342
gccxml/pygccxml
pygccxml/parser/scanner.py
scanner_t.__read_byte_offset
def __read_byte_offset(decl, attrs): """Using duck typing to set the offset instead of in constructor""" offset = attrs.get(XML_AN_OFFSET, 0) # Make sure the size is in bytes instead of bits decl.byte_offset = int(offset) / 8
python
def __read_byte_offset(decl, attrs): """Using duck typing to set the offset instead of in constructor""" offset = attrs.get(XML_AN_OFFSET, 0) # Make sure the size is in bytes instead of bits decl.byte_offset = int(offset) / 8
[ "def", "__read_byte_offset", "(", "decl", ",", "attrs", ")", ":", "offset", "=", "attrs", ".", "get", "(", "XML_AN_OFFSET", ",", "0", ")", "# Make sure the size is in bytes instead of bits", "decl", ".", "byte_offset", "=", "int", "(", "offset", ")", "/", "8" ...
Using duck typing to set the offset instead of in constructor
[ "Using", "duck", "typing", "to", "set", "the", "offset", "instead", "of", "in", "constructor" ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/pygccxml/parser/scanner.py#L345-L349
gccxml/pygccxml
pygccxml/parser/scanner.py
scanner_t.__read_byte_align
def __read_byte_align(decl, attrs): """Using duck typing to set the alignment""" align = attrs.get(XML_AN_ALIGN, 0) # Make sure the size is in bytes instead of bits decl.byte_align = int(align) / 8
python
def __read_byte_align(decl, attrs): """Using duck typing to set the alignment""" align = attrs.get(XML_AN_ALIGN, 0) # Make sure the size is in bytes instead of bits decl.byte_align = int(align) / 8
[ "def", "__read_byte_align", "(", "decl", ",", "attrs", ")", ":", "align", "=", "attrs", ".", "get", "(", "XML_AN_ALIGN", ",", "0", ")", "# Make sure the size is in bytes instead of bits", "decl", ".", "byte_align", "=", "int", "(", "align", ")", "/", "8" ]
Using duck typing to set the alignment
[ "Using", "duck", "typing", "to", "set", "the", "alignment" ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/pygccxml/parser/scanner.py#L352-L356
gccxml/pygccxml
pygccxml/parser/declarations_joiner.py
bind_aliases
def bind_aliases(decls): """ This function binds between class and it's typedefs. :param decls: list of all declarations :rtype: None """ visited = set() typedefs = [ decl for decl in decls if isinstance(decl, declarations.typedef_t)] for decl in typedefs: type_ = dec...
python
def bind_aliases(decls): """ This function binds between class and it's typedefs. :param decls: list of all declarations :rtype: None """ visited = set() typedefs = [ decl for decl in decls if isinstance(decl, declarations.typedef_t)] for decl in typedefs: type_ = dec...
[ "def", "bind_aliases", "(", "decls", ")", ":", "visited", "=", "set", "(", ")", "typedefs", "=", "[", "decl", "for", "decl", "in", "decls", "if", "isinstance", "(", "decl", ",", "declarations", ".", "typedef_t", ")", "]", "for", "decl", "in", "typedefs...
This function binds between class and it's typedefs. :param decls: list of all declarations :rtype: None
[ "This", "function", "binds", "between", "class", "and", "it", "s", "typedefs", "." ]
train
https://github.com/gccxml/pygccxml/blob/2b1efbb9e37ceb2ae925c7f3ce1570f476db9e1e/pygccxml/parser/declarations_joiner.py#L9-L32
d11wtq/dockerpty
features/environment.py
before_all
def before_all(ctx): """ Pulls down busybox:latest before anything is tested. """ ctx.client = get_client() try: ctx.client.inspect_image(IMAGE) except NotFound: ctx.client.pull(IMAGE)
python
def before_all(ctx): """ Pulls down busybox:latest before anything is tested. """ ctx.client = get_client() try: ctx.client.inspect_image(IMAGE) except NotFound: ctx.client.pull(IMAGE)
[ "def", "before_all", "(", "ctx", ")", ":", "ctx", ".", "client", "=", "get_client", "(", ")", "try", ":", "ctx", ".", "client", ".", "inspect_image", "(", "IMAGE", ")", "except", "NotFound", ":", "ctx", ".", "client", ".", "pull", "(", "IMAGE", ")" ]
Pulls down busybox:latest before anything is tested.
[ "Pulls", "down", "busybox", ":", "latest", "before", "anything", "is", "tested", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/features/environment.py#L25-L34
d11wtq/dockerpty
features/environment.py
after_scenario
def after_scenario(ctx, scenario): """ Cleans up docker containers used as test fixtures after test completes. """ if hasattr(ctx, 'container') and hasattr(ctx, 'client'): try: ctx.client.remove_container(ctx.container, force=True) except: pass
python
def after_scenario(ctx, scenario): """ Cleans up docker containers used as test fixtures after test completes. """ if hasattr(ctx, 'container') and hasattr(ctx, 'client'): try: ctx.client.remove_container(ctx.container, force=True) except: pass
[ "def", "after_scenario", "(", "ctx", ",", "scenario", ")", ":", "if", "hasattr", "(", "ctx", ",", "'container'", ")", "and", "hasattr", "(", "ctx", ",", "'client'", ")", ":", "try", ":", "ctx", ".", "client", ".", "remove_container", "(", "ctx", ".", ...
Cleans up docker containers used as test fixtures after test completes.
[ "Cleans", "up", "docker", "containers", "used", "as", "test", "fixtures", "after", "test", "completes", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/features/environment.py#L37-L46
d11wtq/dockerpty
dockerpty/io.py
set_blocking
def set_blocking(fd, blocking=True): """ Set the given file-descriptor blocking or non-blocking. Returns the original blocking status. """ old_flag = fcntl.fcntl(fd, fcntl.F_GETFL) if blocking: new_flag = old_flag & ~ os.O_NONBLOCK else: new_flag = old_flag | os.O_NONBLOCK...
python
def set_blocking(fd, blocking=True): """ Set the given file-descriptor blocking or non-blocking. Returns the original blocking status. """ old_flag = fcntl.fcntl(fd, fcntl.F_GETFL) if blocking: new_flag = old_flag & ~ os.O_NONBLOCK else: new_flag = old_flag | os.O_NONBLOCK...
[ "def", "set_blocking", "(", "fd", ",", "blocking", "=", "True", ")", ":", "old_flag", "=", "fcntl", ".", "fcntl", "(", "fd", ",", "fcntl", ".", "F_GETFL", ")", "if", "blocking", ":", "new_flag", "=", "old_flag", "&", "~", "os", ".", "O_NONBLOCK", "el...
Set the given file-descriptor blocking or non-blocking. Returns the original blocking status.
[ "Set", "the", "given", "file", "-", "descriptor", "blocking", "or", "non", "-", "blocking", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/io.py#L25-L41
d11wtq/dockerpty
dockerpty/io.py
select
def select(read_streams, write_streams, timeout=0): """ Select the streams from `read_streams` that are ready for reading, and streams from `write_streams` ready for writing. Uses `select.select()` internally but only returns two lists of ready streams. """ exception_streams = [] try: ...
python
def select(read_streams, write_streams, timeout=0): """ Select the streams from `read_streams` that are ready for reading, and streams from `write_streams` ready for writing. Uses `select.select()` internally but only returns two lists of ready streams. """ exception_streams = [] try: ...
[ "def", "select", "(", "read_streams", ",", "write_streams", ",", "timeout", "=", "0", ")", ":", "exception_streams", "=", "[", "]", "try", ":", "return", "builtin_select", ".", "select", "(", "read_streams", ",", "write_streams", ",", "exception_streams", ",",...
Select the streams from `read_streams` that are ready for reading, and streams from `write_streams` ready for writing. Uses `select.select()` internally but only returns two lists of ready streams.
[ "Select", "the", "streams", "from", "read_streams", "that", "are", "ready", "for", "reading", "and", "streams", "from", "write_streams", "ready", "for", "writing", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/io.py#L44-L67
d11wtq/dockerpty
dockerpty/io.py
Stream.read
def read(self, n=4096): """ Return `n` bytes of data from the Stream, or None at end of stream. """ while True: try: if hasattr(self.fd, 'recv'): return self.fd.recv(n) return os.read(self.fd.fileno(), n) except...
python
def read(self, n=4096): """ Return `n` bytes of data from the Stream, or None at end of stream. """ while True: try: if hasattr(self.fd, 'recv'): return self.fd.recv(n) return os.read(self.fd.fileno(), n) except...
[ "def", "read", "(", "self", ",", "n", "=", "4096", ")", ":", "while", "True", ":", "try", ":", "if", "hasattr", "(", "self", ".", "fd", ",", "'recv'", ")", ":", "return", "self", ".", "fd", ".", "recv", "(", "n", ")", "return", "os", ".", "re...
Return `n` bytes of data from the Stream, or None at end of stream.
[ "Return", "n", "bytes", "of", "data", "from", "the", "Stream", "or", "None", "at", "end", "of", "stream", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/io.py#L112-L124
d11wtq/dockerpty
dockerpty/io.py
Stream.write
def write(self, data): """ Write `data` to the Stream. Not all data may be written right away. Use select to find when the stream is writeable, and call do_write() to flush the internal buffer. """ if not data: return None self.buffer += data ...
python
def write(self, data): """ Write `data` to the Stream. Not all data may be written right away. Use select to find when the stream is writeable, and call do_write() to flush the internal buffer. """ if not data: return None self.buffer += data ...
[ "def", "write", "(", "self", ",", "data", ")", ":", "if", "not", "data", ":", "return", "None", "self", ".", "buffer", "+=", "data", "self", ".", "do_write", "(", ")", "return", "len", "(", "data", ")" ]
Write `data` to the Stream. Not all data may be written right away. Use select to find when the stream is writeable, and call do_write() to flush the internal buffer.
[ "Write", "data", "to", "the", "Stream", ".", "Not", "all", "data", "may", "be", "written", "right", "away", ".", "Use", "select", "to", "find", "when", "the", "stream", "is", "writeable", "and", "call", "do_write", "()", "to", "flush", "the", "internal",...
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/io.py#L127-L140
d11wtq/dockerpty
dockerpty/io.py
Stream.do_write
def do_write(self): """ Flushes as much pending data from the internal write buffer as possible. """ while True: try: written = 0 if hasattr(self.fd, 'send'): written = self.fd.send(self.buffer) else: ...
python
def do_write(self): """ Flushes as much pending data from the internal write buffer as possible. """ while True: try: written = 0 if hasattr(self.fd, 'send'): written = self.fd.send(self.buffer) else: ...
[ "def", "do_write", "(", "self", ")", ":", "while", "True", ":", "try", ":", "written", "=", "0", "if", "hasattr", "(", "self", ".", "fd", ",", "'send'", ")", ":", "written", "=", "self", ".", "fd", ".", "send", "(", "self", ".", "buffer", ")", ...
Flushes as much pending data from the internal write buffer as possible.
[ "Flushes", "as", "much", "pending", "data", "from", "the", "internal", "write", "buffer", "as", "possible", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/io.py#L142-L164
d11wtq/dockerpty
dockerpty/io.py
Demuxer.read
def read(self, n=4096): """ Read up to `n` bytes of data from the Stream, after demuxing. Less than `n` bytes of data may be returned depending on the available payload, but the number of bytes returned will never exceed `n`. Because demuxing involves scanning 8-byte headers, t...
python
def read(self, n=4096): """ Read up to `n` bytes of data from the Stream, after demuxing. Less than `n` bytes of data may be returned depending on the available payload, but the number of bytes returned will never exceed `n`. Because demuxing involves scanning 8-byte headers, t...
[ "def", "read", "(", "self", ",", "n", "=", "4096", ")", ":", "size", "=", "self", ".", "_next_packet_size", "(", "n", ")", "if", "size", "<=", "0", ":", "return", "else", ":", "data", "=", "six", ".", "binary_type", "(", ")", "while", "len", "(",...
Read up to `n` bytes of data from the Stream, after demuxing. Less than `n` bytes of data may be returned depending on the available payload, but the number of bytes returned will never exceed `n`. Because demuxing involves scanning 8-byte headers, the actual amount of data read from t...
[ "Read", "up", "to", "n", "bytes", "of", "data", "from", "the", "Stream", "after", "demuxing", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/io.py#L224-L247
d11wtq/dockerpty
dockerpty/io.py
Pump.flush
def flush(self, n=4096): """ Flush `n` bytes of data from the reader Stream to the writer Stream. Returns the number of bytes that were actually flushed. A return value of zero is not an error. If EOF has been reached, `None` is returned. """ try: r...
python
def flush(self, n=4096): """ Flush `n` bytes of data from the reader Stream to the writer Stream. Returns the number of bytes that were actually flushed. A return value of zero is not an error. If EOF has been reached, `None` is returned. """ try: r...
[ "def", "flush", "(", "self", ",", "n", "=", "4096", ")", ":", "try", ":", "read", "=", "self", ".", "from_stream", ".", "read", "(", "n", ")", "if", "read", "is", "None", "or", "len", "(", "read", ")", "==", "0", ":", "self", ".", "eof", "=",...
Flush `n` bytes of data from the reader Stream to the writer Stream. Returns the number of bytes that were actually flushed. A return value of zero is not an error. If EOF has been reached, `None` is returned.
[ "Flush", "n", "bytes", "of", "data", "from", "the", "reader", "Stream", "to", "the", "writer", "Stream", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/io.py#L356-L378
d11wtq/dockerpty
dockerpty/io.py
Pump.is_done
def is_done(self): """ Returns True if the read stream is done (either it's returned EOF or the pump doesn't have wait_for_output set), and the write side does not have pending bytes to send. """ return (not self.wait_for_output or self.eof) and \ not (ha...
python
def is_done(self): """ Returns True if the read stream is done (either it's returned EOF or the pump doesn't have wait_for_output set), and the write side does not have pending bytes to send. """ return (not self.wait_for_output or self.eof) and \ not (ha...
[ "def", "is_done", "(", "self", ")", ":", "return", "(", "not", "self", ".", "wait_for_output", "or", "self", ".", "eof", ")", "and", "not", "(", "hasattr", "(", "self", ".", "to_stream", ",", "'needs_write'", ")", "and", "self", ".", "to_stream", ".", ...
Returns True if the read stream is done (either it's returned EOF or the pump doesn't have wait_for_output set), and the write side does not have pending bytes to send.
[ "Returns", "True", "if", "the", "read", "stream", "is", "done", "(", "either", "it", "s", "returned", "EOF", "or", "the", "pump", "doesn", "t", "have", "wait_for_output", "set", ")", "and", "the", "write", "side", "does", "not", "have", "pending", "bytes...
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/io.py#L380-L388
d11wtq/dockerpty
dockerpty/__init__.py
start
def start(client, container, interactive=True, stdout=None, stderr=None, stdin=None, logs=None): """ Present the PTY of the container inside the current process. This is just a wrapper for PseudoTerminal(client, container).start() """ operation = RunOperation(client, container, interactive=interac...
python
def start(client, container, interactive=True, stdout=None, stderr=None, stdin=None, logs=None): """ Present the PTY of the container inside the current process. This is just a wrapper for PseudoTerminal(client, container).start() """ operation = RunOperation(client, container, interactive=interac...
[ "def", "start", "(", "client", ",", "container", ",", "interactive", "=", "True", ",", "stdout", "=", "None", ",", "stderr", "=", "None", ",", "stdin", "=", "None", ",", "logs", "=", "None", ")", ":", "operation", "=", "RunOperation", "(", "client", ...
Present the PTY of the container inside the current process. This is just a wrapper for PseudoTerminal(client, container).start()
[ "Present", "the", "PTY", "of", "the", "container", "inside", "the", "current", "process", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/__init__.py#L20-L30
d11wtq/dockerpty
dockerpty/__init__.py
exec_command
def exec_command( client, container, command, interactive=True, stdout=None, stderr=None, stdin=None): """ Run provided command via exec API in provided container. This is just a wrapper for PseudoTerminal(client, container).exec_command() """ exec_id = exec_create(client, container, comman...
python
def exec_command( client, container, command, interactive=True, stdout=None, stderr=None, stdin=None): """ Run provided command via exec API in provided container. This is just a wrapper for PseudoTerminal(client, container).exec_command() """ exec_id = exec_create(client, container, comman...
[ "def", "exec_command", "(", "client", ",", "container", ",", "command", ",", "interactive", "=", "True", ",", "stdout", "=", "None", ",", "stderr", "=", "None", ",", "stdin", "=", "None", ")", ":", "exec_id", "=", "exec_create", "(", "client", ",", "co...
Run provided command via exec API in provided container. This is just a wrapper for PseudoTerminal(client, container).exec_command()
[ "Run", "provided", "command", "via", "exec", "API", "in", "provided", "container", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/__init__.py#L33-L44
d11wtq/dockerpty
dockerpty/tty.py
size
def size(fd): """ Return a tuple (rows,cols) representing the size of the TTY `fd`. The provided file descriptor should be the stdout stream of the TTY. If the TTY size cannot be determined, returns None. """ if not os.isatty(fd.fileno()): return None try: dims = struct.u...
python
def size(fd): """ Return a tuple (rows,cols) representing the size of the TTY `fd`. The provided file descriptor should be the stdout stream of the TTY. If the TTY size cannot be determined, returns None. """ if not os.isatty(fd.fileno()): return None try: dims = struct.u...
[ "def", "size", "(", "fd", ")", ":", "if", "not", "os", ".", "isatty", "(", "fd", ".", "fileno", "(", ")", ")", ":", "return", "None", "try", ":", "dims", "=", "struct", ".", "unpack", "(", "'hh'", ",", "fcntl", ".", "ioctl", "(", "fd", ",", "...
Return a tuple (rows,cols) representing the size of the TTY `fd`. The provided file descriptor should be the stdout stream of the TTY. If the TTY size cannot be determined, returns None.
[ "Return", "a", "tuple", "(", "rows", "cols", ")", "representing", "the", "size", "of", "the", "TTY", "fd", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/tty.py#L26-L46
d11wtq/dockerpty
dockerpty/tty.py
Terminal.start
def start(self): """ Saves the current terminal attributes and makes the tty raw. This method returns None immediately. """ if os.isatty(self.fd.fileno()) and self.israw(): self.original_attributes = termios.tcgetattr(self.fd) tty.setraw(self.fd)
python
def start(self): """ Saves the current terminal attributes and makes the tty raw. This method returns None immediately. """ if os.isatty(self.fd.fileno()) and self.israw(): self.original_attributes = termios.tcgetattr(self.fd) tty.setraw(self.fd)
[ "def", "start", "(", "self", ")", ":", "if", "os", ".", "isatty", "(", "self", ".", "fd", ".", "fileno", "(", ")", ")", "and", "self", ".", "israw", "(", ")", ":", "self", ".", "original_attributes", "=", "termios", ".", "tcgetattr", "(", "self", ...
Saves the current terminal attributes and makes the tty raw. This method returns None immediately.
[ "Saves", "the", "current", "terminal", "attributes", "and", "makes", "the", "tty", "raw", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/tty.py#L100-L109
d11wtq/dockerpty
dockerpty/tty.py
Terminal.stop
def stop(self): """ Restores the terminal attributes back to before setting raw mode. If the raw terminal was not started, does nothing. """ if self.original_attributes is not None: termios.tcsetattr( self.fd, termios.TCSADRAIN, ...
python
def stop(self): """ Restores the terminal attributes back to before setting raw mode. If the raw terminal was not started, does nothing. """ if self.original_attributes is not None: termios.tcsetattr( self.fd, termios.TCSADRAIN, ...
[ "def", "stop", "(", "self", ")", ":", "if", "self", ".", "original_attributes", "is", "not", "None", ":", "termios", ".", "tcsetattr", "(", "self", ".", "fd", ",", "termios", ".", "TCSADRAIN", ",", "self", ".", "original_attributes", ",", ")" ]
Restores the terminal attributes back to before setting raw mode. If the raw terminal was not started, does nothing.
[ "Restores", "the", "terminal", "attributes", "back", "to", "before", "setting", "raw", "mode", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/tty.py#L112-L124
d11wtq/dockerpty
dockerpty/pty.py
WINCHHandler.start
def start(self): """ Start trapping WINCH signals and resizing the PTY. This method saves the previous WINCH handler so it can be restored on `stop()`. """ def handle(signum, frame): if signum == signal.SIGWINCH: self.pty.resize() se...
python
def start(self): """ Start trapping WINCH signals and resizing the PTY. This method saves the previous WINCH handler so it can be restored on `stop()`. """ def handle(signum, frame): if signum == signal.SIGWINCH: self.pty.resize() se...
[ "def", "start", "(", "self", ")", ":", "def", "handle", "(", "signum", ",", "frame", ")", ":", "if", "signum", "==", "signal", ".", "SIGWINCH", ":", "self", ".", "pty", ".", "resize", "(", ")", "self", ".", "original_handler", "=", "signal", ".", "...
Start trapping WINCH signals and resizing the PTY. This method saves the previous WINCH handler so it can be restored on `stop()`.
[ "Start", "trapping", "WINCH", "signals", "and", "resizing", "the", "PTY", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L57-L69
d11wtq/dockerpty
dockerpty/pty.py
WINCHHandler.stop
def stop(self): """ Stop trapping WINCH signals and restore the previous WINCH handler. """ if self.original_handler is not None: signal.signal(signal.SIGWINCH, self.original_handler)
python
def stop(self): """ Stop trapping WINCH signals and restore the previous WINCH handler. """ if self.original_handler is not None: signal.signal(signal.SIGWINCH, self.original_handler)
[ "def", "stop", "(", "self", ")", ":", "if", "self", ".", "original_handler", "is", "not", "None", ":", "signal", ".", "signal", "(", "signal", ".", "SIGWINCH", ",", "self", ".", "original_handler", ")" ]
Stop trapping WINCH signals and restore the previous WINCH handler.
[ "Stop", "trapping", "WINCH", "signals", "and", "restore", "the", "previous", "WINCH", "handler", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L71-L77
d11wtq/dockerpty
dockerpty/pty.py
RunOperation.start
def start(self, sockets=None, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = sockets or self.sockets() pumps = ...
python
def start(self, sockets=None, **kwargs): """ Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed. """ pty_stdin, pty_stdout, pty_stderr = sockets or self.sockets() pumps = ...
[ "def", "start", "(", "self", ",", "sockets", "=", "None", ",", "*", "*", "kwargs", ")", ":", "pty_stdin", ",", "pty_stdout", ",", "pty_stderr", "=", "sockets", "or", "self", ".", "sockets", "(", ")", "pumps", "=", "[", "]", "if", "pty_stdin", "and", ...
Present the PTY of the container inside the current process. This will take over the current process' TTY until the container's PTY is closed.
[ "Present", "the", "PTY", "of", "the", "container", "inside", "the", "current", "process", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L128-L151
d11wtq/dockerpty
dockerpty/pty.py
RunOperation.israw
def israw(self, **kwargs): """ Returns True if the PTY should operate in raw mode. If the container was not started with tty=True, this will return False. """ if self.raw is None: info = self._container_info() self.raw = self.stdout.isatty() and info['Co...
python
def israw(self, **kwargs): """ Returns True if the PTY should operate in raw mode. If the container was not started with tty=True, this will return False. """ if self.raw is None: info = self._container_info() self.raw = self.stdout.isatty() and info['Co...
[ "def", "israw", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "raw", "is", "None", ":", "info", "=", "self", ".", "_container_info", "(", ")", "self", ".", "raw", "=", "self", ".", "stdout", ".", "isatty", "(", ")", "and", ...
Returns True if the PTY should operate in raw mode. If the container was not started with tty=True, this will return False.
[ "Returns", "True", "if", "the", "PTY", "should", "operate", "in", "raw", "mode", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L153-L164
d11wtq/dockerpty
dockerpty/pty.py
RunOperation.sockets
def sockets(self): """ Returns a tuple of sockets connected to the pty (stdin,stdout,stderr). If any of the sockets are not attached in the container, `None` is returned in the tuple. """ info = self._container_info() def attach_socket(key): if info...
python
def sockets(self): """ Returns a tuple of sockets connected to the pty (stdin,stdout,stderr). If any of the sockets are not attached in the container, `None` is returned in the tuple. """ info = self._container_info() def attach_socket(key): if info...
[ "def", "sockets", "(", "self", ")", ":", "info", "=", "self", ".", "_container_info", "(", ")", "def", "attach_socket", "(", "key", ")", ":", "if", "info", "[", "'Config'", "]", "[", "'Attach{0}'", ".", "format", "(", "key", ".", "capitalize", "(", "...
Returns a tuple of sockets connected to the pty (stdin,stdout,stderr). If any of the sockets are not attached in the container, `None` is returned in the tuple.
[ "Returns", "a", "tuple", "of", "sockets", "connected", "to", "the", "pty", "(", "stdin", "stdout", "stderr", ")", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L166-L191
d11wtq/dockerpty
dockerpty/pty.py
RunOperation.resize
def resize(self, height, width, **kwargs): """ resize pty within container """ self.client.resize(self.container, height=height, width=width)
python
def resize(self, height, width, **kwargs): """ resize pty within container """ self.client.resize(self.container, height=height, width=width)
[ "def", "resize", "(", "self", ",", "height", ",", "width", ",", "*", "*", "kwargs", ")", ":", "self", ".", "client", ".", "resize", "(", "self", ".", "container", ",", "height", "=", "height", ",", "width", "=", "width", ")" ]
resize pty within container
[ "resize", "pty", "within", "container" ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L193-L197
d11wtq/dockerpty
dockerpty/pty.py
ExecOperation.start
def start(self, sockets=None, **kwargs): """ start execution """ stream = sockets or self.sockets() pumps = [] if self.interactive: pumps.append(io.Pump(io.Stream(self.stdin), stream, wait_for_output=False)) pumps.append(io.Pump(stream, io.Stream(sel...
python
def start(self, sockets=None, **kwargs): """ start execution """ stream = sockets or self.sockets() pumps = [] if self.interactive: pumps.append(io.Pump(io.Stream(self.stdin), stream, wait_for_output=False)) pumps.append(io.Pump(stream, io.Stream(sel...
[ "def", "start", "(", "self", ",", "sockets", "=", "None", ",", "*", "*", "kwargs", ")", ":", "stream", "=", "sockets", "or", "self", ".", "sockets", "(", ")", "pumps", "=", "[", "]", "if", "self", ".", "interactive", ":", "pumps", ".", "append", ...
start execution
[ "start", "execution" ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L227-L242
d11wtq/dockerpty
dockerpty/pty.py
ExecOperation.israw
def israw(self, **kwargs): """ Returns True if the PTY should operate in raw mode. If the exec was not started with tty=True, this will return False. """ if self.raw is None: self.raw = self.stdout.isatty() and self.is_process_tty() return self.raw
python
def israw(self, **kwargs): """ Returns True if the PTY should operate in raw mode. If the exec was not started with tty=True, this will return False. """ if self.raw is None: self.raw = self.stdout.isatty() and self.is_process_tty() return self.raw
[ "def", "israw", "(", "self", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "raw", "is", "None", ":", "self", ".", "raw", "=", "self", ".", "stdout", ".", "isatty", "(", ")", "and", "self", ".", "is_process_tty", "(", ")", "return", "self"...
Returns True if the PTY should operate in raw mode. If the exec was not started with tty=True, this will return False.
[ "Returns", "True", "if", "the", "PTY", "should", "operate", "in", "raw", "mode", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L244-L254
d11wtq/dockerpty
dockerpty/pty.py
ExecOperation.sockets
def sockets(self): """ Return a single socket which is processing all I/O to exec """ socket = self.client.exec_start(self.exec_id, socket=True, tty=self.interactive) stream = io.Stream(socket) if self.is_process_tty(): return stream else: ...
python
def sockets(self): """ Return a single socket which is processing all I/O to exec """ socket = self.client.exec_start(self.exec_id, socket=True, tty=self.interactive) stream = io.Stream(socket) if self.is_process_tty(): return stream else: ...
[ "def", "sockets", "(", "self", ")", ":", "socket", "=", "self", ".", "client", ".", "exec_start", "(", "self", ".", "exec_id", ",", "socket", "=", "True", ",", "tty", "=", "self", ".", "interactive", ")", "stream", "=", "io", ".", "Stream", "(", "s...
Return a single socket which is processing all I/O to exec
[ "Return", "a", "single", "socket", "which", "is", "processing", "all", "I", "/", "O", "to", "exec" ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L256-L265
d11wtq/dockerpty
dockerpty/pty.py
ExecOperation.resize
def resize(self, height, width, **kwargs): """ resize pty of an execed process """ self.client.exec_resize(self.exec_id, height=height, width=width)
python
def resize(self, height, width, **kwargs): """ resize pty of an execed process """ self.client.exec_resize(self.exec_id, height=height, width=width)
[ "def", "resize", "(", "self", ",", "height", ",", "width", ",", "*", "*", "kwargs", ")", ":", "self", ".", "client", ".", "exec_resize", "(", "self", ".", "exec_id", ",", "height", "=", "height", ",", "width", "=", "width", ")" ]
resize pty of an execed process
[ "resize", "pty", "of", "an", "execed", "process" ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L267-L271
d11wtq/dockerpty
dockerpty/pty.py
ExecOperation._exec_info
def _exec_info(self): """ Caching wrapper around client.exec_inspect """ if self._info is None: self._info = self.client.exec_inspect(self.exec_id) return self._info
python
def _exec_info(self): """ Caching wrapper around client.exec_inspect """ if self._info is None: self._info = self.client.exec_inspect(self.exec_id) return self._info
[ "def", "_exec_info", "(", "self", ")", ":", "if", "self", ".", "_info", "is", "None", ":", "self", ".", "_info", "=", "self", ".", "client", ".", "exec_inspect", "(", "self", ".", "exec_id", ")", "return", "self", ".", "_info" ]
Caching wrapper around client.exec_inspect
[ "Caching", "wrapper", "around", "client", ".", "exec_inspect" ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L279-L285
d11wtq/dockerpty
dockerpty/pty.py
PseudoTerminal.resize
def resize(self, size=None): """ Resize the container's PTY. If `size` is not None, it must be a tuple of (height,width), otherwise it will be determined by the size of the current TTY. """ if not self.operation.israw(): return size = size or tty.si...
python
def resize(self, size=None): """ Resize the container's PTY. If `size` is not None, it must be a tuple of (height,width), otherwise it will be determined by the size of the current TTY. """ if not self.operation.israw(): return size = size or tty.si...
[ "def", "resize", "(", "self", ",", "size", "=", "None", ")", ":", "if", "not", "self", ".", "operation", ".", "israw", "(", ")", ":", "return", "size", "=", "size", "or", "tty", ".", "size", "(", "self", ".", "operation", ".", "stdout", ")", "if"...
Resize the container's PTY. If `size` is not None, it must be a tuple of (height,width), otherwise it will be determined by the size of the current TTY.
[ "Resize", "the", "container", "s", "PTY", "." ]
train
https://github.com/d11wtq/dockerpty/blob/f8d17d893c6758b7cc25825e99f6b02202632a97/dockerpty/pty.py#L340-L358
mhe/pynrrd
nrrd/formatters.py
format_number
def format_number(x): """Format number to string Function converts a number to string. For numbers of class :class:`float`, up to 17 digits will be used to print the entire floating point number. Any padding zeros will be removed at the end of the number. See :ref:`user-guide:int` and :ref:`user-guide...
python
def format_number(x): """Format number to string Function converts a number to string. For numbers of class :class:`float`, up to 17 digits will be used to print the entire floating point number. Any padding zeros will be removed at the end of the number. See :ref:`user-guide:int` and :ref:`user-guide...
[ "def", "format_number", "(", "x", ")", ":", "if", "isinstance", "(", "x", ",", "float", ")", ":", "# Helps prevent loss of precision as using str() in Python 2 only prints 12 digits of precision.", "# However, IEEE754-1985 standard says that 17 significant decimal digits is required to...
Format number to string Function converts a number to string. For numbers of class :class:`float`, up to 17 digits will be used to print the entire floating point number. Any padding zeros will be removed at the end of the number. See :ref:`user-guide:int` and :ref:`user-guide:double` for more information...
[ "Format", "number", "to", "string" ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/formatters.py#L4-L38
mhe/pynrrd
nrrd/formatters.py
format_optional_vector
def format_optional_vector(x): """Format a (N,) :class:`numpy.ndarray` into a NRRD optional vector string Function converts a (N,) :class:`numpy.ndarray` or :obj:`None` into a string using NRRD vector format. If the input :obj:`x` is :obj:`None`, then :obj:`vector` will be 'none' See :ref:`user-guide:...
python
def format_optional_vector(x): """Format a (N,) :class:`numpy.ndarray` into a NRRD optional vector string Function converts a (N,) :class:`numpy.ndarray` or :obj:`None` into a string using NRRD vector format. If the input :obj:`x` is :obj:`None`, then :obj:`vector` will be 'none' See :ref:`user-guide:...
[ "def", "format_optional_vector", "(", "x", ")", ":", "# If vector is None or all elements are NaN, then return none", "# Otherwise format the vector as normal", "if", "x", "is", "None", "or", "np", ".", "all", "(", "np", ".", "isnan", "(", "x", ")", ")", ":", "retur...
Format a (N,) :class:`numpy.ndarray` into a NRRD optional vector string Function converts a (N,) :class:`numpy.ndarray` or :obj:`None` into a string using NRRD vector format. If the input :obj:`x` is :obj:`None`, then :obj:`vector` will be 'none' See :ref:`user-guide:int vector` and :ref:`user-guide:doubl...
[ "Format", "a", "(", "N", ")", ":", "class", ":", "numpy", ".", "ndarray", "into", "a", "NRRD", "optional", "vector", "string" ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/formatters.py#L60-L84
mhe/pynrrd
nrrd/writer.py
write
def write(filename, data, header=None, detached_header=False, relative_data_path=True, custom_field_map=None, compression_level=9, index_order='F'): """Write :class:`numpy.ndarray` to NRRD file The :obj:`filename` parameter specifies the absolute or relative filename to write the NRRD file to. If the...
python
def write(filename, data, header=None, detached_header=False, relative_data_path=True, custom_field_map=None, compression_level=9, index_order='F'): """Write :class:`numpy.ndarray` to NRRD file The :obj:`filename` parameter specifies the absolute or relative filename to write the NRRD file to. If the...
[ "def", "write", "(", "filename", ",", "data", ",", "header", "=", "None", ",", "detached_header", "=", "False", ",", "relative_data_path", "=", "True", ",", "custom_field_map", "=", "None", ",", "compression_level", "=", "9", ",", "index_order", "=", "'F'", ...
Write :class:`numpy.ndarray` to NRRD file The :obj:`filename` parameter specifies the absolute or relative filename to write the NRRD file to. If the :obj:`filename` extension is .nhdr, then the :obj:`detached_header` parameter is set to true automatically. If the :obj:`detached_header` parameter is set to...
[ "Write", ":", "class", ":", "numpy", ".", "ndarray", "to", "NRRD", "file" ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/writer.py#L97-L272
mhe/pynrrd
nrrd/parsers.py
parse_vector
def parse_vector(x, dtype=None): """Parse NRRD vector from string into (N,) :class:`numpy.ndarray`. See :ref:`user-guide:int vector` and :ref:`user-guide:double vector` for more information on the format. Parameters ---------- x : :class:`str` String containing NRRD vector dtype : data...
python
def parse_vector(x, dtype=None): """Parse NRRD vector from string into (N,) :class:`numpy.ndarray`. See :ref:`user-guide:int vector` and :ref:`user-guide:double vector` for more information on the format. Parameters ---------- x : :class:`str` String containing NRRD vector dtype : data...
[ "def", "parse_vector", "(", "x", ",", "dtype", "=", "None", ")", ":", "if", "x", "[", "0", "]", "!=", "'('", "or", "x", "[", "-", "1", "]", "!=", "')'", ":", "raise", "NRRDError", "(", "'Vector should be enclosed by parentheses.'", ")", "# Always convert...
Parse NRRD vector from string into (N,) :class:`numpy.ndarray`. See :ref:`user-guide:int vector` and :ref:`user-guide:double vector` for more information on the format. Parameters ---------- x : :class:`str` String containing NRRD vector dtype : data-type, optional Datatype to use ...
[ "Parse", "NRRD", "vector", "from", "string", "into", "(", "N", ")", ":", "class", ":", "numpy", ".", "ndarray", "." ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/parsers.py#L6-L46
mhe/pynrrd
nrrd/parsers.py
parse_matrix
def parse_matrix(x, dtype=None): """Parse NRRD matrix from string into (M,N) :class:`numpy.ndarray`. See :ref:`user-guide:int matrix` and :ref:`user-guide:double matrix` for more information on the format. Parameters ---------- x : :class:`str` String containing NRRD matrix dtype : dat...
python
def parse_matrix(x, dtype=None): """Parse NRRD matrix from string into (M,N) :class:`numpy.ndarray`. See :ref:`user-guide:int matrix` and :ref:`user-guide:double matrix` for more information on the format. Parameters ---------- x : :class:`str` String containing NRRD matrix dtype : dat...
[ "def", "parse_matrix", "(", "x", ",", "dtype", "=", "None", ")", ":", "# Split input by spaces, convert each row into a vector and stack them vertically to get a matrix", "matrix", "=", "[", "parse_vector", "(", "x", ",", "dtype", "=", "float", ")", "for", "x", "in", ...
Parse NRRD matrix from string into (M,N) :class:`numpy.ndarray`. See :ref:`user-guide:int matrix` and :ref:`user-guide:double matrix` for more information on the format. Parameters ---------- x : :class:`str` String containing NRRD matrix dtype : data-type, optional Datatype to use...
[ "Parse", "NRRD", "matrix", "from", "string", "into", "(", "M", "N", ")", ":", "class", ":", "numpy", ".", "ndarray", "." ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/parsers.py#L79-L122
mhe/pynrrd
nrrd/parsers.py
parse_optional_matrix
def parse_optional_matrix(x): """Parse optional NRRD matrix from string into (M,N) :class:`numpy.ndarray` of :class:`float`. Function parses optional NRRD matrix from string into an (M,N) :class:`numpy.ndarray` of :class:`float`. This function works the same as :meth:`parse_matrix` except if a row vector i...
python
def parse_optional_matrix(x): """Parse optional NRRD matrix from string into (M,N) :class:`numpy.ndarray` of :class:`float`. Function parses optional NRRD matrix from string into an (M,N) :class:`numpy.ndarray` of :class:`float`. This function works the same as :meth:`parse_matrix` except if a row vector i...
[ "def", "parse_optional_matrix", "(", "x", ")", ":", "# Split input by spaces to get each row and convert into a vector. The row can be 'none', in which case it will", "# return None", "matrix", "=", "[", "parse_optional_vector", "(", "x", ",", "dtype", "=", "float", ")", "for",...
Parse optional NRRD matrix from string into (M,N) :class:`numpy.ndarray` of :class:`float`. Function parses optional NRRD matrix from string into an (M,N) :class:`numpy.ndarray` of :class:`float`. This function works the same as :meth:`parse_matrix` except if a row vector in the matrix is none, the resulting r...
[ "Parse", "optional", "NRRD", "matrix", "from", "string", "into", "(", "M", "N", ")", ":", "class", ":", "numpy", ".", "ndarray", "of", ":", "class", ":", "float", "." ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/parsers.py#L125-L165
mhe/pynrrd
nrrd/parsers.py
parse_number_list
def parse_number_list(x, dtype=None): """Parse NRRD number list from string into (N,) :class:`numpy.ndarray`. See :ref:`user-guide:int list` and :ref:`user-guide:double list` for more information on the format. Parameters ---------- x : :class:`str` String containing NRRD number list d...
python
def parse_number_list(x, dtype=None): """Parse NRRD number list from string into (N,) :class:`numpy.ndarray`. See :ref:`user-guide:int list` and :ref:`user-guide:double list` for more information on the format. Parameters ---------- x : :class:`str` String containing NRRD number list d...
[ "def", "parse_number_list", "(", "x", ",", "dtype", "=", "None", ")", ":", "# Always convert to float and then perform truncation to integer if necessary", "number_list", "=", "np", ".", "array", "(", "[", "float", "(", "x", ")", "for", "x", "in", "x", ".", "spl...
Parse NRRD number list from string into (N,) :class:`numpy.ndarray`. See :ref:`user-guide:int list` and :ref:`user-guide:double list` for more information on the format. Parameters ---------- x : :class:`str` String containing NRRD number list dtype : data-type, optional Datatype t...
[ "Parse", "NRRD", "number", "list", "from", "string", "into", "(", "N", ")", ":", "class", ":", "numpy", ".", "ndarray", "." ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/parsers.py#L168-L204
mhe/pynrrd
nrrd/parsers.py
parse_number_auto_dtype
def parse_number_auto_dtype(x): """Parse number from string with automatic type detection. Parses input string and converts to a number using automatic type detection. If the number contains any fractional parts, then the number will be converted to float, otherwise the number will be converted to an int. ...
python
def parse_number_auto_dtype(x): """Parse number from string with automatic type detection. Parses input string and converts to a number using automatic type detection. If the number contains any fractional parts, then the number will be converted to float, otherwise the number will be converted to an int. ...
[ "def", "parse_number_auto_dtype", "(", "x", ")", ":", "value", "=", "float", "(", "x", ")", "if", "value", ".", "is_integer", "(", ")", ":", "value", "=", "int", "(", "value", ")", "return", "value" ]
Parse number from string with automatic type detection. Parses input string and converts to a number using automatic type detection. If the number contains any fractional parts, then the number will be converted to float, otherwise the number will be converted to an int. See :ref:`user-guide:int` and :ref...
[ "Parse", "number", "from", "string", "with", "automatic", "type", "detection", "." ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/parsers.py#L207-L231
mhe/pynrrd
nrrd/reader.py
_determine_datatype
def _determine_datatype(fields): """Determine the numpy dtype of the data.""" # Convert the NRRD type string identifier into a NumPy string identifier using a map np_typestring = _TYPEMAP_NRRD2NUMPY[fields['type']] # This is only added if the datatype has more than one byte and is not using ASCII enco...
python
def _determine_datatype(fields): """Determine the numpy dtype of the data.""" # Convert the NRRD type string identifier into a NumPy string identifier using a map np_typestring = _TYPEMAP_NRRD2NUMPY[fields['type']] # This is only added if the datatype has more than one byte and is not using ASCII enco...
[ "def", "_determine_datatype", "(", "fields", ")", ":", "# Convert the NRRD type string identifier into a NumPy string identifier using a map", "np_typestring", "=", "_TYPEMAP_NRRD2NUMPY", "[", "fields", "[", "'type'", "]", "]", "# This is only added if the datatype has more than one ...
Determine the numpy dtype of the data.
[ "Determine", "the", "numpy", "dtype", "of", "the", "data", "." ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/reader.py#L145-L163
mhe/pynrrd
nrrd/reader.py
_validate_magic_line
def _validate_magic_line(line): """For NRRD files, the first four characters are always "NRRD", and remaining characters give information about the file format version >>> _validate_magic_line('NRRD0005') 8 >>> _validate_magic_line('NRRD0006') Traceback (most recent call last): ... ...
python
def _validate_magic_line(line): """For NRRD files, the first four characters are always "NRRD", and remaining characters give information about the file format version >>> _validate_magic_line('NRRD0005') 8 >>> _validate_magic_line('NRRD0006') Traceback (most recent call last): ... ...
[ "def", "_validate_magic_line", "(", "line", ")", ":", "if", "not", "line", ".", "startswith", "(", "'NRRD'", ")", ":", "raise", "NRRDError", "(", "'Invalid NRRD magic line. Is this an NRRD file?'", ")", "try", ":", "version", "=", "int", "(", "line", "[", "4",...
For NRRD files, the first four characters are always "NRRD", and remaining characters give information about the file format version >>> _validate_magic_line('NRRD0005') 8 >>> _validate_magic_line('NRRD0006') Traceback (most recent call last): ... NrrdError: NRRD file version too new fo...
[ "For", "NRRD", "files", "the", "first", "four", "characters", "are", "always", "NRRD", "and", "remaining", "characters", "give", "information", "about", "the", "file", "format", "version" ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/reader.py#L166-L193
mhe/pynrrd
nrrd/reader.py
read_header
def read_header(file, custom_field_map=None): """Read contents of header and parse values from :obj:`file` :obj:`file` can be a filename indicating where the NRRD header is located or a string iterator object. If a filename is specified, then the file will be opened and closed after the header is read from...
python
def read_header(file, custom_field_map=None): """Read contents of header and parse values from :obj:`file` :obj:`file` can be a filename indicating where the NRRD header is located or a string iterator object. If a filename is specified, then the file will be opened and closed after the header is read from...
[ "def", "read_header", "(", "file", ",", "custom_field_map", "=", "None", ")", ":", "# If the file is a filename rather than the file handle, then open the file and call this function again with the", "# file handle. Since read function uses a filename, it is easy to think read_header is the sa...
Read contents of header and parse values from :obj:`file` :obj:`file` can be a filename indicating where the NRRD header is located or a string iterator object. If a filename is specified, then the file will be opened and closed after the header is read from it. If not specifying a filename, the :obj:`file...
[ "Read", "contents", "of", "header", "and", "parse", "values", "from", ":", "obj", ":", "file" ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/reader.py#L196-L298
mhe/pynrrd
nrrd/reader.py
read_data
def read_data(header, fh=None, filename=None, index_order='F'): """Read data from file into :class:`numpy.ndarray` The two parameters :obj:`fh` and :obj:`filename` are optional depending on the parameters but it never hurts to specify both. The file handle (:obj:`fh`) is necessary if the header is attached...
python
def read_data(header, fh=None, filename=None, index_order='F'): """Read data from file into :class:`numpy.ndarray` The two parameters :obj:`fh` and :obj:`filename` are optional depending on the parameters but it never hurts to specify both. The file handle (:obj:`fh`) is necessary if the header is attached...
[ "def", "read_data", "(", "header", ",", "fh", "=", "None", ",", "filename", "=", "None", ",", "index_order", "=", "'F'", ")", ":", "if", "index_order", "not", "in", "[", "'F'", ",", "'C'", "]", ":", "raise", "NRRDError", "(", "'Invalid index order'", "...
Read data from file into :class:`numpy.ndarray` The two parameters :obj:`fh` and :obj:`filename` are optional depending on the parameters but it never hurts to specify both. The file handle (:obj:`fh`) is necessary if the header is attached with the NRRD data. However, if the NRRD data is detached from the...
[ "Read", "data", "from", "file", "into", ":", "class", ":", "numpy", ".", "ndarray" ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/reader.py#L301-L466
mhe/pynrrd
nrrd/reader.py
read
def read(filename, custom_field_map=None, index_order='F'): """Read a NRRD file and return the header and data See :ref:`user-guide:Reading NRRD files` for more information on reading NRRD files. .. note:: Users should be aware that the `index_order` argument needs to be consistent between `nr...
python
def read(filename, custom_field_map=None, index_order='F'): """Read a NRRD file and return the header and data See :ref:`user-guide:Reading NRRD files` for more information on reading NRRD files. .. note:: Users should be aware that the `index_order` argument needs to be consistent between `nr...
[ "def", "read", "(", "filename", ",", "custom_field_map", "=", "None", ",", "index_order", "=", "'F'", ")", ":", "\"\"\"Read a NRRD file and return a tuple (data, header).\"\"\"", "with", "open", "(", "filename", ",", "'rb'", ")", "as", "fh", ":", "header", "=", ...
Read a NRRD file and return the header and data See :ref:`user-guide:Reading NRRD files` for more information on reading NRRD files. .. note:: Users should be aware that the `index_order` argument needs to be consistent between `nrrd.read` and `nrrd.write`. I.e., reading an array with `index_order...
[ "Read", "a", "NRRD", "file", "and", "return", "the", "header", "and", "data" ]
train
https://github.com/mhe/pynrrd/blob/96dd875b302031ea27e2d3aaa611dc6f2dfc7979/nrrd/reader.py#L469-L506
bspaans/python-mingus
mingus/core/meter.py
valid_beat_duration
def valid_beat_duration(duration): """Return True when log2(duration) is an integer.""" if duration == 0: return False elif duration == 1: return True else: r = duration while r != 1: if r % 2 == 1: return False r /= 2 retur...
python
def valid_beat_duration(duration): """Return True when log2(duration) is an integer.""" if duration == 0: return False elif duration == 1: return True else: r = duration while r != 1: if r % 2 == 1: return False r /= 2 retur...
[ "def", "valid_beat_duration", "(", "duration", ")", ":", "if", "duration", "==", "0", ":", "return", "False", "elif", "duration", "==", "1", ":", "return", "True", "else", ":", "r", "=", "duration", "while", "r", "!=", "1", ":", "if", "r", "%", "2", ...
Return True when log2(duration) is an integer.
[ "Return", "True", "when", "log2", "(", "duration", ")", "is", "an", "integer", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/meter.py#L30-L42
bspaans/python-mingus
mingus/containers/track.py
Track.add_notes
def add_notes(self, note, duration=None): """Add a Note, note as string or NoteContainer to the last Bar. If the Bar is full, a new one will automatically be created. If the Bar is not full but the note can't fit in, this method will return False. True otherwise. An Instrument...
python
def add_notes(self, note, duration=None): """Add a Note, note as string or NoteContainer to the last Bar. If the Bar is full, a new one will automatically be created. If the Bar is not full but the note can't fit in, this method will return False. True otherwise. An Instrument...
[ "def", "add_notes", "(", "self", ",", "note", ",", "duration", "=", "None", ")", ":", "if", "self", ".", "instrument", "!=", "None", ":", "if", "not", "self", ".", "instrument", ".", "can_play_notes", "(", "note", ")", ":", "raise", "InstrumentRangeError...
Add a Note, note as string or NoteContainer to the last Bar. If the Bar is full, a new one will automatically be created. If the Bar is not full but the note can't fit in, this method will return False. True otherwise. An InstrumentRangeError exception will be raised if an Instrument ...
[ "Add", "a", "Note", "note", "as", "string", "or", "NoteContainer", "to", "the", "last", "Bar", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/track.py#L51-L80
bspaans/python-mingus
mingus/containers/track.py
Track.get_notes
def get_notes(self): """Return an iterator that iterates through every bar in the this track.""" for bar in self.bars: for beat, duration, notes in bar: yield beat, duration, notes
python
def get_notes(self): """Return an iterator that iterates through every bar in the this track.""" for bar in self.bars: for beat, duration, notes in bar: yield beat, duration, notes
[ "def", "get_notes", "(", "self", ")", ":", "for", "bar", "in", "self", ".", "bars", ":", "for", "beat", ",", "duration", ",", "notes", "in", "bar", ":", "yield", "beat", ",", "duration", ",", "notes" ]
Return an iterator that iterates through every bar in the this track.
[ "Return", "an", "iterator", "that", "iterates", "through", "every", "bar", "in", "the", "this", "track", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/track.py#L82-L87
bspaans/python-mingus
mingus/containers/track.py
Track.from_chords
def from_chords(self, chords, duration=1): """Add chords to the Track. The given chords should be a list of shorthand strings or list of list of shorthand strings, etc. Each sublist divides the value by 2. If a tuning is set, chords will be expanded so they have a proper ...
python
def from_chords(self, chords, duration=1): """Add chords to the Track. The given chords should be a list of shorthand strings or list of list of shorthand strings, etc. Each sublist divides the value by 2. If a tuning is set, chords will be expanded so they have a proper ...
[ "def", "from_chords", "(", "self", ",", "chords", ",", "duration", "=", "1", ")", ":", "tun", "=", "self", ".", "get_tuning", "(", ")", "def", "add_chord", "(", "chord", ",", "duration", ")", ":", "if", "type", "(", "chord", ")", "==", "list", ":",...
Add chords to the Track. The given chords should be a list of shorthand strings or list of list of shorthand strings, etc. Each sublist divides the value by 2. If a tuning is set, chords will be expanded so they have a proper fingering. Example: >>> t = Track(...
[ "Add", "chords", "to", "the", "Track", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/track.py#L89-L127
bspaans/python-mingus
mingus/containers/track.py
Track.get_tuning
def get_tuning(self): """Return a StringTuning object. If an instrument is set and has a tuning it will be returned. Otherwise the track's one will be used. """ if self.instrument and self.instrument.tuning: return self.instrument.tuning return self.tuning
python
def get_tuning(self): """Return a StringTuning object. If an instrument is set and has a tuning it will be returned. Otherwise the track's one will be used. """ if self.instrument and self.instrument.tuning: return self.instrument.tuning return self.tuning
[ "def", "get_tuning", "(", "self", ")", ":", "if", "self", ".", "instrument", "and", "self", ".", "instrument", ".", "tuning", ":", "return", "self", ".", "instrument", ".", "tuning", "return", "self", ".", "tuning" ]
Return a StringTuning object. If an instrument is set and has a tuning it will be returned. Otherwise the track's one will be used.
[ "Return", "a", "StringTuning", "object", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/track.py#L129-L137
bspaans/python-mingus
mingus/containers/track.py
Track.set_tuning
def set_tuning(self, tuning): """Set the tuning attribute on both the Track and its instrument (when available). Tuning should be a StringTuning or derivative object. """ if self.instrument: self.instrument.tuning = tuning self.tuning = tuning return ...
python
def set_tuning(self, tuning): """Set the tuning attribute on both the Track and its instrument (when available). Tuning should be a StringTuning or derivative object. """ if self.instrument: self.instrument.tuning = tuning self.tuning = tuning return ...
[ "def", "set_tuning", "(", "self", ",", "tuning", ")", ":", "if", "self", ".", "instrument", ":", "self", ".", "instrument", ".", "tuning", "=", "tuning", "self", ".", "tuning", "=", "tuning", "return", "self" ]
Set the tuning attribute on both the Track and its instrument (when available). Tuning should be a StringTuning or derivative object.
[ "Set", "the", "tuning", "attribute", "on", "both", "the", "Track", "and", "its", "instrument", "(", "when", "available", ")", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/track.py#L139-L148
bspaans/python-mingus
mingus/containers/track.py
Track.transpose
def transpose(self, interval, up=True): """Transpose all the notes in the track up or down the interval. Call transpose() on every Bar. """ for bar in self.bars: bar.transpose(interval, up) return self
python
def transpose(self, interval, up=True): """Transpose all the notes in the track up or down the interval. Call transpose() on every Bar. """ for bar in self.bars: bar.transpose(interval, up) return self
[ "def", "transpose", "(", "self", ",", "interval", ",", "up", "=", "True", ")", ":", "for", "bar", "in", "self", ".", "bars", ":", "bar", ".", "transpose", "(", "interval", ",", "up", ")", "return", "self" ]
Transpose all the notes in the track up or down the interval. Call transpose() on every Bar.
[ "Transpose", "all", "the", "notes", "in", "the", "track", "up", "or", "down", "the", "interval", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/track.py#L150-L157
bspaans/python-mingus
mingus/containers/bar.py
Bar.set_meter
def set_meter(self, meter): """Set the meter of this bar. Meters in mingus are represented by a single tuple. If the format of the meter is not recognised, a MeterFormatError will be raised. """ # warning should raise exception if _meter.valid_beat_duration(mete...
python
def set_meter(self, meter): """Set the meter of this bar. Meters in mingus are represented by a single tuple. If the format of the meter is not recognised, a MeterFormatError will be raised. """ # warning should raise exception if _meter.valid_beat_duration(mete...
[ "def", "set_meter", "(", "self", ",", "meter", ")", ":", "# warning should raise exception", "if", "_meter", ".", "valid_beat_duration", "(", "meter", "[", "1", "]", ")", ":", "self", ".", "meter", "=", "(", "meter", "[", "0", "]", ",", "meter", "[", "...
Set the meter of this bar. Meters in mingus are represented by a single tuple. If the format of the meter is not recognised, a MeterFormatError will be raised.
[ "Set", "the", "meter", "of", "this", "bar", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L54-L72
bspaans/python-mingus
mingus/containers/bar.py
Bar.place_notes
def place_notes(self, notes, duration): """Place the notes on the current_beat. Notes can be strings, Notes, list of strings, list of Notes or a NoteContainer. Raise a MeterFormatError if the duration is not valid. Return True if succesful, False otherwise (ie. the Bar hasn't ...
python
def place_notes(self, notes, duration): """Place the notes on the current_beat. Notes can be strings, Notes, list of strings, list of Notes or a NoteContainer. Raise a MeterFormatError if the duration is not valid. Return True if succesful, False otherwise (ie. the Bar hasn't ...
[ "def", "place_notes", "(", "self", ",", "notes", ",", "duration", ")", ":", "# note should be able to be one of strings, lists, Notes or", "# NoteContainers", "if", "hasattr", "(", "notes", ",", "'notes'", ")", ":", "pass", "elif", "hasattr", "(", "notes", ",", "'...
Place the notes on the current_beat. Notes can be strings, Notes, list of strings, list of Notes or a NoteContainer. Raise a MeterFormatError if the duration is not valid. Return True if succesful, False otherwise (ie. the Bar hasn't got enough room for a note of that duration...
[ "Place", "the", "notes", "on", "the", "current_beat", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L74-L101
bspaans/python-mingus
mingus/containers/bar.py
Bar.place_notes_at
def place_notes_at(self, notes, at): """Place notes at the given index.""" for x in self.bar: if x[0] == at: x[0][2] += notes
python
def place_notes_at(self, notes, at): """Place notes at the given index.""" for x in self.bar: if x[0] == at: x[0][2] += notes
[ "def", "place_notes_at", "(", "self", ",", "notes", ",", "at", ")", ":", "for", "x", "in", "self", ".", "bar", ":", "if", "x", "[", "0", "]", "==", "at", ":", "x", "[", "0", "]", "[", "2", "]", "+=", "notes" ]
Place notes at the given index.
[ "Place", "notes", "at", "the", "given", "index", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L103-L107
bspaans/python-mingus
mingus/containers/bar.py
Bar.remove_last_entry
def remove_last_entry(self): """Remove the last NoteContainer in the Bar.""" self.current_beat -= 1.0 / self.bar[-1][1] self.bar = self.bar[:-1] return self.current_beat
python
def remove_last_entry(self): """Remove the last NoteContainer in the Bar.""" self.current_beat -= 1.0 / self.bar[-1][1] self.bar = self.bar[:-1] return self.current_beat
[ "def", "remove_last_entry", "(", "self", ")", ":", "self", ".", "current_beat", "-=", "1.0", "/", "self", ".", "bar", "[", "-", "1", "]", "[", "1", "]", "self", ".", "bar", "=", "self", ".", "bar", "[", ":", "-", "1", "]", "return", "self", "."...
Remove the last NoteContainer in the Bar.
[ "Remove", "the", "last", "NoteContainer", "in", "the", "Bar", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L116-L120
bspaans/python-mingus
mingus/containers/bar.py
Bar.is_full
def is_full(self): """Return False if there is room in this Bar for another NoteContainer, True otherwise.""" if self.length == 0.0: return False if len(self.bar) == 0: return False if self.current_beat >= self.length - 0.001: return True ...
python
def is_full(self): """Return False if there is room in this Bar for another NoteContainer, True otherwise.""" if self.length == 0.0: return False if len(self.bar) == 0: return False if self.current_beat >= self.length - 0.001: return True ...
[ "def", "is_full", "(", "self", ")", ":", "if", "self", ".", "length", "==", "0.0", ":", "return", "False", "if", "len", "(", "self", ".", "bar", ")", "==", "0", ":", "return", "False", "if", "self", ".", "current_beat", ">=", "self", ".", "length",...
Return False if there is room in this Bar for another NoteContainer, True otherwise.
[ "Return", "False", "if", "there", "is", "room", "in", "this", "Bar", "for", "another", "NoteContainer", "True", "otherwise", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L122-L131
bspaans/python-mingus
mingus/containers/bar.py
Bar.change_note_duration
def change_note_duration(self, at, to): """Change the note duration at the given index to the given duration.""" if valid_beat_duration(to): diff = 0 for x in self.bar: if diff != 0: x[0][0] -= diff if x[0] == at: ...
python
def change_note_duration(self, at, to): """Change the note duration at the given index to the given duration.""" if valid_beat_duration(to): diff = 0 for x in self.bar: if diff != 0: x[0][0] -= diff if x[0] == at: ...
[ "def", "change_note_duration", "(", "self", ",", "at", ",", "to", ")", ":", "if", "valid_beat_duration", "(", "to", ")", ":", "diff", "=", "0", "for", "x", "in", "self", ".", "bar", ":", "if", "diff", "!=", "0", ":", "x", "[", "0", "]", "[", "0...
Change the note duration at the given index to the given duration.
[ "Change", "the", "note", "duration", "at", "the", "given", "index", "to", "the", "given", "duration", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L133-L144
bspaans/python-mingus
mingus/containers/bar.py
Bar.get_range
def get_range(self): """Return the highest and the lowest note in a tuple.""" (min, max) = (100000, -1) for cont in self.bar: for note in cont[2]: if int(note) < int(min): min = note elif int(note) > int(max): ma...
python
def get_range(self): """Return the highest and the lowest note in a tuple.""" (min, max) = (100000, -1) for cont in self.bar: for note in cont[2]: if int(note) < int(min): min = note elif int(note) > int(max): ma...
[ "def", "get_range", "(", "self", ")", ":", "(", "min", ",", "max", ")", "=", "(", "100000", ",", "-", "1", ")", "for", "cont", "in", "self", ".", "bar", ":", "for", "note", "in", "cont", "[", "2", "]", ":", "if", "int", "(", "note", ")", "<...
Return the highest and the lowest note in a tuple.
[ "Return", "the", "highest", "and", "the", "lowest", "note", "in", "a", "tuple", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L146-L155
bspaans/python-mingus
mingus/containers/bar.py
Bar.transpose
def transpose(self, interval, up=True): """Transpose the notes in the bar up or down the interval. Call transpose() on all NoteContainers in the bar. """ for cont in self.bar: cont[2].transpose(interval, up)
python
def transpose(self, interval, up=True): """Transpose the notes in the bar up or down the interval. Call transpose() on all NoteContainers in the bar. """ for cont in self.bar: cont[2].transpose(interval, up)
[ "def", "transpose", "(", "self", ",", "interval", ",", "up", "=", "True", ")", ":", "for", "cont", "in", "self", ".", "bar", ":", "cont", "[", "2", "]", ".", "transpose", "(", "interval", ",", "up", ")" ]
Transpose the notes in the bar up or down the interval. Call transpose() on all NoteContainers in the bar.
[ "Transpose", "the", "notes", "in", "the", "bar", "up", "or", "down", "the", "interval", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L175-L181
bspaans/python-mingus
mingus/containers/bar.py
Bar.determine_chords
def determine_chords(self, shorthand=False): """Return a list of lists [place_in_beat, possible_chords].""" chords = [] for x in self.bar: chords.append([x[0], x[2].determine(shorthand)]) return chords
python
def determine_chords(self, shorthand=False): """Return a list of lists [place_in_beat, possible_chords].""" chords = [] for x in self.bar: chords.append([x[0], x[2].determine(shorthand)]) return chords
[ "def", "determine_chords", "(", "self", ",", "shorthand", "=", "False", ")", ":", "chords", "=", "[", "]", "for", "x", "in", "self", ".", "bar", ":", "chords", ".", "append", "(", "[", "x", "[", "0", "]", ",", "x", "[", "2", "]", ".", "determin...
Return a list of lists [place_in_beat, possible_chords].
[ "Return", "a", "list", "of", "lists", "[", "place_in_beat", "possible_chords", "]", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L183-L188
bspaans/python-mingus
mingus/containers/bar.py
Bar.determine_progression
def determine_progression(self, shorthand=False): """Return a list of lists [place_in_beat, possible_progressions].""" res = [] for x in self.bar: res.append([x[0], progressions.determine(x[2].get_note_names(), self.key.key, shorthand)]) return res
python
def determine_progression(self, shorthand=False): """Return a list of lists [place_in_beat, possible_progressions].""" res = [] for x in self.bar: res.append([x[0], progressions.determine(x[2].get_note_names(), self.key.key, shorthand)]) return res
[ "def", "determine_progression", "(", "self", ",", "shorthand", "=", "False", ")", ":", "res", "=", "[", "]", "for", "x", "in", "self", ".", "bar", ":", "res", ".", "append", "(", "[", "x", "[", "0", "]", ",", "progressions", ".", "determine", "(", ...
Return a list of lists [place_in_beat, possible_progressions].
[ "Return", "a", "list", "of", "lists", "[", "place_in_beat", "possible_progressions", "]", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L190-L196
bspaans/python-mingus
mingus/containers/bar.py
Bar.get_note_names
def get_note_names(self): """Return a list of unique note names in the Bar.""" res = [] for cont in self.bar: for x in cont[2].get_note_names(): if x not in res: res.append(x) return res
python
def get_note_names(self): """Return a list of unique note names in the Bar.""" res = [] for cont in self.bar: for x in cont[2].get_note_names(): if x not in res: res.append(x) return res
[ "def", "get_note_names", "(", "self", ")", ":", "res", "=", "[", "]", "for", "cont", "in", "self", ".", "bar", ":", "for", "x", "in", "cont", "[", "2", "]", ".", "get_note_names", "(", ")", ":", "if", "x", "not", "in", "res", ":", "res", ".", ...
Return a list of unique note names in the Bar.
[ "Return", "a", "list", "of", "unique", "note", "names", "in", "the", "Bar", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/bar.py#L198-L205
bspaans/python-mingus
mingus/midi/midi_file_in.py
MidiFile.parse_midi_file_header
def parse_midi_file_header(self, fp): """Read the header of a MIDI file and return a tuple containing the format type, number of tracks and parsed time division information.""" # Check header try: if fp.read(4) != 'MThd': raise HeaderError('Not a valid MIDI fi...
python
def parse_midi_file_header(self, fp): """Read the header of a MIDI file and return a tuple containing the format type, number of tracks and parsed time division information.""" # Check header try: if fp.read(4) != 'MThd': raise HeaderError('Not a valid MIDI fi...
[ "def", "parse_midi_file_header", "(", "self", ",", "fp", ")", ":", "# Check header", "try", ":", "if", "fp", ".", "read", "(", "4", ")", "!=", "'MThd'", ":", "raise", "HeaderError", "(", "'Not a valid MIDI file header. Byte %d.'", "%", "self", ".", "bytes_read...
Read the header of a MIDI file and return a tuple containing the format type, number of tracks and parsed time division information.
[ "Read", "the", "header", "of", "a", "MIDI", "file", "and", "return", "a", "tuple", "containing", "the", "format", "type", "number", "of", "tracks", "and", "parsed", "time", "division", "information", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/midi_file_in.py#L171-L215
bspaans/python-mingus
mingus/midi/midi_file_in.py
MidiFile.parse_time_division
def parse_time_division(self, bytes): """Parse the time division found in the header of a MIDI file and return a dictionary with the boolean fps set to indicate whether to use frames per second or ticks per beat. If fps is True, the values SMPTE_frames and clock_ticks will also be ...
python
def parse_time_division(self, bytes): """Parse the time division found in the header of a MIDI file and return a dictionary with the boolean fps set to indicate whether to use frames per second or ticks per beat. If fps is True, the values SMPTE_frames and clock_ticks will also be ...
[ "def", "parse_time_division", "(", "self", ",", "bytes", ")", ":", "# If highest bit is set, time division is set in frames per second", "# otherwise in ticks_per_beat", "value", "=", "self", ".", "bytes_to_int", "(", "bytes", ")", "if", "not", "value", "&", "0x8000", "...
Parse the time division found in the header of a MIDI file and return a dictionary with the boolean fps set to indicate whether to use frames per second or ticks per beat. If fps is True, the values SMPTE_frames and clock_ticks will also be set. If fps is False, ticks_per_beat will hold...
[ "Parse", "the", "time", "division", "found", "in", "the", "header", "of", "a", "MIDI", "file", "and", "return", "a", "dictionary", "with", "the", "boolean", "fps", "set", "to", "indicate", "whether", "to", "use", "frames", "per", "second", "or", "ticks", ...
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/midi_file_in.py#L220-L241
bspaans/python-mingus
mingus/midi/midi_file_in.py
MidiFile.parse_track
def parse_track(self, fp): """Parse a MIDI track from its header to its events. Return a list of events and the number of bytes that were read. """ events = [] chunk_size = self.parse_track_header(fp) bytes = chunk_size while chunk_size > 0: (delta_ti...
python
def parse_track(self, fp): """Parse a MIDI track from its header to its events. Return a list of events and the number of bytes that were read. """ events = [] chunk_size = self.parse_track_header(fp) bytes = chunk_size while chunk_size > 0: (delta_ti...
[ "def", "parse_track", "(", "self", ",", "fp", ")", ":", "events", "=", "[", "]", "chunk_size", "=", "self", ".", "parse_track_header", "(", "fp", ")", "bytes", "=", "chunk_size", "while", "chunk_size", ">", "0", ":", "(", "delta_time", ",", "chunk_delta"...
Parse a MIDI track from its header to its events. Return a list of events and the number of bytes that were read.
[ "Parse", "a", "MIDI", "track", "from", "its", "header", "to", "its", "events", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/midi_file_in.py#L243-L259
bspaans/python-mingus
mingus/midi/midi_file_in.py
MidiFile.parse_midi_event
def parse_midi_event(self, fp): """Parse a MIDI event. Return a dictionary and the number of bytes read. """ chunk_size = 0 try: ec = self.bytes_to_int(fp.read(1)) chunk_size += 1 self.bytes_read += 1 except: raise IOError(...
python
def parse_midi_event(self, fp): """Parse a MIDI event. Return a dictionary and the number of bytes read. """ chunk_size = 0 try: ec = self.bytes_to_int(fp.read(1)) chunk_size += 1 self.bytes_read += 1 except: raise IOError(...
[ "def", "parse_midi_event", "(", "self", ",", "fp", ")", ":", "chunk_size", "=", "0", "try", ":", "ec", "=", "self", ".", "bytes_to_int", "(", "fp", ".", "read", "(", "1", ")", ")", "chunk_size", "+=", "1", "self", ".", "bytes_read", "+=", "1", "exc...
Parse a MIDI event. Return a dictionary and the number of bytes read.
[ "Parse", "a", "MIDI", "event", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/midi_file_in.py#L261-L320
bspaans/python-mingus
mingus/midi/midi_file_in.py
MidiFile.parse_track_header
def parse_track_header(self, fp): """Return the size of the track chunk.""" # Check the header try: h = fp.read(4) self.bytes_read += 4 except: raise IOError("Couldn't read track header from file. Byte %d." % self.bytes_read) ...
python
def parse_track_header(self, fp): """Return the size of the track chunk.""" # Check the header try: h = fp.read(4) self.bytes_read += 4 except: raise IOError("Couldn't read track header from file. Byte %d." % self.bytes_read) ...
[ "def", "parse_track_header", "(", "self", ",", "fp", ")", ":", "# Check the header", "try", ":", "h", "=", "fp", ".", "read", "(", "4", ")", "self", ".", "bytes_read", "+=", "4", "except", ":", "raise", "IOError", "(", "\"Couldn't read track header from file...
Return the size of the track chunk.
[ "Return", "the", "size", "of", "the", "track", "chunk", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/midi_file_in.py#L322-L342
bspaans/python-mingus
mingus/midi/midi_file_in.py
MidiFile.parse_midi_file
def parse_midi_file(self, file): """Parse a MIDI file. Return the header -as a tuple containing respectively the MIDI format, the number of tracks and the time division-, the parsed track data and the number of bytes read. """ try: f = open(file, 'r') ...
python
def parse_midi_file(self, file): """Parse a MIDI file. Return the header -as a tuple containing respectively the MIDI format, the number of tracks and the time division-, the parsed track data and the number of bytes read. """ try: f = open(file, 'r') ...
[ "def", "parse_midi_file", "(", "self", ",", "file", ")", ":", "try", ":", "f", "=", "open", "(", "file", ",", "'r'", ")", "except", ":", "raise", "IOError", "(", "'File not found'", ")", "self", ".", "bytes_read", "=", "0", "header", "=", "self", "."...
Parse a MIDI file. Return the header -as a tuple containing respectively the MIDI format, the number of tracks and the time division-, the parsed track data and the number of bytes read.
[ "Parse", "a", "MIDI", "file", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/midi_file_in.py#L344-L364
bspaans/python-mingus
mingus/midi/midi_file_in.py
MidiFile.parse_varbyte_as_int
def parse_varbyte_as_int(self, fp, return_bytes_read=True): """Read a variable length byte from the file and return the corresponding integer.""" result = 0 bytes_read = 0 r = 0x80 while r & 0x80: try: r = self.bytes_to_int(fp.read(1)) ...
python
def parse_varbyte_as_int(self, fp, return_bytes_read=True): """Read a variable length byte from the file and return the corresponding integer.""" result = 0 bytes_read = 0 r = 0x80 while r & 0x80: try: r = self.bytes_to_int(fp.read(1)) ...
[ "def", "parse_varbyte_as_int", "(", "self", ",", "fp", ",", "return_bytes_read", "=", "True", ")", ":", "result", "=", "0", "bytes_read", "=", "0", "r", "=", "0x80", "while", "r", "&", "0x80", ":", "try", ":", "r", "=", "self", ".", "bytes_to_int", "...
Read a variable length byte from the file and return the corresponding integer.
[ "Read", "a", "variable", "length", "byte", "from", "the", "file", "and", "return", "the", "corresponding", "integer", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/midi_file_in.py#L366-L386
bspaans/python-mingus
mingus/containers/note.py
Note.set_note
def set_note(self, name='C', octave=4, dynamics={}): """Set the note to name in octave with dynamics. Return the objects if it succeeded, raise an NoteFormatError otherwise. """ dash_index = name.split('-') if len(dash_index) == 1: if notes.is_valid_note(name...
python
def set_note(self, name='C', octave=4, dynamics={}): """Set the note to name in octave with dynamics. Return the objects if it succeeded, raise an NoteFormatError otherwise. """ dash_index = name.split('-') if len(dash_index) == 1: if notes.is_valid_note(name...
[ "def", "set_note", "(", "self", ",", "name", "=", "'C'", ",", "octave", "=", "4", ",", "dynamics", "=", "{", "}", ")", ":", "dash_index", "=", "name", ".", "split", "(", "'-'", ")", "if", "len", "(", "dash_index", ")", "==", "1", ":", "if", "no...
Set the note to name in octave with dynamics. Return the objects if it succeeded, raise an NoteFormatError otherwise.
[ "Set", "the", "note", "to", "name", "in", "octave", "with", "dynamics", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/note.py#L70-L95
bspaans/python-mingus
mingus/containers/note.py
Note.change_octave
def change_octave(self, diff): """Change the octave of the note to the current octave + diff.""" self.octave += diff if self.octave < 0: self.octave = 0
python
def change_octave(self, diff): """Change the octave of the note to the current octave + diff.""" self.octave += diff if self.octave < 0: self.octave = 0
[ "def", "change_octave", "(", "self", ",", "diff", ")", ":", "self", ".", "octave", "+=", "diff", "if", "self", ".", "octave", "<", "0", ":", "self", ".", "octave", "=", "0" ]
Change the octave of the note to the current octave + diff.
[ "Change", "the", "octave", "of", "the", "note", "to", "the", "current", "octave", "+", "diff", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/note.py#L111-L115
bspaans/python-mingus
mingus/containers/note.py
Note.transpose
def transpose(self, interval, up=True): """Transpose the note up or down the interval. Examples: >>> a = Note('A') >>> a.transpose('3') >>> a 'C#-5' >>> a.transpose('3', False) >>> a 'A-4' """ (old, o_octave) = (self.name, self.oct...
python
def transpose(self, interval, up=True): """Transpose the note up or down the interval. Examples: >>> a = Note('A') >>> a.transpose('3') >>> a 'C#-5' >>> a.transpose('3', False) >>> a 'A-4' """ (old, o_octave) = (self.name, self.oct...
[ "def", "transpose", "(", "self", ",", "interval", ",", "up", "=", "True", ")", ":", "(", "old", ",", "o_octave", ")", "=", "(", "self", ".", "name", ",", "self", ".", "octave", ")", "self", ".", "name", "=", "intervals", ".", "from_shorthand", "(",...
Transpose the note up or down the interval. Examples: >>> a = Note('A') >>> a.transpose('3') >>> a 'C#-5' >>> a.transpose('3', False) >>> a 'A-4'
[ "Transpose", "the", "note", "up", "or", "down", "the", "interval", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/note.py#L129-L148
bspaans/python-mingus
mingus/containers/note.py
Note.from_int
def from_int(self, integer): """Set the Note corresponding to the integer. 0 is a C on octave 0, 12 is a C on octave 1, etc. Example: >>> Note().from_int(12) 'C-1' """ self.name = notes.int_to_note(integer % 12) self.octave = integer // 12 return...
python
def from_int(self, integer): """Set the Note corresponding to the integer. 0 is a C on octave 0, 12 is a C on octave 1, etc. Example: >>> Note().from_int(12) 'C-1' """ self.name = notes.int_to_note(integer % 12) self.octave = integer // 12 return...
[ "def", "from_int", "(", "self", ",", "integer", ")", ":", "self", ".", "name", "=", "notes", ".", "int_to_note", "(", "integer", "%", "12", ")", "self", ".", "octave", "=", "integer", "//", "12", "return", "self" ]
Set the Note corresponding to the integer. 0 is a C on octave 0, 12 is a C on octave 1, etc. Example: >>> Note().from_int(12) 'C-1'
[ "Set", "the", "Note", "corresponding", "to", "the", "integer", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/note.py#L150-L161
bspaans/python-mingus
mingus/containers/note.py
Note.from_hertz
def from_hertz(self, hertz, standard_pitch=440): """Set the Note name and pitch, calculated from the hertz value. The standard_pitch argument can be used to set the pitch of A-4, from which the rest is calculated. """ value = ((log((float(hertz) * 1024) / standard_pitch, 2) + ...
python
def from_hertz(self, hertz, standard_pitch=440): """Set the Note name and pitch, calculated from the hertz value. The standard_pitch argument can be used to set the pitch of A-4, from which the rest is calculated. """ value = ((log((float(hertz) * 1024) / standard_pitch, 2) + ...
[ "def", "from_hertz", "(", "self", ",", "hertz", ",", "standard_pitch", "=", "440", ")", ":", "value", "=", "(", "(", "log", "(", "(", "float", "(", "hertz", ")", "*", "1024", ")", "/", "standard_pitch", ",", "2", ")", "+", "1.0", "/", "24", ")", ...
Set the Note name and pitch, calculated from the hertz value. The standard_pitch argument can be used to set the pitch of A-4, from which the rest is calculated.
[ "Set", "the", "Note", "name", "and", "pitch", "calculated", "from", "the", "hertz", "value", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/note.py#L184-L194
bspaans/python-mingus
mingus/containers/note.py
Note.to_shorthand
def to_shorthand(self): """Give the traditional Helmhotz pitch notation. Examples: >>> Note('C-4').to_shorthand() "c'" >>> Note('C-3').to_shorthand() 'c' >>> Note('C-2').to_shorthand() 'C' >>> Note('C-1').to_shorthand() 'C,' """ ...
python
def to_shorthand(self): """Give the traditional Helmhotz pitch notation. Examples: >>> Note('C-4').to_shorthand() "c'" >>> Note('C-3').to_shorthand() 'c' >>> Note('C-2').to_shorthand() 'C' >>> Note('C-1').to_shorthand() 'C,' """ ...
[ "def", "to_shorthand", "(", "self", ")", ":", "if", "self", ".", "octave", "<", "3", ":", "res", "=", "self", ".", "name", "else", ":", "res", "=", "str", ".", "lower", "(", "self", ".", "name", ")", "o", "=", "self", ".", "octave", "-", "3", ...
Give the traditional Helmhotz pitch notation. Examples: >>> Note('C-4').to_shorthand() "c'" >>> Note('C-3').to_shorthand() 'c' >>> Note('C-2').to_shorthand() 'C' >>> Note('C-1').to_shorthand() 'C,'
[ "Give", "the", "traditional", "Helmhotz", "pitch", "notation", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/note.py#L196-L220
bspaans/python-mingus
mingus/containers/note.py
Note.from_shorthand
def from_shorthand(self, shorthand): """Convert from traditional Helmhotz pitch notation. Examples: >>> Note().from_shorthand("C,,") 'C-0' >>> Note().from_shorthand("C") 'C-2' >>> Note().from_shorthand("c'") 'C-4' """ name = '' oct...
python
def from_shorthand(self, shorthand): """Convert from traditional Helmhotz pitch notation. Examples: >>> Note().from_shorthand("C,,") 'C-0' >>> Note().from_shorthand("C") 'C-2' >>> Note().from_shorthand("c'") 'C-4' """ name = '' oct...
[ "def", "from_shorthand", "(", "self", ",", "shorthand", ")", ":", "name", "=", "''", "octave", "=", "0", "for", "x", "in", "shorthand", ":", "if", "x", "in", "[", "'a'", ",", "'b'", ",", "'c'", ",", "'d'", ",", "'e'", ",", "'f'", ",", "'g'", "]...
Convert from traditional Helmhotz pitch notation. Examples: >>> Note().from_shorthand("C,,") 'C-0' >>> Note().from_shorthand("C") 'C-2' >>> Note().from_shorthand("c'") 'C-4'
[ "Convert", "from", "traditional", "Helmhotz", "pitch", "notation", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/note.py#L222-L248
bspaans/python-mingus
mingus/core/intervals.py
interval
def interval(key, start_note, interval): """Return the note found at the interval starting from start_note in the given key. Raise a KeyError exception if start_note is not a valid note. Example: >>> interval('C', 'D', 1) 'E' """ if not notes.is_valid_note(start_note): raise Ke...
python
def interval(key, start_note, interval): """Return the note found at the interval starting from start_note in the given key. Raise a KeyError exception if start_note is not a valid note. Example: >>> interval('C', 'D', 1) 'E' """ if not notes.is_valid_note(start_note): raise Ke...
[ "def", "interval", "(", "key", ",", "start_note", ",", "interval", ")", ":", "if", "not", "notes", ".", "is_valid_note", "(", "start_note", ")", ":", "raise", "KeyError", "(", "\"The start note '%s' is not a valid note\"", "%", "start_note", ")", "notes_in_key", ...
Return the note found at the interval starting from start_note in the given key. Raise a KeyError exception if start_note is not a valid note. Example: >>> interval('C', 'D', 1) 'E'
[ "Return", "the", "note", "found", "at", "the", "interval", "starting", "from", "start_note", "in", "the", "given", "key", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/intervals.py#L37-L53
bspaans/python-mingus
mingus/core/intervals.py
get_interval
def get_interval(note, interval, key='C'): """Return the note an interval (in half notes) away from the given note. This will produce mostly theoretical sound results, but you should use the minor and major functions to work around the corner cases. """ intervals = map(lambda x: (notes.note_to_int(...
python
def get_interval(note, interval, key='C'): """Return the note an interval (in half notes) away from the given note. This will produce mostly theoretical sound results, but you should use the minor and major functions to work around the corner cases. """ intervals = map(lambda x: (notes.note_to_int(...
[ "def", "get_interval", "(", "note", ",", "interval", ",", "key", "=", "'C'", ")", ":", "intervals", "=", "map", "(", "lambda", "x", ":", "(", "notes", ".", "note_to_int", "(", "key", ")", "+", "x", ")", "%", "12", ",", "[", "0", ",", "2", ",", ...
Return the note an interval (in half notes) away from the given note. This will produce mostly theoretical sound results, but you should use the minor and major functions to work around the corner cases.
[ "Return", "the", "note", "an", "interval", "(", "in", "half", "notes", ")", "away", "from", "the", "given", "note", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/intervals.py#L210-L233
bspaans/python-mingus
mingus/core/intervals.py
measure
def measure(note1, note2): """Return an integer in the range of 0-11, determining the half note steps between note1 and note2. Examples: >>> measure('C', 'D') 2 >>> measure('D', 'C') 10 """ res = notes.note_to_int(note2) - notes.note_to_int(note1) if res < 0: return 12 -...
python
def measure(note1, note2): """Return an integer in the range of 0-11, determining the half note steps between note1 and note2. Examples: >>> measure('C', 'D') 2 >>> measure('D', 'C') 10 """ res = notes.note_to_int(note2) - notes.note_to_int(note1) if res < 0: return 12 -...
[ "def", "measure", "(", "note1", ",", "note2", ")", ":", "res", "=", "notes", ".", "note_to_int", "(", "note2", ")", "-", "notes", ".", "note_to_int", "(", "note1", ")", "if", "res", "<", "0", ":", "return", "12", "-", "res", "*", "-", "1", "else"...
Return an integer in the range of 0-11, determining the half note steps between note1 and note2. Examples: >>> measure('C', 'D') 2 >>> measure('D', 'C') 10
[ "Return", "an", "integer", "in", "the", "range", "of", "0", "-", "11", "determining", "the", "half", "note", "steps", "between", "note1", "and", "note2", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/intervals.py#L235-L249
bspaans/python-mingus
mingus/core/intervals.py
augment_or_diminish_until_the_interval_is_right
def augment_or_diminish_until_the_interval_is_right(note1, note2, interval): """A helper function for the minor and major functions. You should probably not use this directly. """ cur = measure(note1, note2) while cur != interval: if cur > interval: note2 = notes.diminish(note2)...
python
def augment_or_diminish_until_the_interval_is_right(note1, note2, interval): """A helper function for the minor and major functions. You should probably not use this directly. """ cur = measure(note1, note2) while cur != interval: if cur > interval: note2 = notes.diminish(note2)...
[ "def", "augment_or_diminish_until_the_interval_is_right", "(", "note1", ",", "note2", ",", "interval", ")", ":", "cur", "=", "measure", "(", "note1", ",", "note2", ")", "while", "cur", "!=", "interval", ":", "if", "cur", ">", "interval", ":", "note2", "=", ...
A helper function for the minor and major functions. You should probably not use this directly.
[ "A", "helper", "function", "for", "the", "minor", "and", "major", "functions", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/intervals.py#L251-L290
bspaans/python-mingus
mingus/core/intervals.py
invert
def invert(interval): """Invert an interval. Example: >>> invert(['C', 'E']) ['E', 'C'] """ interval.reverse() res = list(interval) interval.reverse() return res
python
def invert(interval): """Invert an interval. Example: >>> invert(['C', 'E']) ['E', 'C'] """ interval.reverse() res = list(interval) interval.reverse() return res
[ "def", "invert", "(", "interval", ")", ":", "interval", ".", "reverse", "(", ")", "res", "=", "list", "(", "interval", ")", "interval", ".", "reverse", "(", ")", "return", "res" ]
Invert an interval. Example: >>> invert(['C', 'E']) ['E', 'C']
[ "Invert", "an", "interval", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/intervals.py#L292-L302
bspaans/python-mingus
mingus/core/intervals.py
determine
def determine(note1, note2, shorthand=False): """Name the interval between note1 and note2. Examples: >>> determine('C', 'E') 'major third' >>> determine('C', 'Eb') 'minor third' >>> determine('C', 'E#') 'augmented third' >>> determine('C', 'Ebb') 'diminished third' This wo...
python
def determine(note1, note2, shorthand=False): """Name the interval between note1 and note2. Examples: >>> determine('C', 'E') 'major third' >>> determine('C', 'Eb') 'minor third' >>> determine('C', 'E#') 'augmented third' >>> determine('C', 'Ebb') 'diminished third' This wo...
[ "def", "determine", "(", "note1", ",", "note2", ",", "shorthand", "=", "False", ")", ":", "# Corner case for unisons ('A' and 'Ab', for instance)", "if", "note1", "[", "0", "]", "==", "note2", "[", "0", "]", ":", "def", "get_val", "(", "note", ")", ":", "\...
Name the interval between note1 and note2. Examples: >>> determine('C', 'E') 'major third' >>> determine('C', 'Eb') 'minor third' >>> determine('C', 'E#') 'augmented third' >>> determine('C', 'Ebb') 'diminished third' This works for all intervals. Note that there are corner cas...
[ "Name", "the", "interval", "between", "note1", "and", "note2", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/intervals.py#L304-L408
bspaans/python-mingus
mingus/core/intervals.py
from_shorthand
def from_shorthand(note, interval, up=True): """Return the note on interval up or down. Examples: >>> from_shorthand('A', 'b3') 'C' >>> from_shorthand('D', '2') 'E' >>> from_shorthand('E', '2', False) 'D' """ # warning should be a valid note. if not notes.is_valid_note(note)...
python
def from_shorthand(note, interval, up=True): """Return the note on interval up or down. Examples: >>> from_shorthand('A', 'b3') 'C' >>> from_shorthand('D', '2') 'E' >>> from_shorthand('E', '2', False) 'D' """ # warning should be a valid note. if not notes.is_valid_note(note)...
[ "def", "from_shorthand", "(", "note", ",", "interval", ",", "up", "=", "True", ")", ":", "# warning should be a valid note.", "if", "not", "notes", ".", "is_valid_note", "(", "note", ")", ":", "return", "False", "# [shorthand, interval function up, interval function d...
Return the note on interval up or down. Examples: >>> from_shorthand('A', 'b3') 'C' >>> from_shorthand('D', '2') 'E' >>> from_shorthand('E', '2', False) 'D'
[ "Return", "the", "note", "on", "interval", "up", "or", "down", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/intervals.py#L410-L463
bspaans/python-mingus
mingus/core/intervals.py
is_consonant
def is_consonant(note1, note2, include_fourths=True): """Return True if the interval is consonant. A consonance is a harmony, chord, or interval considered stable, as opposed to a dissonance. This function tests whether the given interval is consonant. This basically means that it checks whether t...
python
def is_consonant(note1, note2, include_fourths=True): """Return True if the interval is consonant. A consonance is a harmony, chord, or interval considered stable, as opposed to a dissonance. This function tests whether the given interval is consonant. This basically means that it checks whether t...
[ "def", "is_consonant", "(", "note1", ",", "note2", ",", "include_fourths", "=", "True", ")", ":", "return", "(", "is_perfect_consonant", "(", "note1", ",", "note2", ",", "include_fourths", ")", "or", "is_imperfect_consonant", "(", "note1", ",", "note2", ")", ...
Return True if the interval is consonant. A consonance is a harmony, chord, or interval considered stable, as opposed to a dissonance. This function tests whether the given interval is consonant. This basically means that it checks whether the interval is (or sounds like) a unison, third, sixth, p...
[ "Return", "True", "if", "the", "interval", "is", "consonant", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/intervals.py#L465-L479
bspaans/python-mingus
mingus/core/intervals.py
is_perfect_consonant
def is_perfect_consonant(note1, note2, include_fourths=True): """Return True if the interval is a perfect consonant one. Perfect consonances are either unisons, perfect fourths or fifths, or octaves (which is the same as a unison in this model). Perfect fourths are usually included as well, but are co...
python
def is_perfect_consonant(note1, note2, include_fourths=True): """Return True if the interval is a perfect consonant one. Perfect consonances are either unisons, perfect fourths or fifths, or octaves (which is the same as a unison in this model). Perfect fourths are usually included as well, but are co...
[ "def", "is_perfect_consonant", "(", "note1", ",", "note2", ",", "include_fourths", "=", "True", ")", ":", "dhalf", "=", "measure", "(", "note1", ",", "note2", ")", "return", "dhalf", "in", "[", "0", ",", "7", "]", "or", "include_fourths", "and", "dhalf",...
Return True if the interval is a perfect consonant one. Perfect consonances are either unisons, perfect fourths or fifths, or octaves (which is the same as a unison in this model). Perfect fourths are usually included as well, but are considered dissonant when used contrapuntal, which is why you can e...
[ "Return", "True", "if", "the", "interval", "is", "a", "perfect", "consonant", "one", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/core/intervals.py#L481-L491
bspaans/python-mingus
mingus/containers/composition.py
Composition.add_track
def add_track(self, track): """Add a track to the composition. Raise an UnexpectedObjectError if the argument is not a mingus.containers.Track object. """ if not hasattr(track, 'bars'): raise UnexpectedObjectError("Unexpected object '%s', " "expec...
python
def add_track(self, track): """Add a track to the composition. Raise an UnexpectedObjectError if the argument is not a mingus.containers.Track object. """ if not hasattr(track, 'bars'): raise UnexpectedObjectError("Unexpected object '%s', " "expec...
[ "def", "add_track", "(", "self", ",", "track", ")", ":", "if", "not", "hasattr", "(", "track", ",", "'bars'", ")", ":", "raise", "UnexpectedObjectError", "(", "\"Unexpected object '%s', \"", "\"expecting a mingus.containers.Track object\"", "%", "track", ")", "self"...
Add a track to the composition. Raise an UnexpectedObjectError if the argument is not a mingus.containers.Track object.
[ "Add", "a", "track", "to", "the", "composition", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/composition.py#L55-L65
bspaans/python-mingus
mingus/containers/composition.py
Composition.add_note
def add_note(self, note): """Add a note to the selected tracks. Everything container.Track supports in __add__ is accepted. """ for n in self.selected_tracks: self.tracks[n] + note
python
def add_note(self, note): """Add a note to the selected tracks. Everything container.Track supports in __add__ is accepted. """ for n in self.selected_tracks: self.tracks[n] + note
[ "def", "add_note", "(", "self", ",", "note", ")", ":", "for", "n", "in", "self", ".", "selected_tracks", ":", "self", ".", "tracks", "[", "n", "]", "+", "note" ]
Add a note to the selected tracks. Everything container.Track supports in __add__ is accepted.
[ "Add", "a", "note", "to", "the", "selected", "tracks", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/containers/composition.py#L67-L73
bspaans/python-mingus
mingus/midi/pyfluidsynth.py
cfunc
def cfunc(name, result, *args): """Build and apply a ctypes prototype complete with parameter flags.""" atypes = [] aflags = [] for arg in args: atypes.append(arg[1]) aflags.append((arg[2], arg[0]) + arg[3:]) return CFUNCTYPE(result, *atypes)((name, _fl), tuple(aflags))
python
def cfunc(name, result, *args): """Build and apply a ctypes prototype complete with parameter flags.""" atypes = [] aflags = [] for arg in args: atypes.append(arg[1]) aflags.append((arg[2], arg[0]) + arg[3:]) return CFUNCTYPE(result, *atypes)((name, _fl), tuple(aflags))
[ "def", "cfunc", "(", "name", ",", "result", ",", "*", "args", ")", ":", "atypes", "=", "[", "]", "aflags", "=", "[", "]", "for", "arg", "in", "args", ":", "atypes", ".", "append", "(", "arg", "[", "1", "]", ")", "aflags", ".", "append", "(", ...
Build and apply a ctypes prototype complete with parameter flags.
[ "Build", "and", "apply", "a", "ctypes", "prototype", "complete", "with", "parameter", "flags", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/pyfluidsynth.py#L41-L48
bspaans/python-mingus
mingus/midi/pyfluidsynth.py
fluid_synth_write_s16_stereo
def fluid_synth_write_s16_stereo(synth, len): """Return generated samples in stereo 16-bit format. Return value is a Numpy array of samples. """ import numpy buf = create_string_buffer(len * 4) fluid_synth_write_s16(synth, len, buf, 0, 2, buf, 1, 2) return numpy.fromstring(buf[:], dtype=num...
python
def fluid_synth_write_s16_stereo(synth, len): """Return generated samples in stereo 16-bit format. Return value is a Numpy array of samples. """ import numpy buf = create_string_buffer(len * 4) fluid_synth_write_s16(synth, len, buf, 0, 2, buf, 1, 2) return numpy.fromstring(buf[:], dtype=num...
[ "def", "fluid_synth_write_s16_stereo", "(", "synth", ",", "len", ")", ":", "import", "numpy", "buf", "=", "create_string_buffer", "(", "len", "*", "4", ")", "fluid_synth_write_s16", "(", "synth", ",", "len", ",", "buf", ",", "0", ",", "2", ",", "buf", ",...
Return generated samples in stereo 16-bit format. Return value is a Numpy array of samples.
[ "Return", "generated", "samples", "in", "stereo", "16", "-", "bit", "format", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/pyfluidsynth.py#L132-L140
bspaans/python-mingus
mingus/midi/pyfluidsynth.py
Synth.start
def start(self, driver=None): """Start audio output driver in separate background thread. Call this function any time after creating the Synth object. If you don't call this function, use get_samples() to generate samples. Optional keyword argument: driver: which audi...
python
def start(self, driver=None): """Start audio output driver in separate background thread. Call this function any time after creating the Synth object. If you don't call this function, use get_samples() to generate samples. Optional keyword argument: driver: which audi...
[ "def", "start", "(", "self", ",", "driver", "=", "None", ")", ":", "if", "driver", "is", "not", "None", ":", "assert", "driver", "in", "[", "'alsa'", ",", "'oss'", ",", "'jack'", ",", "'portaudio'", ",", "'sndmgr'", ",", "'coreaudio'", ",", "'Direct So...
Start audio output driver in separate background thread. Call this function any time after creating the Synth object. If you don't call this function, use get_samples() to generate samples. Optional keyword argument: driver: which audio driver to use for output ...
[ "Start", "audio", "output", "driver", "in", "separate", "background", "thread", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/pyfluidsynth.py#L164-L194
bspaans/python-mingus
mingus/midi/pyfluidsynth.py
Synth.program_select
def program_select(self, chan, sfid, bank, preset): """Select a program.""" return fluid_synth_program_select(self.synth, chan, sfid, bank, preset)
python
def program_select(self, chan, sfid, bank, preset): """Select a program.""" return fluid_synth_program_select(self.synth, chan, sfid, bank, preset)
[ "def", "program_select", "(", "self", ",", "chan", ",", "sfid", ",", "bank", ",", "preset", ")", ":", "return", "fluid_synth_program_select", "(", "self", ".", "synth", ",", "chan", ",", "sfid", ",", "bank", ",", "preset", ")" ]
Select a program.
[ "Select", "a", "program", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/pyfluidsynth.py#L210-L212
bspaans/python-mingus
mingus/midi/pyfluidsynth.py
Synth.noteon
def noteon(self, chan, key, vel): """Play a note.""" if key < 0 or key > 128: return False if chan < 0: return False if vel < 0 or vel > 128: return False return fluid_synth_noteon(self.synth, chan, key, vel)
python
def noteon(self, chan, key, vel): """Play a note.""" if key < 0 or key > 128: return False if chan < 0: return False if vel < 0 or vel > 128: return False return fluid_synth_noteon(self.synth, chan, key, vel)
[ "def", "noteon", "(", "self", ",", "chan", ",", "key", ",", "vel", ")", ":", "if", "key", "<", "0", "or", "key", ">", "128", ":", "return", "False", "if", "chan", "<", "0", ":", "return", "False", "if", "vel", "<", "0", "or", "vel", ">", "128...
Play a note.
[ "Play", "a", "note", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/pyfluidsynth.py#L214-L222
bspaans/python-mingus
mingus/midi/pyfluidsynth.py
Synth.noteoff
def noteoff(self, chan, key): """Stop a note.""" if key < 0 or key > 128: return False if chan < 0: return False return fluid_synth_noteoff(self.synth, chan, key)
python
def noteoff(self, chan, key): """Stop a note.""" if key < 0 or key > 128: return False if chan < 0: return False return fluid_synth_noteoff(self.synth, chan, key)
[ "def", "noteoff", "(", "self", ",", "chan", ",", "key", ")", ":", "if", "key", "<", "0", "or", "key", ">", "128", ":", "return", "False", "if", "chan", "<", "0", ":", "return", "False", "return", "fluid_synth_noteoff", "(", "self", ".", "synth", ",...
Stop a note.
[ "Stop", "a", "note", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/pyfluidsynth.py#L224-L230
bspaans/python-mingus
mingus/midi/pyfluidsynth.py
Synth.cc
def cc(self, chan, ctrl, val): """Send control change value. The controls that are recognized are dependent on the SoundFont. Values are always 0 to 127. Typical controls include: 1: vibrato 7: volume 10: pan (left to right) 11: expression (soft...
python
def cc(self, chan, ctrl, val): """Send control change value. The controls that are recognized are dependent on the SoundFont. Values are always 0 to 127. Typical controls include: 1: vibrato 7: volume 10: pan (left to right) 11: expression (soft...
[ "def", "cc", "(", "self", ",", "chan", ",", "ctrl", ",", "val", ")", ":", "return", "fluid_synth_cc", "(", "self", ".", "synth", ",", "chan", ",", "ctrl", ",", "val", ")" ]
Send control change value. The controls that are recognized are dependent on the SoundFont. Values are always 0 to 127. Typical controls include: 1: vibrato 7: volume 10: pan (left to right) 11: expression (soft to loud) 64: sustain ...
[ "Send", "control", "change", "value", "." ]
train
https://github.com/bspaans/python-mingus/blob/aa5a5d992d45ada61be0f9f86261380731bd7749/mingus/midi/pyfluidsynth.py#L242-L256