Return a :class:`pypianoroll.Multitrack` object loaded from a MIDI
    (.mid, .midi, .MID, .MIDI) file.

    Parameters
    ----------
    filepath : str
        The file path to the MIDI file.
962134
def parse(filepath, beat_resolution=24, name='unknown'):
    
    if not filepath.endswith(('.mid', '.midi', '.MID', '.MIDI')):
        raise ValueError("Only MIDI files are supported")
    return Multitrack(filepath, beat_resolution=beat_resolution, name=name)
711881
def get_handle(self, filepath):
        
        localpath = self._get_localpath(filepath)
        return self._cache[localpath]
138459
function (filePath)
		{
			if (typeof arguments[1]=='function')
				var cb = arguments[1];

			if (typeof arguments[2]=='function')
				var cb = arguments[2];

			var binary = typeof arguments[1]=='boolean' ? arguments[1] : false,
				realPath = this.instanceOf('wnModule')?this.modulePath+filePath:filePath,
				cmd = !cb ? 'readFileSync' : 'readFile';

			try {
				var _cb = cb ? function (err,file) {
					cb&&cb(!err ? ((binary===true) ? file : file.toString()) : false);
				} : null,
				file = fs[cmd](realPath,_cb);
			} catch (e)
			{
				if (_cb)
					cb&&cb(false);
				else
					return false;
			}
			return (file ? (binary===true) ? file : file.toString() : false);
		}
403193
def _read_track(chunk):
    """"""

    TEMPO, MIDI = range(2)

    # Deviations: The running status should be reset on non midi events, but
    # some files contain meta events inbetween.
    # TODO: Offset and time signature are not considered.

    tempos = []
    events = []

    chunk = bytearray(chunk)
    deltasum = 0
    status = 0
    off = 0
    while off < len(chunk):
        delta, off = _var_int(chunk, off)
        deltasum += delta
        event_type = chunk[off]
        off += 1
        if event_type == 0xFF:
            meta_type = chunk[off]
            off += 1
            num, off = _var_int(chunk, off)
            # TODO: support offset/time signature
            if meta_type == 0x51:
                data = chunk[off:off + num]
                if len(data) != 3:
                    raise SMFError
                tempo = struct.unpack(">I", b"\x00" + bytes(data))[0]
                tempos.append((deltasum, TEMPO, tempo))
            off += num
        elif event_type in (0xF0, 0xF7):
            val, off = _var_int(chunk, off)
            off += val
        else:
            if event_type < 0x80:
                # if < 0x80 take the type from the previous midi event
                off += 1
                event_type = status
            elif event_type < 0xF0:
                off += 2
                status = event_type
            else:
                raise SMFError("invalid event")

            if event_type >> 4 in (0xD, 0xC):
                off -= 1

            events.append((deltasum, MIDI, delta))

    return events, tempos
628338
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)
            self.bytes_read += 4
        except:
            raise IOError("Couldn't read from file.")

        # Parse chunk size
        try:
            chunk_size = self.bytes_to_int(fp.read(4))
            self.bytes_read += 4
        except:
            raise IOError("Couldn't read chunk size from file. Byte %d."
                    % self.bytes_read)

        # Expect chunk size to be at least 6
        if chunk_size < 6:
            return False
        try:
            format_type = self.bytes_to_int(fp.read(2))
            self.bytes_read += 2
            if format_type not in [0, 1, 2]:
                raise FormatError('%d is not a valid MIDI format.'
                        % format_type)
        except:
            raise IOError("Couldn't read format type from file.")
        try:
            number_of_tracks = self.bytes_to_int(fp.read(2))
            time_division = self.parse_time_division(fp.read(2))
            self.bytes_read += 4
        except:
            raise IOError("Couldn't read number of tracks "
                    "and/or time division from tracks.")

        chunk_size -= 6
        if chunk_size % 2 == 1:
            raise FormatError("Won't parse this.")
        fp.read(chunk_size / 2)
        self.bytes_read += chunk_size / 2
        return (format_type, number_of_tracks, time_division)
731389
def parse_midi(self, filename, **kwargs):
        
        pm = pretty_midi.PrettyMIDI(filename)
        self.parse_pretty_midi(pm, **kwargs)
391747
def save(self, file_path, note_df):
        '''
        
            
        '''

        chord = pretty_midi.PrettyMIDI()
        for program in note_df.program.drop_duplicates().values.tolist():
            df = note_df[note_df.program == program]
            midi_obj = pretty_midi.Instrument(program=program)
            for i in range(df.shape[0]):
                note = pretty_midi.Note(
                    velocity=int(df.iloc[i, :]["velocity"]),
                    pitch=int(df.iloc[i, :]["pitch"]),
                    start=float(df.iloc[i, :]["start"]), 
                    end=float(df.iloc[i, :]["end"])
                )
                # Add it to our cello instrument
                midi_obj.notes.append(note)
            # Add the cello instrument to the PrettyMIDI object
            chord.instruments.append(midi_obj)
        # Write out the MIDI data
        chord.write(file_path)
307012
def parse_file_path(filepath):
    # type: (pathlib.Path) -> Tuple[str, str, str]
    
    if not isinstance(filepath, pathlib.Path):
        filepath = pathlib.Path(filepath)
    dirname = '/'.join(filepath.parts[:len(filepath.parts) - 1])
    if len(dirname) == 0:
        dirname = None
    if len(filepath.parts) > 0:
        fname = filepath.parts[-1]
    else:
        fname = None
    fname, snapshot = blobxfer.util.parse_fileshare_or_file_snapshot_parameter(
        fname)
    return (dirname, fname, snapshot)
1369820
def from_gpx(file_path):
        
        gpx = gpxpy.parse(open(file_path, 'r'))
        file_name = basename(file_path)

        tracks = []
        for i, track in enumerate(gpx.tracks):
            segments = []
            for segment in track.segments:
                segments.append(Segment.from_gpx(segment))

            if len(gpx.tracks) > 1:
                name = file_name + "_" + str(i)
            else:
                name = file_name
            tracks.append(Track(name, segments))

        return tracks
518968
def _loadfilepath(self, filepath, **kwargs):
        
        with open(filepath, "r") as f:
            data = json.load(f, **kwargs)
        return data
728094
def read_filepath(filepath, encoding='utf-8'):
    """"""
    with codecs.open(filepath, 'r', encoding=encoding) as fo:
        return fo.read()
200128
def load(self, filepath):
        """"""
        with open(filepath, 'rb') as fd:
            num_keys = struct.unpack(">i", fd.read(4))[0]
            for i in range(num_keys):
                row, value, kind = struct.unpack('>ifb', fd.read(9))
                self.keys.append(TrackKey(row, value, kind))
1228328
public static File getFileFromClasspath(final String filePath) throws FileNotFoundException {
        try {
            URL fileURL = FileUtils.class.getClassLoader().getResource(filePath);
            if (fileURL == null) {
                throw new FileNotFoundException("File [" + filePath + "] could not be found in classpath");
            }
            return new File(fileURL.toURI());
        } catch (URISyntaxException e) {
            throw new FileNotFoundException("File [" + filePath + "] could not be found: " + e.getMessage());
        }
    }
593459
def get_commits_modified_file(self, filepath: str) -> List[str]:
        
        path = str(Path(filepath))

        commits = []
        try:
            commits = self.git.log("--follow", "--format=%H", path).split('\n')
        except GitCommandError:
            logger.debug("Could not find information of file %s", path)

        return commits
1120776
def get_max_length(self):
        
        max_length = 0
        for track in self.tracks:
            if max_length < track.pianoroll.shape[0]:
                max_length = track.pianoroll.shape[0]
        return max_length
676487
def load(self, path):
        
        self.dct = wrapper.Dictionary.load(path)
        return self
919179
def load_indexed_audio(self, indexed_audio_file_abs_path):
        
        with open(indexed_audio_file_abs_path, "rb") as f:
            self.__timestamps = pickle.load(f)