Ejemplo n.º 1
0
def note_post(note_name):
    """
    Overwrite note `note_name` with content from `note_content` param.

    If `last_version` param is present, check that
    the note to be overwrited is on the same version on the client
    and the server. `last_version` must be a date in ISO 8601 format.
    """
    client_mtime_string = request.forms.get('last_version')
    note = notes.get_note(note_name, meta_only=True)
    if client_mtime_string and note:
        client_mtime = arrow.get(client_mtime_string)
        server_mtime = note['mtime']
        delta = abs(client_mtime - server_mtime).total_seconds()
        if delta < 10:
            notes.put_content(note_name, request.forms.note_content)
        else:
            response.status = "409 Conflict"
    else:
        notes.put_content(note_name, request.forms.note_content)

    current_mtime = notes.get_note(note_name, meta_only=True)['mtime']
    response.add_header(
        'Last-Modified',
        format_date_time(current_mtime.timestamp)
    )
Ejemplo n.º 2
0
def corr_main():
	(rate, sample) = wav.read(sys.argv[1])
	regions = get_regions(rate, sample,400)
	for start, region in regions:
		print start/float(rate), (start + len(region))/float(rate)

	for _, region in regions:
		print get_note(region, rate)[0]
Ejemplo n.º 3
0
def transpose(scale, destination):
    """Transposes a escale to another starting with destination_first_note .
		Total transposition will be the distance from the first note of the scale to destination_first_note"""

    transposed = [destination.clone()]
    origin = scale[0]
    steps = destination.semitones - origin.semitones
    stepo = destination.octave - origin.octave
    step = stepo * 12 + steps

    log.info("Transposing %s from %s to %s, step %s" %
             (scale, origin, destination, step))
    notenames = cycle(NOTE_NAMES)
    while next(notenames) != destination.name:
        pass
    for i in range(1, len(scale)):
        note = scale[i]
        nextsemis = calculate_note_semitones(note.semitones, semitones=step)
        distance = get_note_name_distance(scale[i - 1], note)
        for j in range(0, distance):
            nextname = next(notenames)
            nextnote = get_note(semitones=nextsemis,
                                name=nextname,
                                alteration=None)
        transposed.append(nextnote.clone())

    return arrange_octaves(transposed)
Ejemplo n.º 4
0
def note_head(note_name):
    note = notes.get_note(note_name, meta_only=True) or {}
    mtime = note.get('mtime') or arrow.now()

    response.add_header(
        'Last-Modified',
        format_date_time(mtime.timestamp)
    )
    response.add_header('Cache-Control', 'no-cache')
Ejemplo n.º 5
0
def note_edit(note_name):
    note = notes.get_note(note_name)
    json_data = {
        'noteName': note_name,
    }
    vars = {
        'note_name': note_name,
        'note_content': note.get('content') if note else '',
        'json_data': json.dumps(json_data),
    }
    return vars
Ejemplo n.º 6
0
def note_get(note_name):
    note = notes.get_note(note_name) or {}
    mtime = note.get('mtime') or arrow.now()

    response.add_header(
        'Last-Modified',
        format_date_time(mtime.timestamp)
    )
    response.add_header('Cache-Control', 'no-cache')
    return {
        'note_content': note.get('content')
    }
    def reload_bottom_bar(self, note_id=None):
        """
            Called after queue picker dialog has been closed without opening a new note.
        """
        if note_id is not None:

            note = get_note(note_id)
            html = get_reading_modal_bottom_bar(note)
            html = html.replace("`", "\\`")
            return "$('#siac-reading-modal-bottom-bar').replaceWith(`%s`); updatePdfDisplayedMarks();" % html
        
        else:
            return """if (document.getElementById('siac-reading-modal').style.display !== 'none' && document.getElementById('siac-reading-modal-top-bar')) { 
Ejemplo n.º 8
0
def todo_edit(note_name):
    vars = {'note_name': note_name}
    note = notes.get_note(note_name)
    vars['items'] = []
    if note:
        for line in note['content'].split('\n'):
            item = {}
            item['complete'] = line.startswith('x ')
            # Remove e.g. 'x 2015-02-02 '
            item['text'] = re.sub(r'^x \d{4}-\d{2}-\d{2} ', '', line)
            vars['items'].append(item)
    vars['json_data'] = json.dumps({
        'noteName': note_name,
    })
    return vars
    def display(self, note_id):

        index = get_index()
        note = get_note(note_id)

        self.note_id = note_id
        self.note = note

        html = get_reading_modal_html(note)
        index.ui.show_in_large_modal(html)
        # if source is a pdf file path, try to display it
        if note.is_pdf():
            if utility.misc.file_exists(note.source):
                self._display_pdf(note.source.strip(), note_id)
            else:
                message = "Could not load the given PDF.<br>Are you sure the path is correct?"
                self.notification(message)